Skip to content

Commit 65b4a75

Browse files
committed
fix more tests with wrong assumptions
1 parent bd9fd67 commit 65b4a75

38 files changed

+102
-120
lines changed

test/abort/test-abort-fatal-error.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,13 @@ if (common.isWindows)
2727
const assert = require('assert');
2828
const exec = require('child_process').exec;
2929

30-
let cmdline = `ulimit -c 0; ${JSON.stringify(process.execPath)}`;
31-
cmdline += ' --max-old-space-size=16 --max-semi-space-size=4';
32-
cmdline += ' -e "a = []; for (i = 0; i < 1e9; i++) { a.push({}) }"';
30+
const cmdline =
31+
'ulimit -c 0; "$NODE" --max-old-space-size=16 --max-semi-space-size=4' +
32+
' -e "a = []; for (i = 0; i < 1e9; i++) { a.push({}) }"';
3333

34-
exec(cmdline, function(err, stdout, stderr) {
35-
if (!err) {
36-
console.log(stdout);
37-
console.log(stderr);
38-
assert(false, 'this test should fail');
34+
exec(cmdline, { env: { NODE: process.execPath } }, common.mustCall((err, stdout, stderr) => {
35+
if (err?.code !== 134 && err?.signal !== 'SIGABRT') {
36+
console.log({ err, stdout, stderr });
37+
assert.fail(err?.message);
3938
}
40-
41-
if (err.code !== 134 && err.signal !== 'SIGABRT') {
42-
console.log(stdout);
43-
console.log(stderr);
44-
console.log(err);
45-
assert(false, err);
46-
}
47-
});
39+
}));

test/async-hooks/test-callback-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ assert.ok(!arg);
6464
'--abort-on-uncaught-exception', __filename, 'test_callback_abort' ];
6565
const options = { encoding: 'utf8' };
6666
if (!common.isWindows) {
67-
program = `ulimit -c 0 && exec ${program} ${args.join(' ')}`;
67+
program = `ulimit -c 0 && exec "$NODE" ${args[0]} "$FILE" ${args[2]}`;
6868
args = [];
6969
options.shell = true;
70+
options.env = { NODE: process.execPath, FILE: __filename };
7071
}
7172
const child = spawnSync(program, args, options);
7273
if (common.isWindows) {

test/parallel/test-fs-readfile-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ const fixtures = require('../common/fixtures');
3636

3737
function test(env, cb) {
3838
const filename = fixtures.path('test-fs-readfile-error.js');
39-
const execPath = `"${process.execPath}" "${filename}"`;
40-
const options = { env: { ...process.env, ...env } };
39+
const execPath = '"$NODE" "$FILE"';
40+
const options = { env: { ...process.env, ...env, NODE: process.execPath, FILE: filename } };
4141
exec(execPath, options, (err, stdout, stderr) => {
4242
assert(err);
4343
assert.strictEqual(stdout, '');

test/parallel/test-fs-readfile-pipe-large.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ tmpdir.refresh();
2626
fs.writeFileSync(filename, dataExpected);
2727

2828
const exec = require('child_process').exec;
29-
const f = JSON.stringify(__filename);
30-
const node = JSON.stringify(process.execPath);
31-
const cmd = `cat ${filename} | ${node} ${f} child`;
32-
exec(cmd, { maxBuffer: 1000000 }, common.mustSucceed((stdout, stderr) => {
29+
const cmd = '"$NODE" "$FILE" child < "TMP_FILE"';
30+
exec(cmd, { maxBuffer: 1000000, env: {
31+
NODE: process.execPath,
32+
FILE: __filename,
33+
TMP_FILE: filename,
34+
} }, common.mustSucceed((stdout, stderr) => {
3335
assert.strictEqual(
3436
stdout,
3537
dataExpected,

test/parallel/test-fs-readfile-pipe.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ const filename = fixtures.path('readfile_pipe_test.txt');
4343
const dataExpected = fs.readFileSync(filename).toString();
4444

4545
const exec = require('child_process').exec;
46-
const f = JSON.stringify(__filename);
47-
const node = JSON.stringify(process.execPath);
48-
const cmd = `cat ${filename} | ${node} ${f} child`;
49-
exec(cmd, common.mustSucceed((stdout, stderr) => {
46+
const cmd = '"$NODE" "$FILE" child < "TMP_FILE"';
47+
exec(cmd, {
48+
env: { NODE: process.execPath, FILE: __filename, TMP_FILE: filename }
49+
}, common.mustSucceed((stdout, stderr) => {
5050
assert.strictEqual(
5151
stdout,
5252
dataExpected,

test/parallel/test-fs-readfilesync-pipe-large.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ tmpdir.refresh();
2323
fs.writeFileSync(filename, dataExpected);
2424

2525
const exec = require('child_process').exec;
26-
const f = JSON.stringify(__filename);
27-
const node = JSON.stringify(process.execPath);
28-
const cmd = `cat ${filename} | ${node} ${f} child`;
26+
const cmd = '"$NODE" "$FILE" child < "TMP_FILE"';
2927
exec(
3028
cmd,
31-
{ maxBuffer: 1000000 },
29+
{ maxBuffer: 1000000, env: { NODE: process.execPath, FILE: __filename, TMP_FILE: filename } },
3230
common.mustSucceed((stdout, stderr) => {
3331
assert.strictEqual(stdout, dataExpected);
3432
assert.strictEqual(stderr, '');

test/parallel/test-fs-whatwg-url.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,10 @@
33
const common = require('../common');
44
const fixtures = require('../common/fixtures');
55
const assert = require('assert');
6-
const path = require('path');
76
const fs = require('fs');
87
const os = require('os');
98

10-
function pathToFileURL(p) {
11-
if (!path.isAbsolute(p))
12-
throw new Error('Path must be absolute');
13-
if (common.isWindows && p.startsWith('\\\\'))
14-
p = p.slice(2);
15-
return new URL(`file://${p}`);
16-
}
17-
18-
const p = path.resolve(fixtures.fixturesDir, 'a.js');
19-
const url = pathToFileURL(p);
9+
const url = fixtures.fileURL('a.js');
2010

2111
assert(url instanceof URL);
2212

test/parallel/test-fs-write-sigxfsz.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ if (process.argv[2] === 'child') {
2020
tmpdir.refresh();
2121
fs.writeFileSync(filename, '.'.repeat(1 << 16)); // Exceeds RLIMIT_FSIZE.
2222
} else {
23-
const cmd = `ulimit -f 1 && '${process.execPath}' '${__filename}' child`;
24-
const result = child_process.spawnSync('/bin/sh', ['-c', cmd]);
23+
const cmd = 'ulimit -f 1 && "$NODE" "$FILE" child';
24+
const result = child_process.spawnSync('/bin/sh', ['-c', cmd], { env: { NODE: process.execPath, FILE: __filename } });
2525
const haystack = result.stderr.toString();
2626
const needle = 'Error: EFBIG: file too large, write';
2727
const ok = haystack.includes(needle);

test/parallel/test-internal-util-decorate-error-stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ checkStack(err.stack);
5858
// Verify that the stack is only decorated once for uncaught exceptions.
5959
const args = [
6060
'-e',
61-
`require('${badSyntaxPath}')`,
61+
`require(${JSON.stringify(badSyntaxPath)})`,
6262
];
6363
const result = spawnSync(process.argv[0], args, { encoding: 'utf8' });
6464
checkStack(result.stderr);

test/parallel/test-module-create-require.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use strict';
22

33
require('../common');
4+
const fixtures = require('../common/fixtures');
45
const assert = require('assert');
5-
const path = require('path');
66

77
const { createRequire } = require('module');
88

9-
const p = path.resolve(__dirname, '..', 'fixtures', 'fake.js');
10-
const u = new URL(`file://${p}`);
9+
const u = fixtures.fileURL('fake.js');
1110

1211
const reqToo = createRequire(u);
1312
assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });

0 commit comments

Comments
 (0)