0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-cli-bad-options.js
Rafael Gonzaga 00c222593e
src,process: add permission model
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/44004
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-02-23 18:11:51 +00:00

39 lines
1.0 KiB
JavaScript

'use strict';
require('../common');
// Tests that node exits consistently on bad option syntax.
const assert = require('assert');
const { spawnSync } = require('child_process');
if (process.features.inspector) {
requiresArgument('--inspect-port');
requiresArgument('--inspect-port=');
requiresArgument('--debug-port');
requiresArgument('--debug-port=');
}
requiresArgument('--eval');
missingOption('--allow-fs-read=*', '--experimental-permission');
missingOption('--allow-fs-write=*', '--experimental-permission');
function missingOption(option, requiredOption) {
const r = spawnSync(process.execPath, [option], { encoding: 'utf8' });
assert.strictEqual(r.status, 1);
const message = `${requiredOption} is required`;
assert.match(r.stderr, new RegExp(message));
}
function requiresArgument(option) {
const r = spawnSync(process.execPath, [option], { encoding: 'utf8' });
assert.strictEqual(r.status, 9);
const msg = r.stderr.split(/\r?\n/)[0];
assert.strictEqual(
msg,
`${process.execPath}: ${option} requires an argument`
);
}