test: use assert.match instead of regexp.test

PR-URL: https://github.com/nodejs/node/pull/39928
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
This commit is contained in:
Michaël Zasso 2021-08-29 10:14:22 +02:00
parent 162f07b7af
commit 508890d795
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
98 changed files with 259 additions and 259 deletions

View File

@ -90,7 +90,7 @@ if (process.argv[2] === 'child') {
switch (state) {
case 'initial':
assert(/^uv loop at \[.+\] has open handles:$/.test(line), line);
assert.match(line, /^uv loop at \[.+\] has open handles:$/);
state = 'handle-start';
break;
case 'handle-start':
@ -98,15 +98,15 @@ if (process.argv[2] === 'child') {
state = 'assertion-failure';
break;
}
assert(/^\[.+\] timer( \(active\))?$/.test(line), line);
assert.match(line, /^\[.+\] timer( \(active\))?$/);
state = 'close-callback';
break;
case 'close-callback':
assert(/^Close callback:/.test(line), line);
assert.match(line, /^Close callback:/);
state = 'data';
break;
case 'data':
assert(/^Data: .+$/.test(line), line);
assert.match(line, /^Data: .+$/);
state = 'maybe-first-field';
break;
case 'maybe-first-field':
@ -116,7 +116,7 @@ if (process.argv[2] === 'child') {
state = 'handle-start';
break;
case 'assertion-failure':
assert(/Assertion .+ failed/.test(line), line);
assert.match(line, /Assertion .+ failed/);
state = 'done';
break;
case 'done':

View File

@ -12,4 +12,4 @@ const err = binding.errno();
assert.strictEqual(err.syscall, 'syscall');
assert.strictEqual(err.errno, 10);
assert.strictEqual(err.path, 'päth');
assert.ok(/^Error:\s\w+, some error msg 'päth'$/.test(err.toString()));
assert.match(err.toString(), /^Error:\s\w+, some error msg 'päth'$/);

View File

@ -54,11 +54,11 @@ if (process.argv[2] === 'child') {
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}

View File

@ -54,11 +54,11 @@ if (process.argv[2] === 'child') {
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}

View File

@ -53,11 +53,11 @@ if (process.argv[2] === 'child') {
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}

View File

@ -57,11 +57,11 @@ if (process.argv[2] === 'child') {
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 1);
assert.ok(heartbeatMsg.test(outData.toString()),
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.ok(corruptedMsg.test(errData.toString()),
'printed error contains corrupted message ' +
`(found ${errData})`);
assert.match(outData.toString(), heartbeatMsg,
'did not crash until we reached offending line of code ' +
`(found ${outData})`);
assert.match(errData.toString(), corruptedMsg,
'printed error contains corrupted message ' +
`(found ${errData})`);
}));
}

View File

@ -554,7 +554,7 @@ function _expectWarning(name, expected, code) {
if (typeof message === 'string') {
assert.strictEqual(warning.message, message);
} else {
assert(message.test(warning.message));
assert.match(warning.message, message);
}
assert.strictEqual(warning.code, code);
}, expected.length);

View File

@ -146,7 +146,7 @@ function _validateContent(report, fields = []) {
header.networkInterfaces.forEach((iface) => {
assert.strictEqual(typeof iface.name, 'string');
assert.strictEqual(typeof iface.internal, 'boolean');
assert(/^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i.test(iface.mac));
assert.match(iface.mac, /^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i);
if (iface.family === 'IPv4') {
assert.strictEqual(net.isIPv4(iface.address), true);
@ -171,7 +171,7 @@ function _validateContent(report, fields = []) {
assert(typeof frame === 'object' && frame !== null);
checkForUnknownFields(frame, ['pc', 'symbol']);
assert.strictEqual(typeof frame.pc, 'string');
assert(/^0x[0-9a-f]+$/.test(frame.pc));
assert.match(frame.pc, /^0x[0-9a-f]+$/);
assert.strictEqual(typeof frame.symbol, 'string');
});
@ -250,7 +250,7 @@ function _validateContent(report, fields = []) {
report.libuv.forEach((resource) => {
assert.strictEqual(typeof resource.type, 'string');
assert.strictEqual(typeof resource.address, 'string');
assert(/^0x[0-9a-f]+$/.test(resource.address));
assert.match(resource.address, /^0x[0-9a-f]+$/);
assert.strictEqual(typeof resource.is_active, 'boolean');
assert.strictEqual(typeof resource.is_referenced,
resource.type === 'loop' ? 'undefined' : 'boolean');

View File

@ -142,7 +142,7 @@ TEST(function test_lookup_ipv6_hint(done) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'EAI_BADFLAGS');
assert.strictEqual(err.hostname, addresses.INET_HOST);
assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message));
assert.match(err.message, /getaddrinfo EAI_BADFLAGS/);
done();
return;
}

View File

@ -527,7 +527,7 @@ TEST(function test_lookup_failure(done) {
assert.ok(err instanceof Error);
assert.strictEqual(err.code, dns.NOTFOUND);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.ok(!/ENOENT/.test(err.message));
assert.doesNotMatch(err.message, !/ENOENT/);
assert.ok(err.message.includes(addresses.NOT_FOUND));
done();
@ -640,7 +640,7 @@ TEST(function test_lookupservice_invalid(done) {
const req = dns.lookupService('1.2.3.4', 80, (err) => {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.ok(/1\.2\.3\.4/.test(err.message));
assert.match(err.message, /1\.2\.3\.4/);
done();
});
@ -662,7 +662,7 @@ TEST(function test_reverse_failure(done) {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code...
assert.strictEqual(err.hostname, '203.0.113.0');
assert.ok(/203\.0\.113\.0/.test(err.message));
assert.match(err.message, /203\.0\.113\.0/);
done();
});

View File

@ -28,7 +28,7 @@ function check(url, cb) {
});
res.on('end', common.mustCall(() => {
assert(/>Debugging Guide</.test(result));
assert.match(result, />Debugging Guide</);
cb();
}));
})).on('error', common.mustNotCall);

View File

@ -136,7 +136,7 @@ promises.push(assert.rejects(
assert.strictEqual(err.code, 'ERR_ASSERTION');
assert.strictEqual(err.actual, actual);
assert.strictEqual(err.operator, 'rejects');
assert(/rejects/.test(err.stack));
assert.match(err.stack, /rejects/);
return true;
};
const err = new Error();

View File

@ -1246,7 +1246,7 @@ assert.throws(
assert.deepStrictEqual(Array(100).fill(1), 'foobar');
} catch (err) {
threw = true;
assert(/actual: \[Array],\n expected: 'foobar',/.test(inspect(err)));
assert.match(inspect(err), /actual: \[Array],\n expected: 'foobar',/);
}
assert(threw);
}

View File

@ -21,5 +21,5 @@ const ret = spawnSync(
assert.strictEqual(ret.status, 0,
`EXIT CODE: ${ret.status}, STDERR:\n${ret.stderr}`);
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.ok(!/async.*hook/i.test(stderr));
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);

View File

@ -19,5 +19,5 @@ const util = require('util');
{
const buf = Buffer.from('x'.repeat(51));
assert.ok(/^<Buffer (?:78 ){50}\.\.\. 1 more byte>$/.test(util.inspect(buf)));
assert.match(util.inspect(buf), /^<Buffer (?:78 ){50}\.\.\. 1 more byte>$/);
}

View File

@ -29,7 +29,7 @@ syntaxArgs.forEach(function(arg) {
assert.strictEqual(c.stdout, '');
// stderr should have a syntax error message
assert(syntaxErrorRE.test(c.stderr), `${syntaxErrorRE} === ${c.stderr}`);
assert.match(c.stderr, syntaxErrorRE);
assert.strictEqual(c.status, 1);
});
@ -50,7 +50,7 @@ syntaxArgs.forEach(function(arg) {
assert.strictEqual(c.stdout, '');
// stderr should have a syntax error message
assert(syntaxErrorRE.test(c.stderr), `${syntaxErrorRE} === ${c.stderr}`);
assert.match(c.stderr, syntaxErrorRE);
assert.strictEqual(c.status, 1);
});

View File

@ -23,7 +23,7 @@ if (!process.argv[2]) {
workerOnline: common.mustCall((msg) => {
}),
mainWindowHandle: common.mustCall((msg) => {
assert.ok(/0\s*/.test(msg.value));
assert.match(msg.value, /0\s*/);
}),
workerExit: common.mustCall((msg) => {
assert.strictEqual(msg.code, 0);

View File

@ -34,7 +34,7 @@ const { join } = require('path');
const p = fixtures.path('leakedGlobal.js');
execFile(process.execPath, [p], common.mustCall((err, stdout, stderr) => {
assert.notStrictEqual(err.code, 0);
assert.ok(/\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/.test(stderr));
assert.match(stderr, /\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/);
}));
}
@ -130,7 +130,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
// Test `tmpdir`.
{
tmpdir.refresh();
assert.ok(/\.tmp\.\d+/.test(tmpdir.path));
assert.match(tmpdir.path, /\.tmp\.\d+/);
const sentinelPath = join(tmpdir.path, 'gaga');
writeFileSync(sentinelPath, 'googoo');
tmpdir.refresh();

View File

@ -246,24 +246,27 @@ assert.ok(strings[0].includes('foo: { bar: { baz:'));
assert.ok(strings[0].includes('quux'));
assert.ok(strings.shift().includes('quux: true'));
assert.ok(/^label: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^__proto__: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^constructor: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^hasOwnProperty: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.match(strings.shift().trim(), /^label: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^__proto__: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^constructor: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^hasOwnProperty: \d+(\.\d{1,3})?(ms|s)$/);
// Verify that console.time() coerces label values to strings as expected
assert.ok(/^: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^null: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^NaN: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.match(strings.shift().trim(), /^: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(),
/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(),
/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^null: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^NaN: \d+(\.\d{1,3})?(ms|s)$/);
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) test$/.test(strings.shift().trim()));
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/.test(strings.shift().trim()));
assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim()));
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/);
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s) test$/);
assert.match(strings.shift().trim(),
/^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/);
assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/);
// Make sure that we checked all strings
assert.strictEqual(strings.length, 0);

