Skip to content

Commit

Permalink
test: fix test-find-python on v0.10.x buildbot.
Browse files Browse the repository at this point in the history
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: #1172
Reviewed-By: João Reis <reis@janeasystems.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
bnoordhuis authored and gibfahn committed Apr 25, 2017
1 parent a83a380 commit 4980171
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions test/test-find-python.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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, {})
Expand All @@ -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')
Expand Down

0 comments on commit 4980171

Please sign in to comment.