From 49801716c2eaf3da8f602666018dce7a06c808fe Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 11 Apr 2017 20:09:14 +0200 Subject: [PATCH] test: fix test-find-python on v0.10.x buildbot. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Work around a v0.10.x CI issue where path.resolve() on UNIX systems prefixes Windows paths with the current working directory. v0.12 and up are free of this issue because they use path.win32.resolve() which does the right thing. PR-URL: https://github.com/nodejs/node-gyp/pull/1172 Reviewed-By: João Reis Reviewed-By: Gibson Fahnestock Reviewed-By: Richard Lau Reviewed-By: Ben Noordhuis --- lib/configure.js | 4 ++-- test/test-find-python.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/configure.js b/lib/configure.js index 3349e9fedf..4bad1bffd1 100644 --- a/lib/configure.js +++ b/lib/configure.js @@ -375,6 +375,7 @@ PythonFinder.prototype = { env: process.env, execFile: cp.execFile, log: log, + resolve: path.win32 && path.win32.resolve || path.resolve, stat: fs.stat, which: which, win: win, @@ -499,8 +500,7 @@ PythonFinder.prototype = { if (rootDir[rootDir.length - 1] !== '\\') { rootDir += '\\' } - var resolve = path.win32 && path.win32.resolve || path.resolve - var pythonPath = resolve(rootDir, 'Python27', 'python.exe') + var pythonPath = this.resolve(rootDir, 'Python27', 'python.exe') this.log.verbose('ensuring that file exists:', pythonPath) this.stat(pythonPath, function (err, stat) { if (err) { diff --git a/test/test-find-python.js b/test/test-find-python.js index 30ba6df78b..2d9f171c57 100644 --- a/test/test-find-python.js +++ b/test/test-find-python.js @@ -1,6 +1,7 @@ 'use strict' var test = require('tape') +var path = require('path') var configure = require('../lib/configure') var execFile = require('child_process').execFile var PythonFinder = configure.test.PythonFinder @@ -34,10 +35,19 @@ function poison(object, property) { Object.defineProperty(object, property, descriptor) } +// Work around a v0.10.x CI issue where path.resolve() on UNIX systems prefixes +// Windows paths with the current working directory. v0.12 and up are free of +// this issue because they use path.win32.resolve() which does the right thing. +var resolve = path.win32 && path.win32.resolve || function() { + function rstrip(s) { return s.replace(/\\+$/, '') } + return [].slice.call(arguments).map(rstrip).join('\\') +} + function TestPythonFinder() { PythonFinder.apply(this, arguments) } TestPythonFinder.prototype = Object.create(PythonFinder.prototype) poison(TestPythonFinder.prototype, 'env') poison(TestPythonFinder.prototype, 'execFile') +poison(TestPythonFinder.prototype, 'resolve') poison(TestPythonFinder.prototype, 'stat') poison(TestPythonFinder.prototype, 'which') poison(TestPythonFinder.prototype, 'win') @@ -287,6 +297,7 @@ test('find python - no python, no python launcher, good guess', function (t) { t.strictEqual(program, 'py.exe') cb(new Error('not found')) } + f.resolve = resolve f.stat = function(path, cb) { t.ok(re.test(path)) cb(null, {}) @@ -313,6 +324,7 @@ test('find python - no python, no python launcher, bad guess', function (t) { t.strictEqual(program, 'py.exe') cb(new Error('not found')) } + f.resolve = resolve f.stat = function(path, cb) { t.ok(/Z:[\\\/]Python27[\\\/]python.exe/.test(path)) var err = new Error('not found')