Browse Source

test: add common.rootDir

A few of the child process tests can be simplified by computing
the OS specific root directory in common and then accessing that
value.

PR-URL: https://github.com/nodejs/node/pull/7685
Reviewed-By: Roman Reiss <me@silverwind.io>
v7.x
cjihrig 9 years ago
parent
commit
e9bb3329ea
  1. 1
      test/common.js
  2. 3
      test/parallel/test-child-process-cwd.js
  3. 2
      test/parallel/test-child-process-spawnsync.js
  4. 17
      test/sequential/test-child-process-execsync.js

1
test/common.js

@ -27,6 +27,7 @@ exports.isSunOS = process.platform === 'sunos';
exports.isFreeBSD = process.platform === 'freebsd'; exports.isFreeBSD = process.platform === 'freebsd';
exports.enoughTestMem = os.totalmem() > 0x20000000; /* 512MB */ exports.enoughTestMem = os.totalmem() > 0x20000000; /* 512MB */
exports.rootDir = exports.isWindows ? 'c:\\' : '/';
function rimrafSync(p) { function rimrafSync(p) {
try { try {

3
test/parallel/test-child-process-cwd.js

@ -36,12 +36,11 @@ function testCwd(options, forCode, forData) {
} }
// Assume these exist, and 'pwd' gives us the right directory back // Assume these exist, and 'pwd' gives us the right directory back
testCwd({cwd: common.rootDir}, 0, common.rootDir);
if (common.isWindows) { if (common.isWindows) {
testCwd({cwd: process.env.windir}, 0, process.env.windir); testCwd({cwd: process.env.windir}, 0, process.env.windir);
testCwd({cwd: 'c:\\'}, 0, 'c:\\');
} else { } else {
testCwd({cwd: '/dev'}, 0, '/dev'); testCwd({cwd: '/dev'}, 0, '/dev');
testCwd({cwd: '/'}, 0, '/');
} }
// Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT // Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT

2
test/parallel/test-child-process-spawnsync.js

@ -20,7 +20,7 @@ assert.deepStrictEqual(ret_err.spawnargs, ['bar']);
{ {
// Test the cwd option // Test the cwd option
const cwd = common.isWindows ? 'c:\\' : '/'; const cwd = common.rootDir;
const response = common.spawnSyncPwd({cwd}); const response = common.spawnSyncPwd({cwd});
assert.strictEqual(response.stdout.toString().trim(), cwd); assert.strictEqual(response.stdout.toString().trim(), cwd);

17
test/sequential/test-child-process-execsync.js

@ -61,20 +61,13 @@ assert.strictEqual(ret, msg + '\n',
'execFileSync encoding result should match'); 'execFileSync encoding result should match');
// Verify that the cwd option works - GH #7824 // Verify that the cwd option works - GH #7824
(function() { {
var response; const cwd = common.rootDir;
var cwd; const cmd = common.isWindows ? 'echo %cd%' : 'pwd';
const response = execSync(cmd, {cwd});
if (common.isWindows) {
cwd = 'c:\\';
response = execSync('echo %cd%', {cwd: cwd});
} else {
cwd = '/';
response = execSync('pwd', {cwd: cwd});
}
assert.strictEqual(response.toString().trim(), cwd); assert.strictEqual(response.toString().trim(), cwd);
})(); }
// Verify that stderr is not accessed when stdio = 'ignore' - GH #7966 // Verify that stderr is not accessed when stdio = 'ignore' - GH #7966
(function() { (function() {

Loading…
Cancel
Save