View File

@ -105,10 +105,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
const { publicKey, privateKey } = ret;
assert.strictEqual(typeof publicKey, 'string');
assert(pkcs1PubExp.test(publicKey));
assert.match(publicKey, pkcs1PubExp);
assertApproximateSize(publicKey, 162);
assert.strictEqual(typeof privateKey, 'string');
assert(pkcs8Exp.test(privateKey));
assert.match(privateKey, pkcs8Exp);
assertApproximateSize(privateKey, 512);
testEncryptDecrypt(publicKey, privateKey);
@ -183,7 +183,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assertApproximateSize(publicKeyDER, 74);
assert.strictEqual(typeof privateKey, 'string');
assert(pkcs1PrivExp.test(privateKey));
assert.match(privateKey, pkcs1PrivExp);
assertApproximateSize(privateKey, 512);
const publicKey = { key: publicKeyDER, ...publicKeyEncoding };
@ -207,7 +207,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
assertApproximateSize(publicKeyDER, 74);
assert.strictEqual(typeof privateKey, 'string');
assert(pkcs1EncExp('AES-256-CBC').test(privateKey));
assert.match(privateKey, pkcs1EncExp('AES-256-CBC'));
// Since the private key is encrypted, signing shouldn't work anymore.
const publicKey = { key: publicKeyDER, ...publicKeyEncoding };
@ -367,7 +367,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
}, common.mustSucceed((publicKey, privateKeyDER) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.match(publicKey, spkiExp);
// The private key is DER-encoded.
assert(Buffer.isBuffer(privateKeyDER));
@ -432,9 +432,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.match(publicKey, spkiExp);
assert.strictEqual(typeof privateKey, 'string');
assert(sec1Exp.test(privateKey));
assert.match(privateKey, sec1Exp);
testSignVerify(publicKey, privateKey);
}));
@ -454,9 +454,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.match(publicKey, spkiExp);
assert.strictEqual(typeof privateKey, 'string');
assert(sec1Exp.test(privateKey));
assert.match(privateKey, sec1Exp);
testSignVerify(publicKey, privateKey);
}));
@ -477,9 +477,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.match(publicKey, spkiExp);
assert.strictEqual(typeof privateKey, 'string');
assert(sec1EncExp('AES-128-CBC').test(privateKey));
assert.match(privateKey, sec1EncExp('AES-128-CBC'));
// Since the private key is encrypted, signing shouldn't work anymore.
assert.throws(() => testSignVerify(publicKey, privateKey),
@ -511,9 +511,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.match(publicKey, spkiExp);
assert.strictEqual(typeof privateKey, 'string');
assert(sec1EncExp('AES-128-CBC').test(privateKey));
assert.match(privateKey, sec1EncExp('AES-128-CBC'));
// Since the private key is encrypted, signing shouldn't work anymore.
assert.throws(() => testSignVerify(publicKey, privateKey),
@ -548,9 +548,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.match(publicKey, spkiExp);
assert.strictEqual(typeof privateKey, 'string');
assert(pkcs8EncExp.test(privateKey));
assert.match(privateKey, pkcs8EncExp);
// Since the private key is encrypted, signing shouldn't work anymore.
assert.throws(() => testSignVerify(publicKey, privateKey),
@ -585,9 +585,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.match(publicKey, spkiExp);
assert.strictEqual(typeof privateKey, 'string');
assert(pkcs8EncExp.test(privateKey));
assert.match(privateKey, pkcs8EncExp);
// Since the private key is encrypted, signing shouldn't work anymore.
assert.throws(() => testSignVerify(publicKey, privateKey),
@ -759,11 +759,11 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
}).then(common.mustCall((keys) => {
const { publicKey, privateKey } = keys;
assert.strictEqual(typeof publicKey, 'string');
assert(pkcs1PubExp.test(publicKey));
assert.match(publicKey, pkcs1PubExp);
assertApproximateSize(publicKey, 180);
assert.strictEqual(typeof privateKey, 'string');
assert(pkcs1PrivExp.test(privateKey));
assert.match(privateKey, pkcs1PrivExp);
assertApproximateSize(privateKey, 512);
testEncryptDecrypt(publicKey, privateKey);

View File

@ -19,7 +19,7 @@ if (cluster.isPrimary) {
const socket = dgram.createSocket('udp4');
socket.on('error', common.mustCall((err) => {
assert(/^Error: bind UNKNOWN 0\.0\.0\.0$/.test(err.toString()));
assert.match(err.toString(), /^Error: bind UNKNOWN 0\.0\.0\.0$/);
process.nextTick(common.mustCall(() => {
assert.strictEqual(socket._bindState, 0); // BIND_STATE_UNBOUND
socket.close();

View File

@ -11,7 +11,7 @@ s.on('error', common.mustCall((err) => {
s.close();
// Don't check the full error message, as the errno is not important here.
assert(/^Error: recvmsg/.test(err));
assert.match(String(err), /^Error: recvmsg/);
assert.strictEqual(err.syscall, 'recvmsg');
}));

View File

@ -37,7 +37,7 @@ d.on('error', common.mustCall(function(er) {
assert.strictEqual(er.domainThrown, true);
assert.ok(!er.domainEmitter);
assert.strictEqual(er.actual.code, 'ENOENT');
assert.ok(/\bthis file does not exist\b/i.test(er.actual.path));
assert.match(er.actual.path, /\bthis file does not exist\b/i);
assert.strictEqual(typeof er.actual.errno, 'number');
}));

View File

@ -44,38 +44,39 @@ const syntaxErrorMessage = /\bSyntaxError\b/;
// Simple throw error
errExec('throws_error.js', common.mustCall((err, stdout, stderr) => {
assert.ok(/blah/.test(stderr));
assert.match(stderr, /blah/);
}));
// Trying to JSON.parse(undefined)
errExec('throws_error2.js', common.mustCall((err, stdout, stderr) => {
assert.ok(syntaxErrorMessage.test(stderr));
assert.match(stderr, syntaxErrorMessage);
}));
// Trying to JSON.parse(undefined) in nextTick
errExec('throws_error3.js', common.mustCall((err, stdout, stderr) => {
assert.ok(syntaxErrorMessage.test(stderr));
assert.match(stderr, syntaxErrorMessage);
}));
// throw ILLEGAL error
errExec('throws_error4.js', common.mustCall((err, stdout, stderr) => {
assert.ok(syntaxErrorMessage.test(stderr));
assert.match(stderr, syntaxErrorMessage);
}));
// Specific long exception line doesn't result in stack overflow
errExec('throws_error5.js', common.mustCall((err, stdout, stderr) => {
assert.ok(syntaxErrorMessage.test(stderr));
assert.match(stderr, syntaxErrorMessage);
}));
// Long exception line with length > errorBuffer doesn't result in assertion
errExec('throws_error6.js', common.mustCall((err, stdout, stderr) => {
assert.ok(syntaxErrorMessage.test(stderr));
assert.match(stderr, syntaxErrorMessage);
}));
// Object that throws in toString() doesn't print garbage
errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => {
assert.ok(/throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/.test(stderr));
assert.match(stderr,
/throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/);
}));

View File

@ -22,7 +22,7 @@ for (let i = 0; i < 10; i++) {
assert(Object.prototype.toString.call(err), '[object Error]');
assert.strictEqual(err.name, 'Error');
assert.strictEqual(err.message, 'foo');
assert(/^Error: foo\n/.test(err.stack));
assert.match(err.stack, /^Error: foo\n/);
const prev = err;
err = cycle(err);
@ -45,7 +45,7 @@ assert.strictEqual(cycle(Function), '[Function: Function]');
{
const err = new ERR_INVALID_ARG_TYPE('object', 'Object', 42);
assert(/^TypeError \[ERR_INVALID_ARG_TYPE\]:/.test(err));
assert.match(String(err), /^TypeError \[ERR_INVALID_ARG_TYPE\]:/);
assert.strictEqual(err.name, 'TypeError');
assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE');
}

View File

@ -9,7 +9,7 @@ process.on('uncaughtException', common.mustCall((err) => {
const lines = err.stack.split('\n');
assert.strictEqual(lines[0], 'Error');
lines.slice(1).forEach((line) => {
assert(/^ at/.test(line), `${line} has an unexpected format`);
assert.match(line, /^ at/);
});
}));

View File

@ -199,8 +199,7 @@ function re(literals, ...values) {
`expect ${err.dest} to end with 'foo'`);
const regexp = new RegExp('^ENOENT: no such file or directory, link ' +
re`'${nonexistentFile}' -> ` + '\'.*foo\'');
assert.ok(regexp.test(err.message),
`Expect ${err.message} to match ${regexp}`);
assert.match(err.message, regexp);
assert.strictEqual(err.errno, UV_ENOENT);
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.syscall, 'link');
@ -291,8 +290,7 @@ function re(literals, ...values) {
`expect ${err.dest} to end with 'foo'`);
const regexp = new RegExp('ENOENT: no such file or directory, rename ' +
re`'${nonexistentFile}' -> ` + '\'.*foo\'');
assert.ok(regexp.test(err.message),
`Expect ${err.message} to match ${regexp}`);
assert.match(err.message, regexp);
assert.strictEqual(err.errno, UV_ENOENT);
assert.strictEqual(err.code, 'ENOENT');
assert.strictEqual(err.syscall, 'rename');
@ -641,13 +639,11 @@ if (!common.isAIX) {
{
const validateError = (err) => {
const pathPrefix = new RegExp('^' + re`${nonexistentDir}`);
assert(pathPrefix.test(err.path),
`Expect ${err.path} to match ${pathPrefix}`);
assert.match(err.path, pathPrefix);
const prefix = new RegExp('^ENOENT: no such file or directory, mkdtemp ' +
re`'${nonexistentDir}`);
assert(prefix.test(err.message),
`Expect ${err.message} to match ${prefix}`);
assert.match(err.message, prefix);
assert.strictEqual(err.errno, UV_ENOENT);
assert.strictEqual(err.code, 'ENOENT');

View File

@ -29,7 +29,7 @@ fs.mkdir(d, 0o666, common.mustSucceed(() => {
fs.mkdir(d, 0o666, common.mustCall(function(err) {
assert.strictEqual(this, undefined);
assert.ok(err, 'got no error');
assert.ok(/^EEXIST/.test(err.message), 'got no EEXIST message');
assert.match(err.message, /^EEXIST/);
assert.strictEqual(err.code, 'EEXIST');
assert.strictEqual(err.path, d);

View File

@ -47,13 +47,13 @@ function test(env, cb) {
}
test({ NODE_DEBUG: '' }, common.mustCall((data) => {
assert(/EISDIR/.test(data));
assert(/test-fs-readfile-error/.test(data));
assert.match(data, /EISDIR/);
assert.match(data, /test-fs-readfile-error/);
}));
test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => {
assert(/EISDIR/.test(data));
assert(/test-fs-readfile-error/.test(data));
assert.match(data, /EISDIR/);
assert.match(data, /test-fs-readfile-error/);
}));
assert.throws(

View File

@ -28,7 +28,7 @@ process.on('exit', () => {
process.stderr.write = (data) => {
if (writeTimes === 0)
assert.ok(leakWarning.test(data));
assert.match(data, leakWarning);
else
assert.fail('stderr.write should be called only once');

View File

@ -57,9 +57,9 @@ function test(statusCode) {
conn.on('end', common.mustCall(() => {
// Connection: close should be in the response
assert.strictEqual(/^Connection: close\r\n$/m.test(resp), true);
assert.match(resp, /^Connection: close\r\n$/m);
// Make sure this doesn't end with 0\r\n\r\n
assert.strictEqual(/^0\r\n$/m.test(resp), false);
assert.doesNotMatch(resp, /^0\r\n$/m);
}));
})
);

View File

@ -19,7 +19,7 @@ server.listen(0, () => {
// header, which is a violation of the HTTP spec.
const req = http.get({ port: server.address().port }, common.mustNotCall());
req.on('error', common.mustCall((err) => {
assert(/^Parse Error/.test(err.message));
assert.match(err.message, /^Parse Error/);
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
server.close();
}));

View File

@ -18,7 +18,7 @@ server.listen(0, () => {
// header field that ends only in \r with no following \n
const req = http.get({ port: server.address().port }, common.mustNotCall());
req.on('error', common.mustCall((err) => {
assert(/^Parse Error/.test(err.message));
assert.match(err.message, /^Parse Error/);
assert.strictEqual(err.code, 'HPE_LF_EXPECTED');
server.close();
}));

View File

@ -9,7 +9,7 @@ const assert = require('assert');
// Content-Length header is received.
const server = http.createServer(common.mustNotCall());
server.on('clientError', common.mustCall((err, socket) => {
assert(/^Parse Error/.test(err.message));
assert.match(err.message, /^Parse Error/);
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
socket.destroy();
}));

View File

@ -11,7 +11,7 @@ const str = 'GET / HTTP/1.1\r\n' +
const server = http.createServer(common.mustNotCall());
server.on('clientError', common.mustCall((err, socket) => {
assert(/^Parse Error/.test(err.message));
assert.match(err.message, /^Parse Error/);
assert.strictEqual(err.code, 'HPE_INVALID_EOF_STATE');
socket.destroy();
}, 1));

View File

@ -11,7 +11,7 @@ const reqstr = 'POST / HTTP/1.1\r\n' +
const server = http.createServer(common.mustNotCall());
server.on('clientError', common.mustCall((err) => {
assert(/^Parse Error/.test(err.message));
assert.match(err.message, /^Parse Error/);
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
server.close();
}));

View File

@ -13,7 +13,7 @@ const str = 'GET / HTTP/1.1\r\n' +
const server = http.createServer(common.mustNotCall());
server.on('clientError', common.mustCall((err) => {
assert(/^Parse Error/.test(err.message));
assert.match(err.message, /^Parse Error/);
assert.strictEqual(err.code, 'HPE_LF_EXPECTED');
server.close();
}));

View File

@ -131,10 +131,10 @@ process.on('exit', function() {
assert.strictEqual(requests_sent, 4);
const hello = new RegExp('/hello');
assert.ok(hello.test(server_response));
assert.match(server_response, hello);
const quit = new RegExp('/quit');
assert.ok(quit.test(server_response));
assert.match(server_response, quit);
assert.strictEqual(client_got_eof, true);
});

View File

@ -15,14 +15,14 @@ server.on('error', common.mustNotCall());
server.on('session', (session) => {
session.on('close', common.mustCall());
session.on('error', common.mustCall((err) => {
assert.ok(errRegEx.test(err), `server session err: ${err}`);
assert.match(err.message, errRegEx);
assert.strictEqual(session.closed, false);
assert.strictEqual(session.destroyed, true);
}));
session.on('stream', common.mustCall((stream) => {
stream.on('error', common.mustCall((err) => {
assert.ok(errRegEx.test(err), `server stream err: ${err}`);
assert.match(err.message, errRegEx);
assert.strictEqual(session.closed, false);
assert.strictEqual(session.destroyed, true);
assert.strictEqual(stream.rstCode, destroyCode);
@ -36,7 +36,7 @@ server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
session.on('error', common.mustCall((err) => {
assert.ok(errRegEx.test(err), `client session err: ${err}`);
assert.match(err.message, errRegEx);
assert.strictEqual(session.closed, false);
assert.strictEqual(session.destroyed, true);
}));
@ -44,7 +44,7 @@ server.listen(0, common.mustCall(() => {
const stream = session.request({ [http2.constants.HTTP2_HEADER_PATH]: '/' });
stream.on('error', common.mustCall((err) => {
assert.ok(errRegEx.test(err), `client stream err: ${err}`);
assert.match(err.message, errRegEx);
assert.strictEqual(stream.rstCode, destroyCode);
}));

View File

@ -11,10 +11,10 @@ const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
assert.strictEqual(stream.aborted, false);
const insp = util.inspect(stream);
assert.ok(/Http2Stream {/.test(insp));
assert.ok(/ state:/.test(insp));
assert.ok(/ readableState:/.test(insp));
assert.ok(/ writableState:/.test(insp));
assert.match(insp, /Http2Stream {/);
assert.match(insp, / state:/);
assert.match(insp, / readableState:/);
assert.match(insp, / writableState:/);
stream.end('ok');
}));
server.listen(0, common.mustCall(() => {

View File

@ -29,8 +29,8 @@ const checkRequest = (socket, server) => {
result += chunk;
}));
socket.on('end', common.mustCall(() => {
assert(expectedHeader.test(result));
assert(expectedBody.test(result));
assert.match(result, expectedHeader);
assert.match(result, expectedBody);
server.close();
}));
};
@ -112,7 +112,7 @@ function createServer() {
const options = null;
const socket = agent.createConnection(port, host, options);
socket.on('error', common.mustCall((e) => {
assert(expectCertError.test(e.toString()));
assert.match(e.toString(), expectCertError);
server.close();
}));
}));
@ -127,7 +127,7 @@ function createServer() {
const options = undefined;
const socket = agent.createConnection(port, host, options);
socket.on('error', common.mustCall((e) => {
assert(expectCertError.test(e.toString()));
assert.match(e.toString(), expectCertError);
server.close();
}));
}));

View File

@ -58,7 +58,7 @@ function test(next) {
const conn = req.connection;
conn.on('error', (err) => {
console.error(`Caught exception: ${err}`);
assert(/TLS session renegotiation attack/.test(err));
assert.match(err.message, /TLS session renegotiation attack/);
conn.destroy();
});
res.end('ok');

View File

@ -27,7 +27,7 @@ session.post('Runtime.evaluate', {
assert.ifError(error);
const { exception } = res.exceptionDetails;
assert.strictEqual(exception.className, 'EvalError');
assert(/Possible side-effect/.test(exception.description));
assert.match(exception.description, /Possible side-effect/);
assert(context); // Keep 'context' alive and make linter happy.
});

View File

@ -26,7 +26,7 @@ assert.throws(
);
if (process.platform === 'win32') {
assert.strictEqual(/^\\\\\?\\/.test(preprocessSymlinkDestination), true);
assert.match(preprocessSymlinkDestination, /^\\\\\?\\/);
} else {
assert.strictEqual(preprocessSymlinkDestination, pathString);
}

View File

@ -31,9 +31,9 @@ function checkStack(stack) {
// displays the line of code (`var foo bar;`) that is causing a problem.
// ChakraCore does not display the line of code but includes `;` in the phrase
// `Expected ';' `.
assert.ok(/;/g.test(stack));
assert.match(stack, /;/g);
// Test that it's a multiline string.
assert.ok(/\n/g.test(stack));
assert.match(stack, /\n/g);
}
let err;
const badSyntaxPath =

View File

@ -194,7 +194,7 @@ function canConnect(port) {
function asyncFailToConnect(port) {
const onError = () => common.mustCall((err) => {
const regexp = /^Error: connect E\w+.+$/;
assert(regexp.test(String(err)), String(err));
assert.match(String(err), regexp);
});
const dont = () => common.mustNotCall();

View File

@ -85,7 +85,7 @@ function randomPipePath() {
server2.on('error', common.mustCall((err) => {
server1.close();
assert.strictEqual(err.code, 'EADDRINUSE');
assert(/^listen EADDRINUSE: address already in use/.test(err.message));
assert.match(err.message, /^listen EADDRINUSE: address already in use/);
}));
});
}

View File

@ -75,7 +75,7 @@ if (common.isWindows) {
const endianness = os.endianness();
is.string(endianness);
assert.ok(/[BL]E/.test(endianness));
assert.match(endianness, /[BL]E/);
const hostname = os.hostname();
is.string(hostname);
@ -110,7 +110,7 @@ is.string(release);
assert.ok(release.length > 0);
// TODO: Check format on more than just AIX
if (common.isAIX)
assert.ok(/^\d+\.\d+$/.test(release));
assert.match(release, /^\d+\.\d+$/);
const platform = os.platform();
is.string(platform);

View File

@ -168,7 +168,7 @@ childProcess.exec(
fixtures.path('cluster-preload-test.js')}"`,
function(err, stdout, stderr) {
assert.ifError(err);
assert.ok(/worker terminated with code 43/.test(stdout));
assert.match(stdout, /worker terminated with code 43/);
}
);
@ -198,6 +198,6 @@ childProcess.exec(
{ cwd: fixtures.fixturesDir },
function(err, stdout, stderr) {
assert.ifError(err);
assert.ok(/worker terminated with code 43/.test(stdout));
assert.match(stdout, /worker terminated with code 43/);
}
);

View File

@ -12,7 +12,7 @@ const testType = 'CustomWarning';
process.on('warning', common.mustCall((warning) => {
assert(warning);
assert(/^(?:Warning|CustomWarning)/.test(warning.name));
assert.match(warning.name, /^(?:Warning|CustomWarning)/);
assert.strictEqual(warning.message, testMsg);
if (warning.code) assert.strictEqual(warning.code, testCode);
if (warning.detail) assert.strictEqual(warning.detail, testDetail);

View File

@ -51,8 +51,7 @@ const assert = require('assert');
// Assert all "canonical" flags begin with dash(es)
{
process.allowedNodeEnvironmentFlags.forEach((flag) => {
assert(/^--?[a-zA-Z0-9._-]+$/.test(flag),
`Unexpected format for flag ${flag}`);
assert.match(flag, /^--?[a-zA-Z0-9._-]+$/);
});
}

View File

@ -21,6 +21,6 @@ const warnpath = path.join(tmpdir.path, 'warnings.txt');
fork(warnmod, { env: { ...process.env, NODE_REDIRECT_WARNINGS: warnpath } })
.on('exit', common.mustCall(() => {
fs.readFile(warnpath, 'utf8', common.mustSucceed((data) => {
assert(/\(node:\d+\) Warning: a bad practice warning/.test(data));
assert.match(data, /\(node:\d+\) Warning: a bad practice warning/);
}));
}));

View File

@ -21,6 +21,6 @@ const warnpath = path.join(tmpdir.path, 'warnings.txt');
fork(warnmod, { execArgv: [`--redirect-warnings=${warnpath}`] })
.on('exit', common.mustCall(() => {
fs.readFile(warnpath, 'utf8', common.mustSucceed((data) => {
assert(/\(node:\d+\) Warning: a bad practice warning/.test(data));
assert.match(data, /\(node:\d+\) Warning: a bad practice warning/);
}));
}));

View File

@ -38,16 +38,18 @@ assert.deepStrictEqual(actual_keys, expected_keys);
const commonTemplate = /^\d+\.\d+\.\d+(?:-.*)?$/;
assert(commonTemplate.test(process.versions.ares));
assert(commonTemplate.test(process.versions.brotli));
assert(commonTemplate.test(process.versions.llhttp));
assert(commonTemplate.test(process.versions.node));
assert(commonTemplate.test(process.versions.uv));
assert(commonTemplate.test(process.versions.zlib));
assert.match(process.versions.ares, commonTemplate);
assert.match(process.versions.brotli, commonTemplate);
assert.match(process.versions.llhttp, commonTemplate);
assert.match(process.versions.node, commonTemplate);
assert.match(process.versions.uv, commonTemplate);
assert.match(process.versions.zlib, commonTemplate);
assert(/^\d+\.\d+\.\d+(?:\.\d+)?-node\.\d+(?: \(candidate\))?$/
.test(process.versions.v8));
assert(/^\d+$/.test(process.versions.modules));
assert.match(
process.versions.v8,
/^\d+\.\d+\.\d+(?:\.\d+)?-node\.\d+(?: \(candidate\))?$/
);
assert.match(process.versions.modules, /^\d+$/);
if (common.hasCrypto) {
const versionRegex = common.hasOpenSSL3 ?
@ -56,7 +58,7 @@ if (common.hasCrypto) {
// and linking against the main development branch of OpenSSL.
/^\d+\.\d+\.\d+(?:[-+][a-z0-9]+)*$/ :
/^\d+\.\d+\.\d+[a-z]?(\+quic)?(-fips)?$/;
assert(versionRegex.test(process.versions.openssl));
assert.match(process.versions.openssl, versionRegex);
}
for (let i = 0; i < expected_keys.length; i++) {

View File

@ -32,13 +32,15 @@ oStream.on('end', common.mustCall(() => {
const expect = 'process.stdout\r\n' +
'process.stdin\r\n' +
'process.stderr';
assert(new RegExp(expect).test(output));
assert.match(output, new RegExp(expect));
}));
iStream.write('process.s\t');
assert(/process\.std\b/.test(output)); // Completion works.
assert(!/stdout/.test(output)); // Completion doesnt show all results yet.
// Completion works.
assert.match(output, /process\.std\b/);
// Completion doesnt show all results yet.
assert.doesNotMatch(output, /stdout/);
iStream.write('\t');
oStream.end();

View File

@ -35,9 +35,8 @@ r.defineCommand('say2', function() {
});
inputStream.write('.help\n');
assert(/\n\.say1 help for say1\n/.test(output),
'help for say1 not present');
assert(/\n\.say2\n/.test(output), 'help for say2 not present');
assert.match(output, /\n\.say1 help for say1\n/);
assert.match(output, /\n\.say2\n/);
inputStream.write('.say1 node developer\n');
assert.ok(output.startsWith('hello node developer\n'),
`say1 output starts incorrectly: "${output}"`);

View File

@ -43,7 +43,7 @@ child.stdout.on('data', (d) => {
out += d;
});
child.stdout.on('end', () => {
assert(expectOut.test(out));
assert.match(out, expectOut);
console.log('ok');
});

View File

@ -30,8 +30,8 @@ function testStrictMode() {
const cli = initRepl(repl.REPL_MODE_STRICT);
cli.input.emit('data', 'x = 3\n');
assert.ok(/ReferenceError: x is not defined/.test(
cli.output.accumulator.join('')));
assert.match(cli.output.accumulator.join(''),
/ReferenceError: x is not defined/);
cli.output.accumulator.length = 0;
cli.input.emit('data', 'let y = 3\n');

View File

@ -33,8 +33,8 @@ const repl = require('repl');
});
process.on('exit', function() {
assert.strictEqual(/Cannot find module/.test(answer), false);
assert.strictEqual(/Error/.test(answer), false);
assert.doesNotMatch(answer, /Cannot find module/);
assert.doesNotMatch(answer, /Error/);
assert.strictEqual(answer, '\'eye catcher\'\n\'perhaps I work\'\n');
});
}
@ -63,9 +63,9 @@ const repl = require('repl');
});
process.on('exit', function() {
assert.strictEqual(/Uncaught Error: Cannot find module '\.\/bar'/.test(answer), true);
assert.match(answer, /Uncaught Error: Cannot find module '\.\/bar'/);
assert.strictEqual(/code: 'MODULE_NOT_FOUND'/.test(answer), true);
assert.strictEqual(/requireStack: \[ '<repl>' \]/.test(answer), true);
assert.match(answer, /code: 'MODULE_NOT_FOUND'/);
assert.match(answer, /requireStack: \[ '<repl>' \]/);
});
}

View File

@ -40,5 +40,5 @@ setTimeout(() => {
const len = process.listenerCount('uncaughtException');
process.removeAllListeners('uncaughtException');
assert.strictEqual(len, 0);
assert(/ERR_INVALID_REPL_INPUT.*(?!Type)RangeError: abc/s.test(accum));
assert.match(accum, /ERR_INVALID_REPL_INPUT.*(?!Type)RangeError: abc/s);
}, 2);

View File

@ -24,7 +24,7 @@ function run({ command, expected, useColors = false }) {
if (typeof expected === 'string') {
assert.strictEqual(accum, expected);
} else {
assert(expected.test(accum), accum);
assert.match(accum, expected);
}
// Verify that the repl is still working as expected.

View File

@ -199,7 +199,7 @@ function testError() {
if (typeof expected === 'string')
assert.strictEqual(line, expected);
else
assert(expected.test(line), `${line} should match ${expected}`);
assert.match(line, expected);
}
assert.strictEqual(expectedLines.length, 0);

View File

@ -26,7 +26,7 @@ child.stdout.on('data', (d) => {
});
child.stdout.on('end', () => {
assert(expectOut.test(out));
assert.match(out, expectOut);
console.log('ok');
});

View File

@ -90,8 +90,7 @@ async function runReplTests(socket, prompt, tests) {
if (typeof expectedLine === 'string') {
assert.strictEqual(actualLine, expectedLine);
} else {
assert(expectedLine.test(actualLine),
`${actualLine} match ${expectedLine}`);
assert.match(actualLine, expectedLine);
}
}
}

View File

@ -10,5 +10,5 @@ const child_process = require('child_process');
const args = ['--tls-min-v1.3', '--tls-max-v1.2', '-p', 'process.version'];
child_process.execFile(process.argv[0], args, (err) => {
assert(err);
assert(/not both/.test(err.message));
assert.match(err.message, /not both/);
});

View File

@ -56,7 +56,7 @@ function test(next) {
const server = tls.createServer(options, (conn) => {
conn.on('error', (err) => {
console.error(`Caught exception: ${err}`);
assert(/TLS session renegotiation attack/.test(err));
assert.match(err.message, /TLS session renegotiation attack/);
conn.destroy();
});
conn.pipe(conn);

View File

@ -47,6 +47,6 @@ const server = tls.createServer({
process.on('exit', function() {
assert(clientError);
assert(/socket hang up/.test(clientError.message));
assert(/ECONNRESET/.test(clientError.code));
assert.match(clientError.message, /socket hang up/);
assert.match(clientError.code, /ECONNRESET/);
});

View File

@ -16,7 +16,7 @@ const options = {
const server = tls.createServer(options, (c) => {
assert.fail('Should not be called');
}).on('tlsClientError', common.mustCall((err, c) => {
assert(/SSL_use_certificate:passed a null parameter/i.test(err.message));
assert.match(err.message, /SSL_use_certificate:passed a null parameter/i);
server.close();
})).listen(0, common.mustCall(() => {
const c = tls.connect({
@ -26,6 +26,6 @@ const server = tls.createServer(options, (c) => {
}, common.mustNotCall());
c.on('error', common.mustCall((err) => {
assert(/Client network socket disconnected/.test(err.message));
assert.match(err.message, /Client network socket disconnected/);
}));
}));

View File

@ -35,8 +35,8 @@ child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(stdout.trim(), '');
assert(/Warning: Enabling --trace-tls can expose sensitive/.test(stderr));
assert(/Sent Record/.test(stderr));
assert.match(stderr, /Warning: Enabling --trace-tls can expose sensitive/);
assert.match(stderr, /Sent Record/);
}));
function test() {

View File

@ -23,8 +23,8 @@ let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => stderr += data);
child.on('close', common.mustCall(() => {
assert(/Received Record/.test(stderr));
assert(/ClientHello/.test(stderr));
assert.match(stderr, /Received Record/);
assert.match(stderr, /ClientHello/);
}));
// For debugging and observation of actual trace output.

View File

@ -38,7 +38,7 @@ fork(__filename, opts)
// encoding-wise
if (!common.isWindows) {
const re = /Warning: Ignoring extra certs from.*no-such-file-exists-🐢.* load failed:.*No such file or directory/;
assert(re.test(stderr), stderr);
assert.match(stderr, re);
}
}))
.stderr.setEncoding('utf8').on('data', function(str) {

View File

@ -22,7 +22,7 @@ if (process.argv[2] === 'child') {
assert.strictEqual(result.stdout.toString().trim(), '');
// Verify that the error was thrown and that the stack was preserved.
const stderr = result.stderr.toString();
assert(/Error: boom/.test(stderr));
assert(/at throwException/.test(stderr));
assert(/rethrow: true/.test(stderr));
assert.match(stderr, /Error: boom/);
assert.match(stderr, /at throwException/);
assert.match(stderr, /rethrow: true/);
}

View File

@ -27,4 +27,4 @@ const assert = require('assert');
console.log('Σὲ γνωρίζω ἀπὸ τὴν κόψη');
assert.strictEqual(/Hellö Wörld/.test('Hellö Wörld'), true);
assert.match('Hellö Wörld', /Hellö Wörld/);

View File

@ -9,7 +9,7 @@ const { emitExperimentalWarning } = require('internal/util');
// when passed the same feature multiple times.
process.on('warning', common.mustCall((warning) => {
assert(/is an experimental feature/.test(warning.message));
assert.match(warning.message, /is an experimental feature/);
}, 2));
emitExperimentalWarning('feature1');

View File

@ -156,12 +156,14 @@ assert.match(util.inspect((new JSStream())._externalStream),
assert.strictEqual(util.inspect({ a: regexp }, false, 0), '{ a: /regexp/ }');
}
assert(/Object/.test(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true)
));
assert(!/Object/.test(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true)
));
assert.match(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true),
/Object/
);
assert.doesNotMatch(
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true),
/Object/
);
{
const showHidden = true;
@ -1467,13 +1469,13 @@ if (typeof Symbol !== 'undefined') {
// Set single option through property assignment.
util.inspect.defaultOptions.maxArrayLength = null;
assert(!/1 more item/.test(util.inspect(arr)));
assert.doesNotMatch(util.inspect(arr), /1 more item/);
util.inspect.defaultOptions.maxArrayLength = oldOptions.maxArrayLength;
assert(/1 more item/.test(util.inspect(arr)));
assert.match(util.inspect(arr), /1 more item/);
util.inspect.defaultOptions.depth = null;
assert(!/Object/.test(util.inspect(obj)));
assert.doesNotMatch(util.inspect(obj), /Object/);
util.inspect.defaultOptions.depth = oldOptions.depth;
assert(/Object/.test(util.inspect(obj)));
assert.match(util.inspect(obj), /Object/);
assert.strictEqual(
JSON.stringify(util.inspect.defaultOptions),
JSON.stringify(oldOptions)
@ -1481,11 +1483,11 @@ if (typeof Symbol !== 'undefined') {
// Set multiple options through object assignment.
util.inspect.defaultOptions = { maxArrayLength: null, depth: 2 };
assert(!/1 more item/.test(util.inspect(arr)));
assert(/Object/.test(util.inspect(obj)));
assert.doesNotMatch(util.inspect(arr), /1 more item/);
assert.match(util.inspect(obj), /Object/);
util.inspect.defaultOptions = oldOptions;
assert(/1 more item/.test(util.inspect(arr)));
assert(/Object/.test(util.inspect(obj)));
assert.match(util.inspect(arr), /1 more item/);
assert.match(util.inspect(obj), /Object/);
assert.strictEqual(
JSON.stringify(util.inspect.defaultOptions),
JSON.stringify(oldOptions)
@ -2183,12 +2185,12 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
value.foo = 'bar';
let res = util.inspect(value);
assert.notStrictEqual(res, expectedWithoutProto);
assert(/foo: 'bar'/.test(res), res);
assert.match(res, /foo: 'bar'/);
delete value.foo;
value[Symbol('foo')] = 'yeah';
res = util.inspect(value);
assert.notStrictEqual(res, expectedWithoutProto);
assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res);
assert.match(res, /\[Symbol\(foo\)]: 'yeah'/);
});
assert.strictEqual(inspect(1n), '1n');

View File

@ -33,4 +33,4 @@ try {
getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
}
assert(/bad_syntax\.js:1/.test(arrowMessage));
assert.match(arrowMessage, /bad_syntax\.js:1/);

View File

@ -22,7 +22,6 @@
'use strict';
require('../common');
const assert = require('assert');
const { inspect } = require('util');
const vm = require('vm');
const Script = vm.Script;
let script = new Script('"passed";');
@ -58,8 +57,7 @@ try {
vm.runInContext('throw new Error()', context, 'expected-filename.js');
} catch (e) {
gh1140Exception = e;
assert.ok(/expected-filename/.test(e.stack),
`expected appearance of filename in Error stack: ${inspect(e)}`);
assert.match(e.stack, /expected-filename/);
}
// This is outside of catch block to confirm catch block ran.
assert.strictEqual(gh1140Exception.toString(), 'Error');

View File

@ -19,7 +19,7 @@ let output = '';
p.stderr.on('data', (data) => output += data);
p.stderr.on('end', common.mustCall(() => {
assert(/BEGIN CERT/.test(output));
assert(/^\s+\^/m.test(output));
assert(/Invalid left-hand side expression in prefix operation/.test(output));
assert.match(output, /BEGIN CERT/);
assert.match(output, /^\s+\^/m);
assert.match(output, /Invalid left-hand side expression in prefix operation/);
}));

View File

@ -12,5 +12,5 @@ const worker = new Worker(missing);
worker.on('error', common.mustCall((err) => {
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
assert(/Cannot find module .+does-not-exist.js/.test(err.message), err);
assert.match(err.message, /Cannot find module .+does-not-exist.js/);
}));

View File

@ -36,8 +36,7 @@ function parent() {
if (error) {
w.on('error', common.mustCall((err) => {
console.log(err);
assert(error.test(err),
`wrong error for ${arg}\nexpected:${error} but got:${err}`);
assert.match(String(err), error);
}));
}
w.postMessage(arg);

View File

@ -10,7 +10,7 @@ if (!process.env.HAS_STARTED_WORKER) {
w.on('message', common.mustNotCall());
w.on('error', common.mustCall((err) => {
console.log(err.message);
assert(/^Error: foo$/.test(err));
assert.match(String(err), /^Error: foo$/);
}));
w.on('exit', common.mustCall((code) => {
// uncaughtException is code 1

View File

@ -10,7 +10,7 @@ if (!process.env.HAS_STARTED_WORKER) {
w.on('message', common.mustNotCall());
w.on('error', common.mustCall((err) => {
console.log(err.message);
assert(/^Error: foo$/.test(err));
assert.match(String(err), /^Error: foo$/);
}));
w.on('exit', common.mustCall((code) => {
// uncaughtException is code 1

View File

@ -31,7 +31,7 @@ const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]);
const stream = zlib.createInflate();
stream.on('error', common.mustCall(function(err) {
assert(/Missing dictionary/.test(err.message));
assert.match(err.message, /Missing dictionary/);
}));
stream.write(input);
@ -41,7 +41,7 @@ const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]);
const stream = zlib.createInflate({ dictionary: Buffer.from('fail') });
stream.on('error', common.mustCall(function(err) {
assert(/Bad dictionary/.test(err.message));
assert.match(err.message, /Bad dictionary/);
}));
stream.write(input);
@ -53,7 +53,7 @@ const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]);
stream.on('error', common.mustCall(function(err) {
// It's not possible to separate invalid dict and invalid data when using
// the raw format
assert(/invalid/.test(err.message));
assert.match(err.message, /invalid/);
}));
stream.write(input);

View File

@ -45,7 +45,7 @@ const errMessage = /unexpected end of file/;
// Async truncated input test
zlib[methods.decomp](truncated, function(err, result) {
assert(errMessage.test(err.message));
assert.match(err.message, errMessage);
});
const syncFlushOpt = { finishFlush: zlib.constants.Z_SYNC_FLUSH };

View File

@ -58,7 +58,7 @@ function makeRequest() {
const child = spawn(process.execPath, args);
child.on('exit', function(code) {
assert.ok(/DONE/.test(stderrBuffer));
assert.match(stderrBuffer, /DONE/);
assert.strictEqual(code, 0);
});

View File

@ -39,7 +39,7 @@ const syntaxErrorRE = /^SyntaxError: \b/m;
assert.strictEqual(stdout, '');
// Stderr should have a syntax error message
assert(syntaxErrorRE.test(stderr), `${syntaxErrorRE} === ${stderr}`);
assert.match(stderr, syntaxErrorRE);
// stderr should include the filename
assert(stderr.startsWith(file), `${stderr} starts with ${file}`);

View File

@ -31,7 +31,7 @@ const notFoundRE = /^Error: Cannot find module/m;
assert.strictEqual(stdout, '');
// `stderr` should have a module not found error message.
assert(notFoundRE.test(stderr), `${notFoundRE} === ${stderr}`);
assert.match(stderr, notFoundRE);
assert.strictEqual(err.code, 1,
`code ${err.code} !== 1 for error:\n\n${err}`);

View File

@ -27,7 +27,7 @@ const syntaxErrorRE = /^SyntaxError: \b/m;
assert.strictEqual(stdout, '');
// stderr should have a syntax error message
assert(syntaxErrorRE.test(stderr), `${syntaxErrorRE} === ${stderr}`);
assert.match(stderr, syntaxErrorRE);
// stderr should include the filename
assert(stderr.startsWith(file), `${stderr} starts with ${file}`);

View File

@ -44,7 +44,7 @@ execFile(node, normal, function(er, stdout, stderr) {
console.error('normal: show deprecation warning');
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(/this function is deprecated/.test(stderr));
assert.match(stderr, /this function is deprecated/);
console.log('normal ok');
});
@ -62,8 +62,8 @@ execFile(node, traceDep, function(er, stdout, stderr) {
assert.strictEqual(stdout, '');
const stack = stderr.trim().split('\n');
// Just check the top and bottom.
assert(/this function is deprecated/.test(stack[1]));
assert(/This is deprecated/.test(stack[0]));
assert.match(stack[1], /this function is deprecated/);
assert.match(stack[0], /This is deprecated/);
console.log('trace ok');
});
@ -71,18 +71,18 @@ execFile(node, [depUserlandFunction], function(er, stdout, stderr) {
console.error('normal: testing deprecated userland function');
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(/deprecatedFunction is deprecated/.test(stderr));
assert.match(stderr, /deprecatedFunction is deprecated/);
console.error('normal: ok');
});
execFile(node, [depUserlandClass], function(er, stdout, stderr) {
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(/deprecatedClass is deprecated/.test(stderr));
assert.match(stderr, /deprecatedClass is deprecated/);
});
execFile(node, [depUserlandSubClass], function(er, stdout, stderr) {
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(/deprecatedClass is deprecated/.test(stderr));
assert.match(stderr, /deprecatedClass is deprecated/);
});

View File

@ -37,5 +37,5 @@ const cmd =
`"${process.execPath}" "${fixturesDir}/test-fs-stat-sync-overflow.js"`;
exec(cmd, function(err, stdout, stderr) {
assert(/RangeError: Maximum call stack size exceeded/.test(stderr));
assert.match(stderr, /RangeError: Maximum call stack size exceeded/);
});

View File

@ -24,7 +24,7 @@ if (process.argv[2] === 'child') {
assert.strictEqual(files.length, 2);
for (let i = 0; i < files.length; i++) {
assert(/^Heap\..+\.heapsnapshot$/.test(files[i]));
assert.match(files[i], /^Heap\..+\.heapsnapshot$/);
JSON.parse(fs.readFileSync(files[i]));
}
})();

View File

@ -74,26 +74,26 @@ function afterPing(result) {
const successRE = /success/;
switch (responses.length) {
case 2:
assert.ok(ECONNREFUSED_RE.test(responses[0]));
assert.ok(ECONNREFUSED_RE.test(responses[1]));
assert.match(responses[0], ECONNREFUSED_RE);
assert.match(responses[1], ECONNREFUSED_RE);
serverOn();
break;
case 4:
assert.ok(successRE.test(responses[2]));
assert.ok(successRE.test(responses[3]));
assert.match(responses[2], successRE);
assert.match(responses[3], successRE);
serverOff();
break;
case 6:
assert.ok(ECONNREFUSED_RE.test(responses[4]));
assert.ok(ECONNREFUSED_RE.test(responses[5]));
assert.match(responses[4], ECONNREFUSED_RE);
assert.match(responses[5], ECONNREFUSED_RE);
serverOn();
break;
case 8:
assert.ok(successRE.test(responses[6]));
assert.ok(successRE.test(responses[7]));
assert.match(responses[6], successRE);
assert.match(responses[7], successRE);
server.close();
// We should go to process.on('exit') from here.
break;

View File

@ -19,7 +19,7 @@ function test(arg, port = '') {
proc.stderr.on('close', (hadErr) => assert(!hadErr));
proc.stderr.on('data', () => {
if (!stderr.includes('\n')) return;
assert(/Debugger listening on (.+)/.test(stderr));
assert.match(stderr, /Debugger listening on (.+)/);
port = new URL(RegExp.$1).port;
assert(+port > 0);
});

View File

@ -32,8 +32,8 @@ function checkVersion(response) {
function checkBadPath(err) {
assert(err instanceof SyntaxError);
assert(/Unexpected token/.test(err.message), err.message);
assert(/WebSockets request was expected/.test(err.body), err.body);
assert.match(err.message, /Unexpected token/);
assert.match(err.body, /WebSockets request was expected/);
}
function checkException(message) {

View File

@ -214,9 +214,9 @@ assert.throws(
(e) => {
// Not a real .node module, but we know we require'd the right thing.
if (common.isOpenBSD) { // OpenBSD errors with non-ELF object error
assert.ok(/File not an ELF object/.test(e.message.replace(backslash, '/')));
assert.match(e.message, /File not an ELF object/);
} else {
assert.ok(/file3\.node/.test(e.message.replace(backslash, '/')));
assert.match(e.message, /file3\.node/);
}
return true;
}
@ -229,9 +229,9 @@ assert.throws(
() => require(`${loadOrder}file7`),
(e) => {
if (common.isOpenBSD) {
assert.ok(/File not an ELF object/.test(e.message.replace(backslash, '/')));
assert.match(e.message, /File not an ELF object/);
} else {
assert.ok(/file7\/index\.node/.test(e.message.replace(backslash, '/')));
assert.match(e.message.replace(backslash, '/'), /file7\/index\.node/);
}
return true;
}

View File

@ -17,20 +17,20 @@ execFile(node, normal, function(er, stdout, stderr) {
// Show Process Warnings
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(warningMessage.test(stderr));
assert.match(stderr, warningMessage);
});
execFile(node, noWarn, function(er, stdout, stderr) {
// Hide Process Warnings
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(!warningMessage.test(stderr));
assert.doesNotMatch(stderr, warningMessage);
});
execFile(node, traceWarn, function(er, stdout, stderr) {
// Show Warning Trace
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert(warningMessage.test(stderr));
assert(/at Object\.<anonymous>\s\(.+warnings\.js:3:9\)/.test(stderr));
assert.match(stderr, warningMessage);
assert.match(stderr, /at Object\.<anonymous>\s\(.+warnings\.js:3:9\)/);
});

View File

@ -39,6 +39,6 @@ if (process.argv[2] === 'child') {
});
process.on('exit', function() {
assert.ok(/Script execution timed out after 1ms/.test(err));
assert.match(err, /Script execution timed out after 1ms/);
});
}

View File

@ -52,8 +52,8 @@ function runPolyfill(content) {
[
'--prof-process', LOG_FILE,
]);
assert(WARN_REG_EXP.test(child.stderr.toString()));
assert(WARN_DETAIL_REG_EXP.test(child.stderr.toString()));
assert.match(child.stderr.toString(), WARN_REG_EXP);
assert.match(child.stderr.toString(), WARN_DETAIL_REG_EXP);
assert.strictEqual(child.status, 0);
}