Skip to content

Commit

Permalink
fix more tests with wrong assumptions
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 24, 2023
1 parent bd9fd67 commit 65b4a75
Show file tree
Hide file tree
Showing 38 changed files with 102 additions and 120 deletions.
24 changes: 8 additions & 16 deletions test/abort/test-abort-fatal-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,13 @@ if (common.isWindows)
const assert = require('assert');
const exec = require('child_process').exec;

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

exec(cmdline, function(err, stdout, stderr) {
if (!err) {
console.log(stdout);
console.log(stderr);
assert(false, 'this test should fail');
exec(cmdline, { env: { NODE: process.execPath } }, common.mustCall((err, stdout, stderr) => {
if (err?.code !== 134 && err?.signal !== 'SIGABRT') {
console.log({ err, stdout, stderr });
assert.fail(err?.message);
}

if (err.code !== 134 && err.signal !== 'SIGABRT') {
console.log(stdout);
console.log(stderr);
console.log(err);
assert(false, err);
}
});
}));
3 changes: 2 additions & 1 deletion test/async-hooks/test-callback-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ assert.ok(!arg);
'--abort-on-uncaught-exception', __filename, 'test_callback_abort' ];
const options = { encoding: 'utf8' };
if (!common.isWindows) {
program = `ulimit -c 0 && exec ${program} ${args.join(' ')}`;
program = `ulimit -c 0 && exec "$NODE" ${args[0]} "$FILE" ${args[2]}`;
args = [];
options.shell = true;
options.env = { NODE: process.execPath, FILE: __filename };
}
const child = spawnSync(program, args, options);
if (common.isWindows) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-readfile-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const fixtures = require('../common/fixtures');

