2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2020-03-23 13:06:24 -07:00
|
|
|
const {
|
|
|
|
isWindows,
|
|
|
|
mustCall,
|
|
|
|
mustCallAtLeast,
|
|
|
|
} = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
2017-08-30 17:57:12 +08:00
|
|
|
const os = require('os');
|
2020-03-23 13:06:24 -07:00
|
|
|
const debug = require('util').debuglog('test');
|
2010-03-17 14:00:17 -07:00
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const spawn = require('child_process').spawn;
|
2011-02-18 13:44:20 -08:00
|
|
|
|
2019-11-12 15:40:35 +00:00
|
|
|
const env = {
|
|
|
|
...process.env,
|
2017-08-30 17:57:12 +08:00
|
|
|
'HELLO': 'WORLD',
|
|
|
|
'UNDEFINED': undefined,
|
|
|
|
'NULL': null,
|
2020-09-24 18:25:18 +02:00
|
|
|
'EMPTY': '',
|
|
|
|
'duplicate': 'lowercase',
|
|
|
|
'DUPLICATE': 'uppercase',
|
2019-11-12 15:40:35 +00:00
|
|
|
};
|
2016-02-08 21:12:09 +08:00
|
|
|
Object.setPrototypeOf(env, {
|
2011-02-18 13:44:20 -08:00
|
|
|
'FOO': 'BAR'
|
2016-02-08 21:12:09 +08:00
|
|
|
});
|
2011-02-18 13:44:20 -08:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let child;
|
2020-03-23 13:06:24 -07:00
|
|
|
if (isWindows) {
|
2018-08-21 17:09:11 +08:00
|
|
|
child = spawn('cmd.exe', ['/c', 'set'], { env });
|
2011-08-01 13:43:38 -07:00
|
|
|
} else {
|
2018-08-21 17:09:11 +08:00
|
|
|
child = spawn('/usr/bin/env', [], { env });
|
2011-08-01 13:43:38 -07:00
|
|
|
}
|
|
|
|
|
2010-03-17 14:00:17 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let response = '';
|
2010-03-03 10:45:58 -08:00
|
|
|
|
2010-03-17 14:00:17 -07:00
|
|
|
child.stdout.setEncoding('utf8');
|
|
|
|
|
2020-03-23 13:06:24 -07:00
|
|
|
child.stdout.on('data', mustCallAtLeast((chunk) => {
|
|
|
|
debug(`stdout: ${chunk}`);
|
2010-03-17 14:00:17 -07:00
|
|
|
response += chunk;
|
2020-03-23 13:06:24 -07:00
|
|
|
}));
|
2010-03-03 10:45:58 -08:00
|
|
|
|
2020-03-23 13:06:24 -07:00
|
|
|
child.stdout.on('end', mustCall(() => {
|
2017-04-23 02:01:54 +03:00
|
|
|
assert.ok(response.includes('HELLO=WORLD'));
|
2018-01-17 13:30:43 -05:00
|
|
|
assert.ok(response.includes('FOO=BAR'));
|
2017-08-30 17:57:12 +08:00
|
|
|
assert.ok(!response.includes('UNDEFINED=undefined'));
|
|
|
|
assert.ok(response.includes('NULL=null'));
|
|
|
|
assert.ok(response.includes(`EMPTY=${os.EOL}`));
|
2020-09-24 18:25:18 +02:00
|
|
|
if (isWindows) {
|
|
|
|
assert.ok(response.includes('DUPLICATE=uppercase'));
|
|
|
|
assert.ok(!response.includes('duplicate=lowercase'));
|
|
|
|
} else {
|
|
|
|
assert.ok(response.includes('DUPLICATE=uppercase'));
|
|
|
|
assert.ok(response.includes('duplicate=lowercase'));
|
|
|
|
}
|
2020-03-23 13:06:24 -07:00
|
|
|
}));
|