• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const test = require('tap').test
4const path = require('path')
5const devDir = require('./common').devDir()
6const gyp = require('../lib/node-gyp')
7const requireInject = require('require-inject')
8const configure = requireInject('../lib/configure', {
9  'graceful-fs': {
10    openSync: function () { return 0 },
11    closeSync: function () { },
12    writeFile: function (file, data, cb) { cb() },
13    stat: function (file, cb) { cb(null, {}) }
14  }
15})
16
17const EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib')
18const SEPARATOR = process.platform === 'win32' ? ';' : ':'
19const SPAWN_RESULT = { on: function () { } }
20
21require('npmlog').level = 'warn'
22
23test('configure PYTHONPATH with no existing env', function (t) {
24  t.plan(1)
25
26  delete process.env.PYTHONPATH
27
28  var prog = gyp()
29  prog.parseArgv([])
30  prog.spawn = function () {
31    t.equal(process.env.PYTHONPATH, EXPECTED_PYPATH)
32    return SPAWN_RESULT
33  }
34  prog.devDir = devDir
35  configure(prog, [], t.fail)
36})
37
38test('configure PYTHONPATH with existing env of one dir', function (t) {
39  t.plan(2)
40
41  var existingPath = path.join('a', 'b')
42  process.env.PYTHONPATH = existingPath
43
44  var prog = gyp()
45  prog.parseArgv([])
46  prog.spawn = function () {
47    t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
48
49    var dirs = process.env.PYTHONPATH.split(SEPARATOR)
50    t.deepEqual(dirs, [EXPECTED_PYPATH, existingPath])
51
52    return SPAWN_RESULT
53  }
54  prog.devDir = devDir
55  configure(prog, [], t.fail)
56})
57
58test('configure PYTHONPATH with existing env of multiple dirs', function (t) {
59  t.plan(2)
60
61  var pythonDir1 = path.join('a', 'b')
62  var pythonDir2 = path.join('b', 'c')
63  var existingPath = [pythonDir1, pythonDir2].join(SEPARATOR)
64  process.env.PYTHONPATH = existingPath
65
66  var prog = gyp()
67  prog.parseArgv([])
68  prog.spawn = function () {
69    t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
70
71    var dirs = process.env.PYTHONPATH.split(SEPARATOR)
72    t.deepEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2])
73
74    return SPAWN_RESULT
75  }
76  prog.devDir = devDir
77  configure(prog, [], t.fail)
78})
79