function test(env, cb) {
const filename = fixtures.path('test-fs-readfile-error.js');
const execPath = `"${process.execPath}" "${filename}"`;
const options = { env: { ...process.env, ...env } };
const execPath = '"$NODE" "$FILE"';
const options = { env: { ...process.env, ...env, NODE: process.execPath, FILE: filename } };
exec(execPath, options, (err, stdout, stderr) => {
assert(err);
assert.strictEqual(stdout, '');
Expand Down
10 changes: 6 additions & 4 deletions test/parallel/test-fs-readfile-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ tmpdir.refresh();
fs.writeFileSync(filename, dataExpected);

const exec = require('child_process').exec;
const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${filename} | ${node} ${f} child`;
exec(cmd, { maxBuffer: 1000000 }, common.mustSucceed((stdout, stderr) => {
const cmd = '"$NODE" "$FILE" child < "TMP_FILE"';
exec(cmd, { maxBuffer: 1000000, env: {
NODE: process.execPath,
FILE: __filename,
TMP_FILE: filename,
} }, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(
stdout,
dataExpected,
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-fs-readfile-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const filename = fixtures.path('readfile_pipe_test.txt');
const dataExpected = fs.readFileSync(filename).toString();

const exec = require('child_process').exec;
const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${filename} | ${node} ${f} child`;
exec(cmd, common.mustSucceed((stdout, stderr) => {
const cmd = '"$NODE" "$FILE" child < "TMP_FILE"';
exec(cmd, {
env: { NODE: process.execPath, FILE: __filename, TMP_FILE: filename }
}, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(
stdout,
dataExpected,
Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-fs-readfilesync-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ tmpdir.refresh();
fs.writeFileSync(filename, dataExpected);

const exec = require('child_process').exec;
const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${filename} | ${node} ${f} child`;
const cmd = '"$NODE" "$FILE" child < "TMP_FILE"';
exec(
cmd,
{ maxBuffer: 1000000 },
{ maxBuffer: 1000000, env: { NODE: process.execPath, FILE: __filename, TMP_FILE: filename } },
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, dataExpected);
assert.strictEqual(stderr, '');
Expand Down
12 changes: 1 addition & 11 deletions test/parallel/test-fs-whatwg-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const os = require('os');

function pathToFileURL(p) {
if (!path.isAbsolute(p))
throw new Error('Path must be absolute');
if (common.isWindows && p.startsWith('\\\\'))
p = p.slice(2);
return new URL(`file://${p}`);
}

const p = path.resolve(fixtures.fixturesDir, 'a.js');
const url = pathToFileURL(p);
const url = fixtures.fileURL('a.js');

assert(url instanceof URL);

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-write-sigxfsz.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if (process.argv[2] === 'child') {
tmpdir.refresh();
fs.writeFileSync(filename, '.'.repeat(1 << 16)); // Exceeds RLIMIT_FSIZE.
} else {
const cmd = `ulimit -f 1 && '${process.execPath}' '${__filename}' child`;
const result = child_process.spawnSync('/bin/sh', ['-c', cmd]);
const cmd = 'ulimit -f 1 && "$NODE" "$FILE" child';
const result = child_process.spawnSync('/bin/sh', ['-c', cmd], { env: { NODE: process.execPath, FILE: __filename } });
const haystack = result.stderr.toString();
const needle = 'Error: EFBIG: file too large, write';
const ok = haystack.includes(needle);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-internal-util-decorate-error-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ checkStack(err.stack);
// Verify that the stack is only decorated once for uncaught exceptions.
const args = [
'-e',
`require('${badSyntaxPath}')`,
`require(${JSON.stringify(badSyntaxPath)})`,
];
const result = spawnSync(process.argv[0], args, { encoding: 'utf8' });
checkStack(result.stderr);
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-module-create-require.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const path = require('path');

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

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

const reqToo = createRequire(u);
assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-npm-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ const pkgPath = path.join(installDir, 'package.json');
fs.writeFileSync(pkgPath, pkgContent);

const env = { ...process.env,
NODE: process.execPath,
NPM: npmPath,
PATH: path.dirname(process.execPath),
NPM_CONFIG_PREFIX: path.join(npmSandbox, 'npm-prefix'),
NPM_CONFIG_TMP: path.join(npmSandbox, 'npm-tmp'),
NPM_CONFIG_AUDIT: false,
NPM_CONFIG_UPDATE_NOTIFIER: false,
HOME: homeDir };

exec(`${process.execPath} ${npmPath} install`, {
exec('"$NODE" "$NPM" install', {
cwd: installDir,
env: env
}, common.mustCall(handleExit));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-permission-allow-child-process-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (process.argv[2] === 'child') {
{
// doesNotThrow
childProcess.spawnSync(process.execPath, ['--version']);
childProcess.execSync(process.execPath, ['--version']);
childProcess.execSync('"$NODE" --version', { env: { NODE: process.execPath } });
childProcess.fork(__filename, ['child']);
childProcess.execFileSync(process.execPath, ['--version']);
}
4 changes: 2 additions & 2 deletions test/parallel/test-pipe-head.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const exec = require('child_process').exec;
const nodePath = process.argv[0];
const script = fixtures.path('print-10-lines.js');

const cmd = `"${nodePath}" "${script}" | head -2`;
const cmd = '"$NODE" "$FILE" | head -2';

exec(cmd, common.mustSucceed((stdout, stderr) => {
exec(cmd, { env: { NODE: nodePath, FILE: script } }, common.mustSucceed((stdout, stderr) => {
const lines = stdout.split('\n');
assert.strictEqual(lines.length, 3);
}));
7 changes: 3 additions & 4 deletions test/parallel/test-preload-self-referential.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ if (!common.isMainThread)
const selfRefModule = fixtures.path('self_ref_module');
const fixtureA = fixtures.path('printA.js');

exec(`"${nodeBinary}" -r self_ref "${fixtureA}"`, { cwd: selfRefModule },
(err, stdout, stderr) => {
assert.ifError(err);
exec('"$NODE" -r self_ref "$FIXTURE_A"', { cwd: selfRefModule, env: { NODE: nodeBinary, FIXTURE_A: fixtureA } },
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, 'A\n');
});
}));
2 changes: 1 addition & 1 deletion test/parallel/test-preload-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const { exec } = require('child_process');
const kNodeBinary = process.argv[0];


exec(`"${kNodeBinary}" -r "${worker}" -pe "1+1"`, common.mustSucceed());
exec('"$NODE" -r "$WORKER" -pe "1+1"', { env: { NODE: kNodeBinary, WORKER: worker } }, common.mustSucceed());
2 changes: 1 addition & 1 deletion test/parallel/test-repl-require-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ child.on('exit', common.mustCall(() => {

child.stdin.write('const isObject = (obj) => obj.constructor === Object;\n');
child.stdin.write('isObject({});\n');
child.stdin.write(`require('${fixture}').isObject({});\n`);
child.stdin.write(`require(${JSON.stringify(fixture)}).isObject({});\n`);
child.stdin.write('.exit');
child.stdin.end();
4 changes: 2 additions & 2 deletions test/parallel/test-startup-large-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const { spawnSync } = require('child_process');
[ '--use-largepages=xyzzy', '-p', '42' ]);
assert.strictEqual(child.status, 9);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stderr.toString().match(/\S+/g).slice(1).join(' '),
'invalid value for --use-largepages');
assert.match(child.stderr.toString().trim(),
/invalid value for --use-largepages$/);
}

// TODO(gabrielschulhof): Make assertions about the stderr, which may or may not
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-stdin-from-file-spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ setTimeout(() => {
}, 100);
`);

execSync(`${process.argv[0]} ${tmpJsFile} < ${tmpCmdFile}`);
execSync('"$NODE" "$JS_FILE" < "$CMD_FILE"',
{ env: { NODE: process.argv0, JS_FILE: tmpJsFile, CMD_FILE: tmpCmdFile } });
6 changes: 4 additions & 2 deletions test/parallel/test-stdin-from-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fs = require('fs');
const stdoutScript = fixtures.path('echo-close-check.js');
const tmpFile = join(tmpdir.path, 'stdin.txt');

const cmd = `"${process.argv[0]}" "${stdoutScript}" < "${tmpFile}"`;
const cmd = '"$NODE" "$STDOUT_SCRIPT" < "$TMP_FILE"';

const string = 'abc\nümlaut.\nsomething else\n' +
'南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,' +
Expand All @@ -31,7 +31,9 @@ console.log(`${cmd}\n\n`);

fs.writeFileSync(tmpFile, string);

childProcess.exec(cmd, common.mustCall(function(err, stdout, stderr) {
childProcess.exec(cmd, { env: {
NODE: process.argv0, STDOUT_SCRIPT: stdoutScript, TMP_FILE: tmpFile
} }, common.mustCall(function(err, stdout, stderr) {
fs.unlinkSync(tmpFile);

assert.ifError(err);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stdio-closed.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ if (process.argv[2] === 'child') {
}

// Run the script in a shell but close stdout and stderr.
const cmd = `"${process.execPath}" "${__filename}" child 1>&- 2>&-`;
const proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit' });
const cmd = '"$NODE" "$FILE" child 1>&- 2>&-';
const proc = spawn('/bin/sh', ['-c', cmd], { stdio: 'inherit', env: { NODE: process.execPath, FILE: __filename } });

proc.on('exit', common.mustCall(function(exitCode) {
assert.strictEqual(exitCode, 0);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stdio-pipe-stderr.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fs.writeFileSync(fakeModulePath, '', 'utf8');

stream.on('open', () => {
spawnSync(process.execPath, {
input: `require("${fakeModulePath.replace(/\\/g, '/')}")`,
input: `require(${JSON.stringify(fakeModulePath)})`,
stdio: ['pipe', 'pipe', stream]
});
const stderr = fs.readFileSync(stderrOutputPath, 'utf8').trim();
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-stdout-close-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const { getSystemErrorName } = require('util');

const testScript = fixtures.path('catch-stdout-error.js');

const cmd = `${JSON.stringify(process.execPath)} ` +
`${JSON.stringify(testScript)} | ` +
`${JSON.stringify(process.execPath)} ` +
const cmd = '"$NODE" ' +
'"$TEST_SCRIPT" | ' +
'"$NODE" ' +
'-pe "process.stdin.on(\'data\' , () => process.exit(1))"';

const child = child_process.exec(cmd);
const child = child_process.exec(cmd, { env: { NODE: process.execPath, TEST_SCRIPT: testScript } });
let output = '';

child.stderr.on('data', function(c) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stdout-to-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const tmpFile = path.join(tmpdir.path, 'stdout.txt');
tmpdir.refresh();

function test(size, useBuffer, cb) {
const cmd = `"${process.argv[0]}" "${
const cmd = `"$NODE" "${
useBuffer ? scriptBuffer : scriptString}" ${size} > "${tmpFile}"`;

try {
Expand All @@ -25,7 +25,7 @@ function test(size, useBuffer, cb) {

console.log(`${size} chars to ${tmpFile}...`);

childProcess.exec(cmd, common.mustSucceed(() => {
childProcess.exec(cmd, { env: { NODE: process.execPath } }, common.mustSucceed(() => {
console.log('done!');

const stat = fs.statSync(tmpFile);
Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-timers-immediate-promisified.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ const common = require('../common');
const assert = require('assert');
const timers = require('timers');
const { promisify } = require('util');
const child_process = require('child_process');

const { getEventListeners } = require('events');
const { NodeEventTarget } = require('internal/event_target');

const timerPromises = require('timers/promises');

const setPromiseImmediate = promisify(timers.setImmediate);
const exec = promisify(child_process.exec);

assert.strictEqual(setPromiseImmediate, timerPromises.setImmediate);

Expand Down Expand Up @@ -91,9 +89,9 @@ process.on('multipleResolves', common.mustNotCall());
}

{
exec(`${process.execPath} -pe "const assert = require('assert');` +
common.spawnPromisified(process.execPath, ['-pe', "const assert = require('assert');" +
'require(\'timers/promises\').setImmediate(null, { ref: false }).' +
'then(assert.fail)"').then(common.mustCall(({ stderr }) => {
'then(assert.fail)']).then(common.mustCall(({ stderr }) => {
assert.strictEqual(stderr, '');
}));
}
Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-timers-interval-promisified.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ const common = require('../common');
const assert = require('assert');
const timers = require('timers');
const { promisify } = require('util');
const child_process = require('child_process');

const { getEventListeners } = require('events');
const { NodeEventTarget } = require('internal/event_target');

const timerPromises = require('timers/promises');

const setPromiseTimeout = promisify(timers.setTimeout);
const exec = promisify(child_process.exec);

const { setInterval } = timerPromises;

Expand Down Expand Up @@ -154,11 +152,11 @@ process.on('multipleResolves', common.mustNotCall());
}

{
exec(`${process.execPath} -pe "const assert = require('assert');` +
common.spawnPromisified(process.execPath, ['-pe', "const assert = require('assert');" +
'const interval = require(\'timers/promises\')' +
'.setInterval(1000, null, { ref: false });' +
'interval[Symbol.asyncIterator]().next()' +
'.then(assert.fail)"').then(common.mustCall(({ stderr }) => {
'.then(assert.fail)']).then(common.mustCall(({ stderr }) => {
assert.strictEqual(stderr, '');
}));
}
Expand Down
Loading

0 comments on commit 65b4a75

Please sign in to comment.