| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f20ce47 commit c554aa1
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,11 +28,14 @@ const assert = require('assert'); | |||
| 28 | 28 | const { spawn } = require('child_process'); | |
| 29 | 29 | ||
| 30 | 30 | // Spawns 'pwd' with given options, then test | |
| 31 | + // - whether the child pid is undefined or number, | ||
| 31 | 32 | // - whether the exit code equals expectCode, | |
| 32 | 33 | // - optionally whether the trimmed stdout result matches expectData | |
| 33 | - function testCwd(options, expectCode = 0, expectData) { | ||
| 34 | + function testCwd(options, expectPidType, expectCode = 0, expectData) { | ||
| 34 | 35 | const child = spawn(...common.pwdCommand, options); | |
| 35 | 36 | ||
| 37 | + assert.strictEqual(typeof child.pid, expectPidType); | ||
| 38 | + | ||
| 36 | 39 | child.stdout.setEncoding('utf8'); | |
| 37 | 40 | ||
| 38 | 41 | // No need to assert callback since `data` is asserted. | |
@@ -57,18 +60,18 @@ function testCwd(options, expectCode = 0, expectData) { | |||
| 57 | 60 | ||
| 58 | 61 | // Assume does-not-exist doesn't exist, expect exitCode=-1 and errno=ENOENT | |
| 59 | 62 | { | |
| 60 | - testCwd({ cwd: 'does-not-exist' }, -1) | ||
| 63 | + testCwd({ cwd: 'does-not-exist' }, 'undefined', -1) | ||
| 61 | 64 | .on('error', common.mustCall(function(e) { | |
| 62 | 65 | assert.strictEqual(e.code, 'ENOENT'); | |
| 63 | 66 | })); | |
| 64 | 67 | } | |
| 65 | 68 | ||
| 66 | 69 | // Assume these exist, and 'pwd' gives us the right directory back | |
| 67 | - testCwd({ cwd: tmpdir.path }, 0, tmpdir.path); | ||
| 70 | + testCwd({ cwd: tmpdir.path }, 'number', 0, tmpdir.path); | ||
| 68 | 71 | const shouldExistDir = common.isWindows ? process.env.windir : '/dev'; | |
| 69 | - testCwd({ cwd: shouldExistDir }, 0, shouldExistDir); | ||
| 72 | + testCwd({ cwd: shouldExistDir }, 'number', 0, shouldExistDir); | ||
| 70 | 73 | ||
| 71 | 74 | // Spawn() shouldn't try to chdir() to invalid arg, so this should just work | |
| 72 | - testCwd({ cwd: '' }); | ||
| 73 | - testCwd({ cwd: undefined }); | ||
| 74 | - testCwd({ cwd: null }); | ||
| 75 | + testCwd({ cwd: '' }, 'number'); | ||
| 76 | + testCwd({ cwd: undefined }, 'number'); | ||
| 77 | + testCwd({ cwd: null }, 'number'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,17 +24,21 @@ const common = require('../common'); | |||
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | const child_process = require('child_process'); | |
| 26 | 26 | ||
| 27 | - function test(fn, code) { | ||
| 28 | - fn('does-not-exist', common.mustCall(function(err) { | ||
| 27 | + function test(fn, code, expectPidType = 'number') { | ||
| 28 | + const child = fn('does-not-exist', common.mustCall(function(err) { | ||
| 29 | 29 | assert.strictEqual(err.code, code); | |
| 30 | 30 | assert(err.cmd.includes('does-not-exist')); | |
| 31 | 31 | })); | |
| 32 | + | ||
| 33 | + assert.strictEqual(typeof child.pid, expectPidType); | ||
| 32 | 34 | } | |
| 33 | 35 | ||
| 36 | + // With `shell: true`, expect pid (of the shell) | ||
| 34 | 37 | if (common.isWindows) { | |
| 35 | - test(child_process.exec, 1); // Exit code of cmd.exe | ||
| 38 | + test(child_process.exec, 1, 'number'); // Exit code of cmd.exe | ||
| 36 | 39 | } else { | |
| 37 | - test(child_process.exec, 127); // Exit code of /bin/sh | ||
| 40 | + test(child_process.exec, 127, 'number'); // Exit code of /bin/sh | ||
| 38 | 41 | } | |
| 39 | 42 | ||
| 40 | - test(child_process.execFile, 'ENOENT'); | ||
| 43 | + // With `shell: false`, expect no pid | ||
| 44 | + test(child_process.execFile, 'ENOENT', 'undefined'); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,9 @@ assert.strictEqual(enoentChild.stdio[0], enoentChild.stdin); | |||
| 41 | 41 | assert.strictEqual(enoentChild.stdio[1], enoentChild.stdout); | |
| 42 | 42 | assert.strictEqual(enoentChild.stdio[2], enoentChild.stderr); | |
| 43 | 43 | ||
| 44 | + // Verify pid is not assigned. | ||
| 45 | + assert.strictEqual(enoentChild.pid, undefined); | ||
| 46 | + | ||
| 44 | 47 | enoentChild.on('spawn', common.mustNotCall()); | |
| 45 | 48 | ||
| 46 | 49 | enoentChild.on('error', common.mustCall(function(err) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments