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