test: remove assert.doesNotThrow()

There is actually no reason to use `assert.doesNotThrow()` in the
tests. If a test throws, just let the error bubble up right away
instead of first catching it and then rethrowing it.

PR-URL: https://github.com/nodejs/node/pull/18669
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Ruben Bridgewater 2018-02-09 02:32:04 +01:00
parent 4d3c3f039a
commit caee112e52
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
124 changed files with 598 additions and 1012 deletions

View File

@ -81,7 +81,7 @@ const y = {};
test_general.wrap(y);
test_general.removeWrap(y);
// Wrapping twice succeeds if a remove_wrap() separates the instances
assert.doesNotThrow(() => test_general.wrap(y));
test_general.wrap(y);
// Ensure that removing a wrap and garbage collecting does not fire the
// finalize callback.

View File

@ -30,5 +30,5 @@ const sub = require('./submodule');
const mod = require(path.join(i, 'binding.node'));
assert.notStrictEqual(mod, null);
assert.strictEqual(mod.hello(), 'world');
assert.doesNotThrow(() => sub.test(i));
sub.test(i);
});

View File

@ -10,7 +10,7 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// addMembership() with valid socket and multicast address should not throw
{
const socket = setup();
assert.doesNotThrow(() => { socket.addMembership(multicastAddress); });
socket.addMembership(multicastAddress);
socket.close();
}
@ -27,11 +27,7 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// dropMembership() after addMembership() should not throw
{
const socket = setup();
assert.doesNotThrow(
() => {
socket.addMembership(multicastAddress);
socket.dropMembership(multicastAddress);
}
);
socket.addMembership(multicastAddress);
socket.dropMembership(multicastAddress);
socket.close();
}

View File

@ -580,14 +580,10 @@ process.on('exit', function() {
});
assert.doesNotThrow(() =>
dns.lookup(addresses.INET6_HOST, 6, common.mustCall()));
dns.lookup(addresses.INET6_HOST, 6, common.mustCall());
assert.doesNotThrow(() =>
dns.lookup(addresses.INET_HOST, {}, common.mustCall()));
dns.lookup(addresses.INET_HOST, {}, common.mustCall());
assert.doesNotThrow(() =>
dns.lookupService('0.0.0.0', '0', common.mustCall()));
dns.lookupService('0.0.0.0', '0', common.mustCall());
assert.doesNotThrow(() =>
dns.lookupService('0.0.0.0', 0, common.mustCall()));
dns.lookupService('0.0.0.0', 0, common.mustCall());

View File

@ -30,8 +30,8 @@ function re(literals, ...values) {
FakeDate.prototype = Date.prototype;
const fake = new FakeDate();
assert.doesNotThrow(() => assert.deepEqual(date, fake));
assert.doesNotThrow(() => assert.deepEqual(fake, date));
assert.deepEqual(date, fake);
assert.deepEqual(fake, date);
// For deepStrictEqual we check the runtime type,
// then reveal the fakeness of the fake date
@ -47,7 +47,7 @@ function re(literals, ...values) {
for (const prop of Object.keys(global)) {
fakeGlobal[prop] = global[prop];
}
assert.doesNotThrow(() => assert.deepEqual(fakeGlobal, global));
assert.deepEqual(fakeGlobal, global);
// Message will be truncated anyway, don't validate
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global),
assert.AssertionError);
@ -59,7 +59,7 @@ function re(literals, ...values) {
for (const prop of Object.keys(process)) {
fakeProcess[prop] = process[prop];
}
assert.doesNotThrow(() => assert.deepEqual(fakeProcess, process));
assert.deepEqual(fakeProcess, process);
// Message will be truncated anyway, don't validate
assert.throws(() => assert.deepStrictEqual(fakeProcess, process),
assert.AssertionError);

View File

@ -34,7 +34,7 @@ const buf = Buffer.from(arr);
// They have different [[Prototype]]
assert.throws(() => assert.deepStrictEqual(arr, buf),
re`${arr} deepStrictEqual ${buf}`);
assert.doesNotThrow(() => assert.deepEqual(arr, buf));
assert.deepEqual(arr, buf);
{
const buf2 = Buffer.from(arr);
@ -42,7 +42,7 @@ assert.doesNotThrow(() => assert.deepEqual(arr, buf));
assert.throws(() => assert.deepStrictEqual(buf2, buf),
re`${buf2} deepStrictEqual ${buf}`);
assert.doesNotThrow(() => assert.deepEqual(buf2, buf));
assert.deepEqual(buf2, buf);
}
{
@ -50,7 +50,7 @@ assert.doesNotThrow(() => assert.deepEqual(arr, buf));
arr2.prop = 5;
assert.throws(() => assert.deepStrictEqual(arr, arr2),
re`${arr} deepStrictEqual ${arr2}`);
assert.doesNotThrow(() => assert.deepEqual(arr, arr2));
assert.deepEqual(arr, arr2);
}
const date = new Date('2016');
@ -66,8 +66,8 @@ const date2 = new MyDate('2016');
// deepEqual returns true as long as the time are the same,
// but deepStrictEqual checks own properties
assert.doesNotThrow(() => assert.deepEqual(date, date2));
assert.doesNotThrow(() => assert.deepEqual(date2, date));
assert.deepEqual(date, date2);
assert.deepEqual(date2, date);
assert.throws(() => assert.deepStrictEqual(date, date2),
re`${date} deepStrictEqual ${date2}`);
assert.throws(() => assert.deepStrictEqual(date2, date),
@ -85,7 +85,7 @@ const re2 = new MyRegExp('test');
// deepEqual returns true as long as the regexp-specific properties
// are the same, but deepStrictEqual checks all properties
assert.doesNotThrow(() => assert.deepEqual(re1, re2));
assert.deepEqual(re1, re2);
assert.throws(() => assert.deepStrictEqual(re1, re2),
re`${re1} deepStrictEqual ${re2}`);
@ -148,11 +148,11 @@ function assertNotDeepOrStrict(a, b, err) {
}
function assertOnlyDeepEqual(a, b, err) {
assert.doesNotThrow(() => assert.deepEqual(a, b));
assert.deepEqual(a, b);
assert.throws(() => assert.deepStrictEqual(a, b), err ||
re`${a} deepStrictEqual ${b}`);
assert.doesNotThrow(() => assert.deepEqual(b, a));
assert.deepEqual(b, a);
assert.throws(() => assert.deepStrictEqual(b, a), err ||
re`${b} deepStrictEqual ${a}`);
}
@ -492,10 +492,9 @@ assertOnlyDeepEqual([1, , , 3], [1, , , 3, , , ]);
// Handle NaN
assert.throws(() => { assert.deepEqual(NaN, NaN); }, assert.AssertionError);
assert.doesNotThrow(() => { assert.deepStrictEqual(NaN, NaN); });
assert.doesNotThrow(() => { assert.deepStrictEqual({ a: NaN }, { a: NaN }); });
assert.doesNotThrow(
() => { assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]); });
{ assert.deepStrictEqual(NaN, NaN); }
{ assert.deepStrictEqual({ a: NaN }, { a: NaN }); }
assert.deepStrictEqual([ 1, 2, NaN, 4 ], [ 1, 2, NaN, 4 ]);
// Handle boxed primitives
{
@ -547,9 +546,7 @@ assertDeepAndStrictEqual(-0, -0);
assertDeepAndStrictEqual(a, b);
}
assert.doesNotThrow(
() => assert.deepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14)),
'deepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))');
assert.deepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14));
assert.throws(() => assert.deepEqual(new Date(), new Date(2000, 3, 14)),
AssertionError,
@ -561,16 +558,13 @@ assert.throws(
'notDeepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))'
);
assert.doesNotThrow(
() => assert.notDeepEqual(new Date(), new Date(2000, 3, 14)),
'notDeepEqual(new Date(), new Date(2000, 3, 14))'
);
assert.notDeepEqual(new Date(), new Date(2000, 3, 14));
assert.doesNotThrow(() => assert.deepEqual(/a/, /a/));
assert.doesNotThrow(() => assert.deepEqual(/a/g, /a/g));
assert.doesNotThrow(() => assert.deepEqual(/a/i, /a/i));
assert.doesNotThrow(() => assert.deepEqual(/a/m, /a/m));
assert.doesNotThrow(() => assert.deepEqual(/a/igm, /a/igm));
assert.deepEqual(/a/, /a/);
assert.deepEqual(/a/g, /a/g);
assert.deepEqual(/a/i, /a/i);
assert.deepEqual(/a/m, /a/m);
assert.deepEqual(/a/igm, /a/igm);
assert.throws(() => assert.deepEqual(/ab/, /a/),
{
code: 'ERR_ASSERTION',
@ -605,23 +599,23 @@ assert.throws(() => assert.deepEqual(/a/igm, /a/im),
{
const re1 = /a/g;
re1.lastIndex = 3;
assert.doesNotThrow(() => assert.deepEqual(re1, /a/g));
assert.deepEqual(re1, /a/g);
}
assert.doesNotThrow(() => assert.deepEqual(4, '4'), 'deepEqual(4, \'4\')');
assert.doesNotThrow(() => assert.deepEqual(true, 1), 'deepEqual(true, 1)');
assert.deepEqual(4, '4');
assert.deepEqual(true, 1);
assert.throws(() => assert.deepEqual(4, '5'),
AssertionError,
'deepEqual( 4, \'5\')');
// Having the same number of owned properties && the same set of keys.
assert.doesNotThrow(() => assert.deepEqual({ a: 4 }, { a: 4 }));
assert.doesNotThrow(() => assert.deepEqual({ a: 4, b: '2' }, { a: 4, b: '2' }));
assert.doesNotThrow(() => assert.deepEqual([4], ['4']));
assert.deepEqual({ a: 4 }, { a: 4 });
assert.deepEqual({ a: 4, b: '2' }, { a: 4, b: '2' });
assert.deepEqual([4], ['4']);
assert.throws(
() => assert.deepEqual({ a: 4 }, { a: 4, b: true }), AssertionError);
assert.doesNotThrow(() => assert.deepEqual(['a'], { 0: 'a' }));
assert.doesNotThrow(() => assert.deepEqual({ a: 4, b: '1' }, { b: '1', a: 4 }));
assert.deepEqual(['a'], { 0: 'a' });
assert.deepEqual({ a: 4, b: '1' }, { b: '1', a: 4 });
const a1 = [1, 2, 3];
const a2 = [1, 2, 3];
a1.a = 'test';
@ -630,7 +624,7 @@ a2.b = true;
a2.a = 'test';
assert.throws(() => assert.deepEqual(Object.keys(a1), Object.keys(a2)),
AssertionError);
assert.doesNotThrow(() => assert.deepEqual(a1, a2));
assert.deepEqual(a1, a2);
// Having an identical prototype property.
const nbRoot = {
@ -654,11 +648,11 @@ nameBuilder2.prototype = nbRoot;
const nb1 = new nameBuilder('Ryan', 'Dahl');
let nb2 = new nameBuilder2('Ryan', 'Dahl');
assert.doesNotThrow(() => assert.deepEqual(nb1, nb2));
assert.deepEqual(nb1, nb2);
nameBuilder2.prototype = Object;
nb2 = new nameBuilder2('Ryan', 'Dahl');
assert.doesNotThrow(() => assert.deepEqual(nb1, nb2));
assert.deepEqual(nb1, nb2);
// Primitives and object.
assert.throws(() => assert.deepEqual(null, {}), AssertionError);
@ -670,21 +664,15 @@ assert.throws(() => assert.deepEqual(true, {}), AssertionError);
assert.throws(() => assert.deepEqual(Symbol(), {}), AssertionError);
// Primitive wrappers and object.
assert.doesNotThrow(() => assert.deepEqual(new String('a'), ['a']),
AssertionError);
assert.doesNotThrow(() => assert.deepEqual(new String('a'), { 0: 'a' }),
AssertionError);
assert.doesNotThrow(() => assert.deepEqual(new Number(1), {}), AssertionError);
assert.doesNotThrow(() => assert.deepEqual(new Boolean(true), {}),
AssertionError);
assert.deepEqual(new String('a'), ['a']);
assert.deepEqual(new String('a'), { 0: 'a' });
assert.deepEqual(new Number(1), {});
assert.deepEqual(new Boolean(true), {});
// Same number of keys but different key names.
assert.throws(() => assert.deepEqual({ a: 1 }, { b: 1 }), AssertionError);
assert.doesNotThrow(
() => assert.deepStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14)),
'deepStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))'
);
assert.deepStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14));
assert.throws(
() => assert.deepStrictEqual(new Date(), new Date(2000, 3, 14)),
@ -698,16 +686,13 @@ assert.throws(
'notDeepStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))'
);
assert.doesNotThrow(
() => assert.notDeepStrictEqual(new Date(), new Date(2000, 3, 14)),
'notDeepStrictEqual(new Date(), new Date(2000, 3, 14))'
);
assert.notDeepStrictEqual(new Date(), new Date(2000, 3, 14));
assert.doesNotThrow(() => assert.deepStrictEqual(/a/, /a/));
assert.doesNotThrow(() => assert.deepStrictEqual(/a/g, /a/g));
assert.doesNotThrow(() => assert.deepStrictEqual(/a/i, /a/i));
assert.doesNotThrow(() => assert.deepStrictEqual(/a/m, /a/m));
assert.doesNotThrow(() => assert.deepStrictEqual(/a/igm, /a/igm));
assert.deepStrictEqual(/a/, /a/);
assert.deepStrictEqual(/a/g, /a/g);
assert.deepStrictEqual(/a/i, /a/i);
assert.deepStrictEqual(/a/m, /a/m);
assert.deepStrictEqual(/a/igm, /a/igm);
assert.throws(
() => assert.deepStrictEqual(/ab/, /a/),
{
@ -747,7 +732,7 @@ assert.throws(
{
const re1 = /a/;
re1.lastIndex = 3;
assert.doesNotThrow(() => assert.deepStrictEqual(re1, /a/));
assert.deepStrictEqual(re1, /a/);
}
assert.throws(() => assert.deepStrictEqual(4, '4'),
@ -763,9 +748,8 @@ assert.throws(() => assert.deepStrictEqual(4, '5'),
'deepStrictEqual(4, \'5\')');
// Having the same number of owned properties && the same set of keys.
assert.doesNotThrow(() => assert.deepStrictEqual({ a: 4 }, { a: 4 }));
assert.doesNotThrow(
() => assert.deepStrictEqual({ a: 4, b: '2' }, { a: 4, b: '2' }));
assert.deepStrictEqual({ a: 4 }, { a: 4 });
assert.deepStrictEqual({ a: 4, b: '2' }, { a: 4, b: '2' });
assert.throws(() => assert.deepStrictEqual([4], ['4']),
{
code: 'ERR_ASSERTION',
@ -787,14 +771,13 @@ assert.throws(() => assert.deepStrictEqual(['a'], { 0: 'a' }),
/* eslint-enable */
assert.doesNotThrow(
() => assert.deepStrictEqual({ a: 4, b: '1' }, { b: '1', a: 4 }));
assert.deepStrictEqual({ a: 4, b: '1' }, { b: '1', a: 4 });
assert.throws(
() => assert.deepStrictEqual([0, 1, 2, 'a', 'b'], [0, 1, 2, 'b', 'a']),
AssertionError);
assert.doesNotThrow(() => assert.deepStrictEqual(a1, a2));
assert.deepStrictEqual(a1, a2);
// Prototype check.
function Constructor1(first, last) {
@ -815,7 +798,7 @@ assert.throws(() => assert.deepStrictEqual(obj1, obj2), AssertionError);
Constructor2.prototype = Constructor1.prototype;
obj2 = new Constructor2('Ryan', 'Dahl');
assert.doesNotThrow(() => assert.deepStrictEqual(obj1, obj2));
assert.deepStrictEqual(obj1, obj2);
// primitives
assert.throws(() => assert.deepStrictEqual(4, '4'), AssertionError);
@ -824,7 +807,7 @@ assert.throws(() => assert.deepStrictEqual(Symbol(), Symbol()),
AssertionError);
const s = Symbol();
assert.doesNotThrow(() => assert.deepStrictEqual(s, s));
assert.deepStrictEqual(s, s);
// Primitives and object.
assert.throws(() => assert.deepStrictEqual(null, {}), AssertionError);

View File

@ -67,9 +67,9 @@ assert.throws(
}
);
assert.doesNotThrow(() => { assert.ifError(null); });
assert.doesNotThrow(() => { assert.ifError(); });
assert.doesNotThrow(() => { assert.ifError(undefined); });
assert.ifError(null);
assert.ifError();
assert.ifError(undefined);
// https://github.com/nodejs/node-v0.x-archive/issues/2893
{

View File

@ -38,32 +38,22 @@ assert.ok(a.AssertionError.prototype instanceof Error,
'a.AssertionError instanceof Error');
assert.throws(() => a(false), a.AssertionError, 'ok(false)');
assert.doesNotThrow(() => a(true), a.AssertionError, 'ok(true)');
assert.doesNotThrow(() => a('test', 'ok(\'test\')'));
assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)');
assert.doesNotThrow(() => a.ok(true), a.AssertionError, 'ok(true)');
assert.doesNotThrow(() => a.ok('test'), 'ok(\'test\')');
a(true);
a('test', 'ok(\'test\')');
a.ok(true);
a.ok('test');
assert.throws(() => a.equal(true, false),
a.AssertionError, 'equal(true, false)');
assert.doesNotThrow(() => a.equal(null, null), 'equal(null, null)');
assert.doesNotThrow(() => a.equal(undefined, undefined),
'equal(undefined, undefined)');
assert.doesNotThrow(() => a.equal(null, undefined), 'equal(null, undefined)');
assert.doesNotThrow(() => a.equal(true, true), 'equal(true, true)');
assert.doesNotThrow(() => a.equal(2, '2'), 'equal(2, \'2\')');
assert.doesNotThrow(() => a.notEqual(true, false), 'notEqual(true, false)');
a.equal(null, null);
a.equal(undefined, undefined);
a.equal(null, undefined);
a.equal(true, true);
a.equal(2, '2');
a.notEqual(true, false);
assert.throws(() => a.notEqual(true, true),
a.AssertionError, 'notEqual(true, true)');
@ -77,7 +67,7 @@ assert.throws(() => a.strictEqual(null, undefined),
assert.throws(() => a.notStrictEqual(2, 2),
a.AssertionError, 'notStrictEqual(2, 2)');
assert.doesNotThrow(() => a.notStrictEqual(2, '2'), 'notStrictEqual(2, \'2\')');
a.notStrictEqual(2, '2');
// Testing the throwing.
function thrower(errorConstructor) {

View File

@ -63,16 +63,16 @@ assert.throws(() => b.write('test', 'utf8', 0),
// try to create 0-length buffers
assert.doesNotThrow(() => Buffer.from(''));
assert.doesNotThrow(() => Buffer.from('', 'ascii'));
assert.doesNotThrow(() => Buffer.from('', 'latin1'));
assert.doesNotThrow(() => Buffer.alloc(0));
assert.doesNotThrow(() => Buffer.allocUnsafe(0));
assert.doesNotThrow(() => new Buffer(''));
assert.doesNotThrow(() => new Buffer('', 'ascii'));
assert.doesNotThrow(() => new Buffer('', 'latin1'));
assert.doesNotThrow(() => new Buffer('', 'binary'));
assert.doesNotThrow(() => Buffer(0));
Buffer.from('');
Buffer.from('', 'ascii');
Buffer.from('', 'latin1');
Buffer.alloc(0);
Buffer.allocUnsafe(0);
new Buffer('');
new Buffer('', 'ascii');
new Buffer('', 'latin1');
new Buffer('', 'binary');
Buffer(0);
// try to write a 0-length string beyond the end of b
assert.throws(() => b.write('', 2048), RangeError);
@ -109,7 +109,7 @@ b.copy(Buffer.alloc(1), 0, 2048, 2048);
// Offset points to the end of the buffer
// (see https://github.com/nodejs/node/issues/8127).
assert.doesNotThrow(() => Buffer.alloc(1).write('', 1, 0));
Buffer.alloc(1).write('', 1, 0);
// ASCII slice test
{
@ -963,7 +963,7 @@ assert.strictEqual(SlowBuffer.prototype.offset, undefined);
Buffer.from(''));
// Check pool offset after that by trying to write string into the pool.
assert.doesNotThrow(() => Buffer.from('abc'));
Buffer.from('abc');
}
@ -993,12 +993,12 @@ common.expectsError(() => {
}
// Regression test
assert.doesNotThrow(() => Buffer.from(new ArrayBuffer()));
Buffer.from(new ArrayBuffer());
// Test that ArrayBuffer from a different context is detected correctly
const arrayBuf = vm.runInNewContext('new ArrayBuffer()');
assert.doesNotThrow(() => Buffer.from(arrayBuf));
assert.doesNotThrow(() => Buffer.from({ buffer: arrayBuf }));
Buffer.from(arrayBuf);
Buffer.from({ buffer: arrayBuf });
assert.throws(() => Buffer.alloc({ valueOf: () => 1 }),
/"size" argument must be of type number/);

View File

@ -2,9 +2,7 @@
const common = require('../common');
const assert = require('assert');
assert.doesNotThrow(function() {
Buffer.allocUnsafe(10);
});
Buffer.allocUnsafe(10);
const err = common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
@ -16,6 +14,4 @@ assert.throws(function() {
Buffer.from(10, 'hex');
}, err);
assert.doesNotThrow(function() {
Buffer.from('deadbeaf', 'hex');
});
Buffer.from('deadbeaf', 'hex');

View File

@ -11,7 +11,7 @@ assert(MAX_STRING_LENGTH <= MAX_LENGTH);
assert.throws(() => ' '.repeat(MAX_STRING_LENGTH + 1),
/^RangeError: Invalid string length$/);
assert.doesNotThrow(() => ' '.repeat(MAX_STRING_LENGTH));
' '.repeat(MAX_STRING_LENGTH);
// Legacy values match:
assert.strictEqual(kMaxLength, MAX_LENGTH);

View File

@ -93,7 +93,7 @@ bb.fill('hello crazy world');
// try to copy from before the beginning of b
assert.doesNotThrow(() => { b.copy(c, 0, 100, 10); });
b.copy(c, 0, 100, 10);
// copy throws at negative sourceStart
assert.throws(function() {

View File

@ -51,10 +51,8 @@ assert.strictEqual(util.inspect(s), expected);
buffer.INSPECT_MAX_BYTES = Infinity;
assert.doesNotThrow(function() {
assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);
});
assert.strictEqual(util.inspect(b), expected);
assert.strictEqual(util.inspect(s), expected);
b.inspect = undefined;
assert.strictEqual(util.inspect(b), expected);

View File

@ -15,11 +15,7 @@ function read(buff, funx, args, expected) {
}
);
assert.doesNotThrow(
() => assert.strictEqual(buff[funx](...args, true), expected),
'noAssert does not change return value for valid ranges'
);
assert.strictEqual(buff[funx](...args, true), expected);
}
// testing basic functionality of readDoubleBE() and readDoubleLE()

View File

@ -26,4 +26,4 @@ assert.deepStrictEqual(arr_buf, ar_buf);
assert.strictEqual(Buffer.byteLength(sab), sab.byteLength);
assert.doesNotThrow(() => Buffer.from({ buffer: sab }));
Buffer.from({ buffer: sab });

View File

@ -79,7 +79,7 @@ const utf16Buf = Buffer.from('0123456789', 'utf16le');
assert.deepStrictEqual(utf16Buf.slice(0, 6), Buffer.from('012', 'utf16le'));
// try to slice a zero length Buffer
// see https://github.com/joyent/node/issues/5881
assert.doesNotThrow(() => Buffer.alloc(0).slice(0, 1));
Buffer.alloc(0).slice(0, 1);
assert.strictEqual(Buffer.alloc(0).slice(0, 1).length, 0);
{

View File

@ -39,7 +39,5 @@ process.on('exit', function() {
assert.throws(function() {
process.kill(child.pid);
}, /^Error: kill ESRCH$/);
assert.doesNotThrow(function() {
process.kill(persistentPid);
});
process.kill(persistentPid);
});

View File

@ -41,21 +41,10 @@ assert.throws(function() {
}, TypeError);
// verify that valid argument combinations do not throw
assert.doesNotThrow(function() {
spawn(cmd);
});
assert.doesNotThrow(function() {
spawn(cmd, []);
});
assert.doesNotThrow(function() {
spawn(cmd, {});
});
assert.doesNotThrow(function() {
spawn(cmd, [], {});
});
spawn(cmd);
spawn(cmd, []);
spawn(cmd, {});
spawn(cmd, [], {});
// verify that invalid argument combinations throw
assert.throws(function() {
@ -100,14 +89,14 @@ const n = null;
// (f, a)
// (f, a, o)
// (f, o)
assert.doesNotThrow(function() { spawn(cmd); });
assert.doesNotThrow(function() { spawn(cmd, a); });
assert.doesNotThrow(function() { spawn(cmd, a, o); });
assert.doesNotThrow(function() { spawn(cmd, o); });
spawn(cmd);
spawn(cmd, a);
spawn(cmd, a, o);
spawn(cmd, o);
// Variants of undefined as explicit 'no argument' at a position
assert.doesNotThrow(function() { spawn(cmd, u, o); });
assert.doesNotThrow(function() { spawn(cmd, a, u); });
spawn(cmd, u, o);
spawn(cmd, a, u);
assert.throws(function() { spawn(cmd, n, o); }, invalidArgTypeError);
assert.throws(function() { spawn(cmd, a, n); }, invalidArgTypeError);
@ -128,36 +117,36 @@ assert.throws(function() { spawn(cmd, a, s); }, invalidArgTypeError);
// (f, o)
// (f, o, c)
// (f, c)
assert.doesNotThrow(function() { execFile(cmd); });
assert.doesNotThrow(function() { execFile(cmd, a); });
assert.doesNotThrow(function() { execFile(cmd, a, o); });
assert.doesNotThrow(function() { execFile(cmd, a, o, c); });
assert.doesNotThrow(function() { execFile(cmd, a, c); });
assert.doesNotThrow(function() { execFile(cmd, o); });
assert.doesNotThrow(function() { execFile(cmd, o, c); });
assert.doesNotThrow(function() { execFile(cmd, c); });
execFile(cmd);
execFile(cmd, a);
execFile(cmd, a, o);
execFile(cmd, a, o, c);
execFile(cmd, a, c);
execFile(cmd, o);
execFile(cmd, o, c);
execFile(cmd, c);
// Variants of undefined as explicit 'no argument' at a position
assert.doesNotThrow(function() { execFile(cmd, u, o, c); });
assert.doesNotThrow(function() { execFile(cmd, a, u, c); });
assert.doesNotThrow(function() { execFile(cmd, a, o, u); });
assert.doesNotThrow(function() { execFile(cmd, n, o, c); });
assert.doesNotThrow(function() { execFile(cmd, a, n, c); });
assert.doesNotThrow(function() { execFile(cmd, a, o, n); });
assert.doesNotThrow(function() { execFile(cmd, u, u, u); });
assert.doesNotThrow(function() { execFile(cmd, u, u, c); });
assert.doesNotThrow(function() { execFile(cmd, u, o, u); });
assert.doesNotThrow(function() { execFile(cmd, a, u, u); });
assert.doesNotThrow(function() { execFile(cmd, n, n, n); });
assert.doesNotThrow(function() { execFile(cmd, n, n, c); });
assert.doesNotThrow(function() { execFile(cmd, n, o, n); });
assert.doesNotThrow(function() { execFile(cmd, a, n, n); });
assert.doesNotThrow(function() { execFile(cmd, a, u); });
assert.doesNotThrow(function() { execFile(cmd, a, n); });
assert.doesNotThrow(function() { execFile(cmd, o, u); });
assert.doesNotThrow(function() { execFile(cmd, o, n); });
assert.doesNotThrow(function() { execFile(cmd, c, u); });
assert.doesNotThrow(function() { execFile(cmd, c, n); });
execFile(cmd, u, o, c);
execFile(cmd, a, u, c);
execFile(cmd, a, o, u);
execFile(cmd, n, o, c);
execFile(cmd, a, n, c);
execFile(cmd, a, o, n);
execFile(cmd, u, u, u);
execFile(cmd, u, u, c);
execFile(cmd, u, o, u);
execFile(cmd, a, u, u);
execFile(cmd, n, n, n);
execFile(cmd, n, n, c);
execFile(cmd, n, o, n);
execFile(cmd, a, n, n);
execFile(cmd, a, u);
execFile(cmd, a, n);
execFile(cmd, o, u);
execFile(cmd, o, n);
execFile(cmd, c, u);
execFile(cmd, c, n);
// string is invalid in arg position (this may seem strange, but is
// consistent across node API, cf. `net.createServer('not options', 'not
@ -173,7 +162,7 @@ assert.throws(function() { execFile(cmd, a, u, s); }, invalidArgValueError);
assert.throws(function() { execFile(cmd, a, n, s); }, invalidArgValueError);
assert.throws(function() { execFile(cmd, u, o, s); }, invalidArgValueError);
assert.throws(function() { execFile(cmd, n, o, s); }, invalidArgValueError);
assert.doesNotThrow(function() { execFile(cmd, c, s); });
execFile(cmd, c, s);
// verify that fork has same argument parsing behavior as spawn
@ -183,16 +172,16 @@ assert.doesNotThrow(function() { execFile(cmd, c, s); });
// (f, a)
// (f, a, o)
// (f, o)
assert.doesNotThrow(function() { fork(empty); });
assert.doesNotThrow(function() { fork(empty, a); });
assert.doesNotThrow(function() { fork(empty, a, o); });
assert.doesNotThrow(function() { fork(empty, o); });
assert.doesNotThrow(function() { fork(empty, u, u); });
assert.doesNotThrow(function() { fork(empty, u, o); });
assert.doesNotThrow(function() { fork(empty, a, u); });
assert.doesNotThrow(function() { fork(empty, n, n); });
assert.doesNotThrow(function() { fork(empty, n, o); });
assert.doesNotThrow(function() { fork(empty, a, n); });
fork(empty);
fork(empty, a);
fork(empty, a, o);
fork(empty, o);
fork(empty, u, u);
fork(empty, u, o);
fork(empty, a, u);
fork(empty, n, n);
fork(empty, n, o);
fork(empty, a, n);
assert.throws(function() { fork(empty, s); }, invalidArgValueError);
assert.throws(function() { fork(empty, a, s); }, invalidArgValueError);

View File

@ -2,7 +2,6 @@
const common = require('../common');
const { Console } = require('console');
const { Writable } = require('stream');
const assert = require('assert');
for (const method of ['dir', 'log', 'warn']) {
const out = new Writable({
@ -13,7 +12,5 @@ for (const method of ['dir', 'log', 'warn']) {
const c = new Console(out, out, true);
assert.doesNotThrow(() => {
c[method]('abc');
});
c[method]('abc');
}

View File

@ -87,9 +87,7 @@ out.write = common.mustCall((d) => {
[1, 2, 3].forEach(c.log);
// Console() detects if it is called without `new` keyword
assert.doesNotThrow(() => {
Console(out, err);
});
Console(out, err);
// Instance that does not ignore the stream errors.
const c2 = new Console(out, err, false);

View File

@ -2,13 +2,10 @@
require('../common');
const assert = require('assert');
const { test, assert_equals, assert_true, assert_false } =
require('../common/wpt');
assert.doesNotThrow(() => {
global.console = global.console;
});
global.console = global.console;
const self = global;

View File

@ -2,7 +2,6 @@
const common = require('../common');
const { Console } = require('console');
const { Writable } = require('stream');
const assert = require('assert');
for (const method of ['dir', 'log', 'warn']) {
{
@ -14,9 +13,7 @@ for (const method of ['dir', 'log', 'warn']) {
const c = new Console(out, out, true);
assert.doesNotThrow(() => {
c[method]('abc');
});
c[method]('abc');
}
{
@ -28,9 +25,7 @@ for (const method of ['dir', 'log', 'warn']) {
const c = new Console(out, out, true);
assert.doesNotThrow(() => {
c[method]('abc');
});
c[method]('abc');
}
{
@ -42,8 +37,6 @@ for (const method of ['dir', 'log', 'warn']) {
const c = new Console(out, out, true);
assert.doesNotThrow(() => {
c[method]('abc');
});
c[method]('abc');
}
}

View File

@ -29,18 +29,14 @@ assert.ok(process.stderr.writable);
assert.strictEqual(typeof process.stdout.fd, 'number');
assert.strictEqual(typeof process.stderr.fd, 'number');
assert.doesNotThrow(function() {
process.once('warning', common.mustCall((warning) => {
assert(/no such label/.test(warning.message));
}));
process.once('warning', common.mustCall((warning) => {
assert(/no such label/.test(warning.message));
}));
console.timeEnd('no such label');
});
console.timeEnd('no such label');
assert.doesNotThrow(function() {
console.time('label');
console.timeEnd('label');
});
console.time('label');
console.timeEnd('label');
// Check that the `Error` is a `TypeError` but do not check the message as it
// will be different in different JavaScript engines.
@ -140,15 +136,11 @@ console.timeEnd();
console.time(NaN);
console.timeEnd(NaN);
assert.doesNotThrow(() => {
console.assert(false, '%s should', 'console.assert', 'not throw');
assert.strictEqual(errStrings[errStrings.length - 1],
'Assertion failed: console.assert should not throw\n');
});
console.assert(false, '%s should', 'console.assert', 'not throw');
assert.strictEqual(errStrings[errStrings.length - 1],
'Assertion failed: console.assert should not throw\n');
assert.doesNotThrow(() => {
console.assert(true, 'this should not throw');
});
console.assert(true, 'this should not throw');
assert.strictEqual(strings.length, process.stdout.writeTimes);
assert.strictEqual(errStrings.length, process.stderr.writeTimes);

View File

@ -46,9 +46,7 @@ const rsaPubPem = fixtures.readSync('test_rsa_pubkey.pem', 'ascii');
const rsaKeyPem = fixtures.readSync('test_rsa_privkey.pem', 'ascii');
// PFX tests
assert.doesNotThrow(function() {
tls.createSecureContext({ pfx: certPfx, passphrase: 'sample' });
});
tls.createSecureContext({ pfx: certPfx, passphrase: 'sample' });
assert.throws(function() {
tls.createSecureContext({ pfx: certPfx });

View File

@ -201,18 +201,18 @@ testCipher2(Buffer.from('0123456789abcdef'));
let decipher = crypto.createDecipher('aes192', key);
let txt;
assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2'));
assert.doesNotThrow(() => txt += decipher.final('ucs2'));
txt = decipher.update(ciph, 'base64', 'ucs2');
txt += decipher.final('ucs2');
assert.strictEqual(txt, plaintext);
decipher = crypto.createDecipher('aes192', key);
assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs-2'));
assert.doesNotThrow(() => txt += decipher.final('ucs-2'));
txt = decipher.update(ciph, 'base64', 'ucs-2');
txt += decipher.final('ucs-2');
assert.strictEqual(txt, plaintext);
decipher = crypto.createDecipher('aes192', key);
assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'utf-16le'));
assert.doesNotThrow(() => txt += decipher.final('utf-16le'));
txt = decipher.update(ciph, 'base64', 'utf-16le');
txt += decipher.final('utf-16le');
assert.strictEqual(txt, plaintext);
}

View File

@ -37,7 +37,7 @@ function test() {
// FIPS requires a length of at least 1024
if (!common.hasFipsCrypto) {
assert.doesNotThrow(function() { test(); });
test();
} else {
assert.throws(function() { test(); }, /key size too small/);
}

View File

@ -371,9 +371,7 @@ if (availableCurves.has('prime256v1') && availableHashes.has('sha256')) {
'AwEHoUQDQgAEurOxfSxmqIRYzJVagdZfMMSjRNNhB8i3mXyIMq704m2m52FdfKZ2\n' +
'pQhByd5eyj3lgZ7m7jbchtdgyOF8Io/1ng==\n' +
'-----END EC PRIVATE KEY-----';
assert.doesNotThrow(() => {
crypto.createSign('SHA256').sign(ecPrivateKey);
});
crypto.createSign('SHA256').sign(ecPrivateKey);
}
// invalid test: curve argument is undefined

View File

@ -100,11 +100,9 @@ assert.throws(function() {
enc(ODD_LENGTH_PLAIN, false);
}, /data not multiple of block length/);
assert.doesNotThrow(function() {
assert.strictEqual(
enc(EVEN_LENGTH_PLAIN, false), EVEN_LENGTH_ENCRYPTED_NOPAD
);
});
assert.strictEqual(
enc(EVEN_LENGTH_PLAIN, false), EVEN_LENGTH_ENCRYPTED_NOPAD
);
/*
@ -114,20 +112,16 @@ assert.doesNotThrow(function() {
assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, true), ODD_LENGTH_PLAIN);
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, true), EVEN_LENGTH_PLAIN);
assert.doesNotThrow(function() {
// returns including original padding
assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, false).length, 32);
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48);
});
// returns including original padding
assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, false).length, 32);
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48);
assert.throws(function() {
// must have at least 1 byte of padding (PKCS):
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN);
}, /bad decrypt/);
assert.doesNotThrow(function() {
// no-pad encrypted string should return the same:
assert.strictEqual(
dec(EVEN_LENGTH_ENCRYPTED_NOPAD, false), EVEN_LENGTH_PLAIN
);
});
// no-pad encrypted string should return the same:
assert.strictEqual(
dec(EVEN_LENGTH_ENCRYPTED_NOPAD, false), EVEN_LENGTH_PLAIN
);

View File

@ -100,11 +100,9 @@ common.expectsError(
// Should not get FATAL ERROR with empty password and salt
// https://github.com/nodejs/node/issues/8571
assert.doesNotThrow(() => {
crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall((e) => {
assert.ifError(e);
}));
});
crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall((e) => {
assert.ifError(e);
}));
common.expectsError(
() => crypto.pbkdf2('password', 'salt', 8, 8, common.mustNotCall()),

View File

@ -153,10 +153,8 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true);
// Test RSA key signing/verification with encrypted key
rsaSign = crypto.createSign('SHA1');
rsaSign.update(rsaPubPem);
assert.doesNotThrow(() => {
const signOptions = { key: rsaKeyPemEncrypted, passphrase: 'password' };
rsaSignature = rsaSign.sign(signOptions, 'hex');
});
const signOptions = { key: rsaKeyPemEncrypted, passphrase: 'password' };
rsaSignature = rsaSign.sign(signOptions, 'hex');
assert.strictEqual(rsaSignature, expectedSignature);
rsaVerify = crypto.createVerify('SHA1');
@ -259,11 +257,8 @@ const input = 'I AM THE WALRUS';
const sign = crypto.createSign('SHA1');
sign.update(input);
let signature;
assert.doesNotThrow(() => {
const signOptions = { key: dsaKeyPemEncrypted, passphrase: 'password' };
signature = sign.sign(signOptions, 'hex');
});
const signOptions = { key: dsaKeyPemEncrypted, passphrase: 'password' };
const signature = sign.sign(signOptions, 'hex');
const verify = crypto.createVerify('SHA1');
verify.update(input);

View File

@ -56,9 +56,7 @@ assert.throws(function() {
});
// PFX tests
assert.doesNotThrow(function() {
tls.createSecureContext({ pfx: certPfx, passphrase: 'sample' });
});
tls.createSecureContext({ pfx: certPfx, passphrase: 'sample' });
assert.throws(function() {
tls.createSecureContext({ pfx: certPfx });

View File

@ -34,10 +34,8 @@ invalidTypes.forEach((invalidType) => {
// Error must not be thrown with valid types
validTypes.forEach((validType) => {
assert.doesNotThrow(() => {
const socket = dgram.createSocket(validType);
socket.close();
});
const socket = dgram.createSocket(validType);
socket.close();
});
// Ensure buffer sizes can be set

View File

@ -53,55 +53,47 @@ common.expectsError(() => {
message: 'The value "20" is invalid for option "family"'
});
assert.doesNotThrow(() => {
dns.lookup(false, {
hints: 0,
family: 0,
all: true
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
assert.deepStrictEqual(result, []);
assert.strictEqual(addressType, undefined);
}));
});
dns.lookup(false, {
hints: 0,
family: 0,
all: true
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
assert.deepStrictEqual(result, []);
assert.strictEqual(addressType, undefined);
}));
assert.doesNotThrow(() => {
dns.lookup('127.0.0.1', {
hints: 0,
family: 4,
all: true
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
assert.deepStrictEqual(result, [{
address: '127.0.0.1',
family: 4
}]);
assert.strictEqual(addressType, undefined);
}));
});
dns.lookup('127.0.0.1', {
hints: 0,
family: 4,
all: true
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
assert.deepStrictEqual(result, [{
address: '127.0.0.1',
family: 4
}]);
assert.strictEqual(addressType, undefined);
}));
assert.doesNotThrow(() => {
dns.lookup('127.0.0.1', {
hints: 0,
family: 4,
all: false
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
assert.deepStrictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
}));
});
dns.lookup('127.0.0.1', {
hints: 0,
family: 4,
all: false
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
assert.deepStrictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
}));
assert.doesNotThrow(() => {
let tickValue = 0;
let tickValue = 0;
dns.lookup('example.com', common.mustCall((error, result, addressType) => {
assert(error);
assert.strictEqual(tickValue, 1);
assert.strictEqual(error.code, 'ENOENT');
}));
dns.lookup('example.com', common.mustCall((error, result, addressType) => {
assert(error);
assert.strictEqual(tickValue, 1);
assert.strictEqual(error.code, 'ENOENT');
}));
// Make sure that the error callback is called
// on next tick.
tickValue = 1;
});
// Make sure that the error callback is called
// on next tick.
tickValue = 1;

View File

@ -29,7 +29,7 @@ const existing = dns.getServers();
assert(existing.length > 0);
// Verify that setServers() handles arrays with holes and other oddities
assert.doesNotThrow(() => {
{
const servers = [];
servers[0] = '127.0.0.1';
@ -37,9 +37,9 @@ assert.doesNotThrow(() => {
dns.setServers(servers);
assert.deepStrictEqual(dns.getServers(), ['127.0.0.1', '0.0.0.0']);
});
}
assert.doesNotThrow(() => {
{
const servers = ['127.0.0.1', '192.168.1.1'];
servers[3] = '127.1.0.1';
@ -60,13 +60,13 @@ assert.doesNotThrow(() => {
'192.168.1.1',
'0.0.0.0'
]);
});
}
const goog = [
'8.8.8.8',
'8.8.4.4',
];
assert.doesNotThrow(() => dns.setServers(goog));
dns.setServers(goog);
assert.deepStrictEqual(dns.getServers(), goog);
common.expectsError(() => dns.setServers(['foobar']), {
code: 'ERR_INVALID_IP_ADDRESS',
@ -84,7 +84,7 @@ const goog6 = [
'2001:4860:4860::8888',
'2001:4860:4860::8844',
];
assert.doesNotThrow(() => dns.setServers(goog6));
dns.setServers(goog6);
assert.deepStrictEqual(dns.getServers(), goog6);
goog6.push('4.4.4.4');
@ -106,7 +106,7 @@ const portsExpected = [
dns.setServers(ports);
assert.deepStrictEqual(dns.getServers(), portsExpected);
assert.doesNotThrow(() => dns.setServers([]));
dns.setServers([]);
assert.deepStrictEqual(dns.getServers(), []);
common.expectsError(() => {
@ -146,16 +146,11 @@ common.expectsError(() => {
assert.strictEqual(family, 4);
};
assert.doesNotThrow(() => dns.lookup('', common.mustCall(checkCallback)));
assert.doesNotThrow(() => dns.lookup(null, common.mustCall(checkCallback)));
assert.doesNotThrow(() => dns.lookup(undefined,
common.mustCall(checkCallback)));
assert.doesNotThrow(() => dns.lookup(0, common.mustCall(checkCallback)));
assert.doesNotThrow(() => dns.lookup(NaN, common.mustCall(checkCallback)));
dns.lookup('', common.mustCall(checkCallback));
dns.lookup(null, common.mustCall(checkCallback));
dns.lookup(undefined, common.mustCall(checkCallback));
dns.lookup(0, common.mustCall(checkCallback));
dns.lookup(NaN, common.mustCall(checkCallback));
}
/*
@ -186,24 +181,18 @@ common.expectsError(() => dns.lookup('nodejs.org', 4), {
type: TypeError
});
assert.doesNotThrow(() => dns.lookup('', { family: 4, hints: 0 },
common.mustCall()));
dns.lookup('', { family: 4, hints: 0 }, common.mustCall());
assert.doesNotThrow(() => {
dns.lookup('', {
family: 6,
hints: dns.ADDRCONFIG
}, common.mustCall());
});
dns.lookup('', {
family: 6,
hints: dns.ADDRCONFIG
}, common.mustCall());
assert.doesNotThrow(() => dns.lookup('', { hints: dns.V4MAPPED },
common.mustCall()));
dns.lookup('', { hints: dns.V4MAPPED }, common.mustCall());
assert.doesNotThrow(() => {
dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED
}, common.mustCall());
});
dns.lookup('', {
hints: dns.ADDRCONFIG | dns.V4MAPPED
}, common.mustCall());
common.expectsError(() => dns.lookupService('0.0.0.0'), {
code: 'ERR_MISSING_ARGS',

View File

@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');
process.setUncaughtExceptionCaptureCallback(common.mustNotCall());
@ -15,4 +14,4 @@ common.expectsError(
process.setUncaughtExceptionCaptureCallback(null);
assert.doesNotThrow(() => require('domain'));
require('domain');

View File

@ -81,7 +81,7 @@ function expect(expected) {
// Check for regression where removeAllListeners() throws when
// there exists a 'removeListener' listener, but there exists
// no listeners for the provided event type.
assert.doesNotThrow(ee.removeAllListeners.bind(ee, 'foo'));
ee.removeAllListeners.bind(ee, 'foo');
}
{

View File

@ -118,15 +118,10 @@ common.expectsError(
type: TypeError
});
assert.doesNotThrow(() => {
fs.accessSync(__filename);
});
fs.accessSync(__filename);
assert.doesNotThrow(() => {
const mode = fs.F_OK | fs.R_OK | fs.W_OK;
fs.accessSync(readWriteFile, mode);
});
const mode = fs.F_OK | fs.R_OK | fs.W_OK;
fs.accessSync(readWriteFile, mode);
assert.throws(
() => { fs.accessSync(doesNotExist); },

View File

@ -9,22 +9,18 @@ const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
assert.doesNotThrow(() => {
fs.access(Buffer.from(tmpdir.path), common.mustCall((err) => {
assert.ifError(err);
}));
});
fs.access(Buffer.from(tmpdir.path), common.mustCall((err) => {
assert.ifError(err);
}));
assert.doesNotThrow(() => {
const buf = Buffer.from(path.join(tmpdir.path, 'a.txt'));
fs.open(buf, 'w+', common.mustCall((err, fd) => {
const buf = Buffer.from(path.join(tmpdir.path, 'a.txt'));
fs.open(buf, 'w+', common.mustCall((err, fd) => {
assert.ifError(err);
assert(fd);
fs.close(fd, common.mustCall((err) => {
assert.ifError(err);
assert(fd);
fs.close(fd, common.mustCall((err) => {
assert.ifError(err);
}));
}));
});
}));
common.expectsError(
() => {

View File

@ -27,9 +27,9 @@ const { URL } = require('url');
const f = __filename;
// Only warnings are emitted when the callback is invalid
assert.doesNotThrow(() => fs.exists(f));
assert.doesNotThrow(() => fs.exists());
assert.doesNotThrow(() => fs.exists(f, {}));
fs.exists(f);
fs.exists();
fs.exists(f, {});
fs.exists(f, common.mustCall(function(y) {
assert.strictEqual(y, true);

View File

@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
@ -20,7 +19,7 @@ function testMakeCallback(cb) {
common.expectWarning('DeprecationWarning', warn);
// Passing undefined/nothing calls rethrow() internally, which emits a warning
assert.doesNotThrow(testMakeCallback());
testMakeCallback()();
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {

View File

@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
const warn = 'Calling an asynchronous function without callback is deprecated.';
@ -15,10 +14,10 @@ function testMakeStatsCallback(cb) {
common.expectWarning('DeprecationWarning', warn);
// Verify the case where a callback function is provided
assert.doesNotThrow(testMakeStatsCallback(common.mustCall()));
testMakeStatsCallback(common.mustCall())();
// Passing undefined/nothing calls rethrow() internally, which emits a warning
assert.doesNotThrow(testMakeStatsCallback());
testMakeStatsCallback()();
function invalidCallbackThrowsTests() {
callbackThrowValues.forEach((value) => {

View File

@ -32,5 +32,5 @@ fs.mkdtemp(path.join(tmpdir.path, 'bar.'), {}, common.mustCall(handler));
// Making sure that not passing a callback doesn't crash, as a default function
// is passed internally.
assert.doesNotThrow(() => fs.mkdtemp(path.join(tmpdir.path, 'bar-')));
assert.doesNotThrow(() => fs.mkdtemp(path.join(tmpdir.path, 'bar-'), {}));
fs.mkdtemp(path.join(tmpdir.path, 'bar-'));
fs.mkdtemp(path.join(tmpdir.path, 'bar-'), {});

View File

@ -17,19 +17,11 @@ const options = Object.freeze({});
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
{
assert.doesNotThrow(() =>
fs.readFile(__filename, options, common.mustCall(errHandler))
);
assert.doesNotThrow(() => fs.readFileSync(__filename, options));
}
fs.readFile(__filename, options, common.mustCall(errHandler));
fs.readFileSync(__filename, options);
{
assert.doesNotThrow(() =>
fs.readdir(__dirname, options, common.mustCall(errHandler))
);
assert.doesNotThrow(() => fs.readdirSync(__dirname, options));
}
fs.readdir(__dirname, options, common.mustCall(errHandler));
fs.readdirSync(__dirname, options);
if (common.canCreateSymLink()) {
const sourceFile = path.resolve(tmpdir.path, 'test-readlink');
@ -38,63 +30,46 @@ if (common.canCreateSymLink()) {
fs.writeFileSync(sourceFile, '');
fs.symlinkSync(sourceFile, linkFile);
assert.doesNotThrow(() =>
fs.readlink(linkFile, options, common.mustCall(errHandler))
);
assert.doesNotThrow(() => fs.readlinkSync(linkFile, options));
fs.readlink(linkFile, options, common.mustCall(errHandler));
fs.readlinkSync(linkFile, options);
}
{
const fileName = path.resolve(tmpdir.path, 'writeFile');
assert.doesNotThrow(() => fs.writeFileSync(fileName, 'ABCD', options));
assert.doesNotThrow(() =>
fs.writeFile(fileName, 'ABCD', options, common.mustCall(errHandler))
);
fs.writeFileSync(fileName, 'ABCD', options);
fs.writeFile(fileName, 'ABCD', options, common.mustCall(errHandler));
}
{
const fileName = path.resolve(tmpdir.path, 'appendFile');
assert.doesNotThrow(() => fs.appendFileSync(fileName, 'ABCD', options));
assert.doesNotThrow(() =>
fs.appendFile(fileName, 'ABCD', options, common.mustCall(errHandler))
);
fs.appendFileSync(fileName, 'ABCD', options);
fs.appendFile(fileName, 'ABCD', options, common.mustCall(errHandler));
}
{
let watch;
assert.doesNotThrow(() => {
watch = fs.watch(__filename, options, common.mustNotCall());
});
const watch = fs.watch(__filename, options, common.mustNotCall());
watch.close();
}
{
assert.doesNotThrow(
() => fs.watchFile(__filename, options, common.mustNotCall())
);
fs.watchFile(__filename, options, common.mustNotCall());
fs.unwatchFile(__filename);
}
{
assert.doesNotThrow(() => fs.realpathSync(__filename, options));
assert.doesNotThrow(() =>
fs.realpath(__filename, options, common.mustCall(errHandler))
);
fs.realpathSync(__filename, options);
fs.realpath(__filename, options, common.mustCall(errHandler));
}
{
const tempFileName = path.resolve(tmpdir.path, 'mkdtemp-');
assert.doesNotThrow(() => fs.mkdtempSync(tempFileName, options));
assert.doesNotThrow(() =>
fs.mkdtemp(tempFileName, options, common.mustCall(errHandler))
);
fs.mkdtempSync(tempFileName, options);
fs.mkdtemp(tempFileName, options, common.mustCall(errHandler));
}
{
const fileName = path.resolve(tmpdir.path, 'streams');
assert.doesNotThrow(() => {
fs.WriteStream(fileName, options).once('open', common.mustCall(() => {
assert.doesNotThrow(() => fs.ReadStream(fileName, options));
}));
});
fs.WriteStream(fileName, options).once('open', common.mustCall(() => {
fs.ReadStream(fileName, options);
}));
}

View File

@ -1,23 +1,14 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
const example = fixtures.path('x.txt');
assert.doesNotThrow(function() {
fs.createReadStream(example, undefined);
});
assert.doesNotThrow(function() {
fs.createReadStream(example, null);
});
assert.doesNotThrow(function() {
fs.createReadStream(example, 'utf8');
});
assert.doesNotThrow(function() {
fs.createReadStream(example, { encoding: 'utf8' });
});
fs.createReadStream(example, undefined);
fs.createReadStream(example, null);
fs.createReadStream(example, 'utf8');
fs.createReadStream(example, { encoding: 'utf8' });
const createReadStreamErr = (path, opt) => {
common.expectsError(

View File

@ -1,7 +1,6 @@
'use strict';
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
[Infinity, -Infinity, NaN].forEach((input) => {
common.expectsError(
@ -25,5 +24,5 @@ common.expectsError(
const okInputs = [1, -1, '1', '-1', Date.now()];
okInputs.forEach((input) => {
assert.doesNotThrow(() => fs._toUnixTimestamp(input));
fs._toUnixTimestamp(input);
});

View File

@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
@ -10,21 +9,10 @@ const example = path.join(tmpdir.path, 'dummy');
tmpdir.refresh();
assert.doesNotThrow(() => {
fs.createWriteStream(example, undefined);
});
assert.doesNotThrow(() => {
fs.createWriteStream(example, null);
});
assert.doesNotThrow(() => {
fs.createWriteStream(example, 'utf8');
});
assert.doesNotThrow(() => {
fs.createWriteStream(example, { encoding: 'utf8' });
});
fs.createWriteStream(example, undefined);
fs.createWriteStream(example, null);
fs.createWriteStream(example, 'utf8');
fs.createWriteStream(example, { encoding: 'utf8' });
const createWriteStreamErr = (path, opt) => {
common.expectsError(

View File

@ -59,7 +59,7 @@ server.listen(0, baseOptions.host, common.mustCall(function() {
});
acceptableAgentOptions.forEach((agent) => {
assert.doesNotThrow(() => createRequest(agent));
createRequest(agent);
});
}));

View File

@ -37,11 +37,7 @@ const s = http.createServer(function(req, res) {
res.end('hello world\n');
// This checks that after the headers have been sent, getHeader works
// and does not throw an exception (Issue 752)
assert.doesNotThrow(
function() {
assert.strictEqual(plain, res.getHeader(contentType));
}
);
assert.strictEqual(plain, res.getHeader(contentType));
});
s.listen(0, runTest);

View File

@ -1,7 +1,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
// All of these values should cause http.request() to throw synchronously
@ -36,8 +35,6 @@ vals.forEach((v) => {
// Only testing for 'hostname' validation so ignore connection errors.
const dontCare = () => {};
['', undefined, null].forEach((v) => {
assert.doesNotThrow(() => {
http.request({ hostname: v }).on('error', dontCare).end();
http.request({ host: v }).on('error', dontCare).end();
});
http.request({ hostname: v }).on('error', dontCare).end();
http.request({ host: v }).on('error', dontCare).end();
});

View File

@ -9,9 +9,7 @@ const ee = new EventEmitter();
let count = 3;
const server = http.createServer(function(req, res) {
assert.doesNotThrow(function() {
res.setHeader('testing_123', 123);
});
res.setHeader('testing_123', 123);
assert.throws(function() {
res.setHeader('testing 123', 123);
}, TypeError);
@ -37,17 +35,13 @@ server.listen(0, function() {
}
);
assert.doesNotThrow(
function() {
const options = {
port: server.address().port,
headers: { 'testing_123': 123 }
};
http.get(options, function() {
ee.emit('done');
});
}, TypeError
);
const options = {
port: server.address().port,
headers: { 'testing_123': 123 }
};
http.get(options, function() {
ee.emit('done');
});
});
ee.on('done', function() {

View File

@ -1,12 +1,9 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const server = http.createServer((req, res) => {
assert.doesNotThrow(() => {
res.setHeader('header1', 1);
});
res.setHeader('header1', 1);
res.write('abc');
common.expectsError(
() => res.setHeader('header2', 2),

View File

@ -1,12 +1,9 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const server = http.createServer((req, res) => {
assert.doesNotThrow(() => {
res.removeHeader('header1', 1);
});
res.removeHeader('header1', 1);
res.write('abc');
common.expectsError(
() => res.removeHeader('header2', 2),

View File

@ -5,7 +5,7 @@ if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
assert.doesNotThrow(() => process.binding('http2'));
process.binding('http2');
const binding = process.binding('http2');
const http2 = require('http2');

View File

@ -23,7 +23,7 @@ server.listen(0, common.mustCall(() => {
req._destroy = common.mustCall(req._destroy.bind(req));
// second call doesn't do anything
assert.doesNotThrow(() => req.close(8));
req.close(8);
req.on('close', common.mustCall((code) => {
assert.strictEqual(req.destroyed, true);

View File

@ -28,8 +28,8 @@ server.on('request', common.mustCall((req, res) => {
// shouldn't throw if underlying Http2Stream no longer exists
res.on('finish', common.mustCall(() => process.nextTick(() => {
assert.doesNotThrow(() => req.pause());
assert.doesNotThrow(() => req.resume());
req.pause();
req.resume();
})));
}));

View File

@ -3,7 +3,6 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const msecs = common.platformTimeout(1);
@ -16,9 +15,7 @@ server.on('request', (req, res) => {
res.on('finish', common.mustCall(() => {
req.setTimeout(msecs, common.mustNotCall());
process.nextTick(() => {
assert.doesNotThrow(
() => req.setTimeout(msecs, common.mustNotCall())
);
req.setTimeout(msecs, common.mustNotCall());
server.close();
});
}));

View File

@ -3,7 +3,6 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const Countdown = require('../common/countdown');
@ -22,9 +21,9 @@ const server = http2.createServer(common.mustCall((req, res) => {
res.on('error', common.mustNotCall());
res.on('finish', common.mustCall(() => {
assert.doesNotThrow(() => res.destroy(nextError));
res.destroy(nextError);
process.nextTick(() => {
assert.doesNotThrow(() => res.destroy(nextError));
res.destroy(nextError);
});
}));

View File

@ -15,12 +15,12 @@ server.listen(0, common.mustCall(function() {
server.once('request', common.mustCall(function(request, response) {
response.on('finish', common.mustCall(() => {
assert.strictEqual(response.headersSent, false);
assert.doesNotThrow(() => response.setHeader('test', 'value'));
assert.doesNotThrow(() => response.removeHeader('test', 'value'));
response.setHeader('test', 'value');
response.removeHeader('test', 'value');
process.nextTick(() => {
assert.doesNotThrow(() => response.setHeader('test', 'value'));
assert.doesNotThrow(() => response.removeHeader('test', 'value'));
response.setHeader('test', 'value');
response.removeHeader('test', 'value');
server.close();
});

View File

@ -3,7 +3,6 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const msecs = common.platformTimeout(1);
@ -16,9 +15,7 @@ server.on('request', (req, res) => {
res.on('finish', common.mustCall(() => {
res.setTimeout(msecs, common.mustNotCall());
process.nextTick(() => {
assert.doesNotThrow(
() => res.setTimeout(msecs, common.mustNotCall())
);
res.setTimeout(msecs, common.mustNotCall());
server.close();
});
}));

View File

@ -27,12 +27,10 @@ server.listen(0, common.mustCall(function() {
assert.strictEqual(response.statusCode, expectedDefaultStatusCode);
assert.doesNotThrow(function() {
response.statusCode = realStatusCodes.ok;
response.statusCode = realStatusCodes.multipleChoices;
response.statusCode = realStatusCodes.badRequest;
response.statusCode = realStatusCodes.internalServerError;
});
response.statusCode = realStatusCodes.ok;
response.statusCode = realStatusCodes.multipleChoices;
response.statusCode = realStatusCodes.badRequest;
response.statusCode = realStatusCodes.internalServerError;
common.expectsError(function() {
response.statusCode = realStatusCodes.continue;

View File

@ -49,7 +49,7 @@ server.on('request', common.mustCall(function(request, response) {
request.on('end', common.mustCall(() => {
assert.strictEqual(request.socket.readable, false);
assert.doesNotThrow(() => response.socket.destroy());
response.socket.destroy();
}));
response.on('finish', common.mustCall(() => {
assert.ok(request.socket);

View File

@ -3,7 +3,6 @@
const { mustCall, hasCrypto, skip, expectsError } = require('../common');
if (!hasCrypto)
skip('missing crypto');
const { doesNotThrow, throws } = require('assert');
const { createServer, connect } = require('http2');
{
const server = createServer();
@ -13,10 +12,11 @@ const { createServer, connect } = require('http2');
const listener = () => mustCall();
const clients = new Set();
doesNotThrow(() => clients.add(connect(authority)));
doesNotThrow(() => clients.add(connect(authority, options)));
doesNotThrow(() => clients.add(connect(authority, options, listener())));
doesNotThrow(() => clients.add(connect(authority, listener())));
// Should not throw.
clients.add(connect(authority));
clients.add(connect(authority, options));
clients.add(connect(authority, options, listener()));
clients.add(connect(authority, listener()));
for (const client of clients) {
client.once('connect', mustCall((headers) => {
@ -33,20 +33,18 @@ const { createServer, connect } = require('http2');
// check for https as protocol
{
const authority = 'https://localhost';
doesNotThrow(() => {
// A socket error may or may not be reported, keep this as a non-op
// instead of a mustCall or mustNotCall
connect(authority).on('error', () => {});
});
// A socket error may or may not be reported, keep this as a non-op
// instead of a mustCall or mustNotCall
connect(authority).on('error', () => {});
}
// check for error for an invalid protocol (not http or https)
{
const authority = 'ssh://localhost';
throws(() => {
expectsError(() => {
connect(authority);
}, expectsError({
}, {
code: 'ERR_HTTP2_UNSUPPORTED_PROTOCOL',
type: Error
}));
});
}

View File

@ -26,11 +26,11 @@ assert.deepStrictEqual(val, check);
['maxHeaderListSize', 0],
['maxHeaderListSize', 2 ** 32 - 1]
].forEach((i) => {
assert.doesNotThrow(() => http2.getPackedSettings({ [i[0]]: i[1] }));
http2.getPackedSettings({ [i[0]]: i[1] });
});
assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: true }));
assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
http2.getPackedSettings({ enablePush: true });
http2.getPackedSettings({ enablePush: false });
[
['headerTableSize', -1],
@ -151,9 +151,7 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
assert.doesNotThrow(() => {
http2.getUnpackedSettings(packed, { validate: true });
});
http2.getUnpackedSettings(packed, { validate: true });
}
// check for maxFrameSize failing the max number

View File

@ -10,7 +10,6 @@ const commonFixtures = require('../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const tls = require('tls');
const net = require('net');
@ -21,25 +20,17 @@ const options = {
};
// There should not be any throws
assert.doesNotThrow(() => {
const serverTLS = http2.createSecureServer(options, () => {});
serverTLS.listen(0, common.mustCall(() => serverTLS.close()));
const serverTLS = http2.createSecureServer(options, () => {});
// There should not be an error event reported either
serverTLS.on('error', common.mustNotCall());
serverTLS.listen(0, common.mustCall(() => serverTLS.close()));
const server = http2.createServer(options, common.mustNotCall());
server.listen(0, common.mustCall(() => server.close()));
// There should not be an error event reported either
serverTLS.on('error', common.mustNotCall());
});
// There should not be any throws
assert.doesNotThrow(() => {
const server = http2.createServer(options, common.mustNotCall());
server.listen(0, common.mustCall(() => server.close()));
// There should not be an error event reported either
server.on('error', common.mustNotCall());
});
// There should not be an error event reported either
server.on('error', common.mustNotCall());
// Test the plaintext server socket timeout
{

View File

@ -76,9 +76,7 @@ server.listen(
// State will only be valid after connect event is emitted
req.on('ready', common.mustCall(() => {
assert.doesNotThrow(() => {
client.settings({ maxHeaderListSize: 1 }, common.mustCall());
});
client.settings({ maxHeaderListSize: 1 }, common.mustCall());
// Verify valid error ranges
[

View File

@ -51,8 +51,8 @@ server.on('stream', common.mustCall(function(stream, headers) {
common.expectsError(() => (socket.resume = undefined), errMsg);
common.expectsError(() => (socket.write = undefined), errMsg);
assert.doesNotThrow(() => (socket.on = socket.on));
assert.doesNotThrow(() => (socket.once = socket.once));
socket.on = socket.on;
socket.once = socket.once;
stream.respond();

View File

@ -2,7 +2,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const {
assertIsObject,
assertWithinRange,
@ -15,7 +14,7 @@ const {
new Date(),
new (class Foo {})()
].forEach((i) => {
assert.doesNotThrow(() => assertIsObject(i, 'foo', 'Object'));
assertIsObject(i, 'foo', 'Object');
});
[
@ -34,7 +33,7 @@ const {
});
});
assert.doesNotThrow(() => assertWithinRange('foo', 1, 0, 2));
assertWithinRange('foo', 1, 0, 2);
common.expectsError(() => assertWithinRange('foo', 1, 2, 3),
{

View File

@ -3,6 +3,5 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
assert.doesNotThrow(() => require('http2'));
require('http2');

View File

@ -6,5 +6,5 @@ if (!common.hasCrypto)
const assert = require('assert');
const https = require('https');
assert.doesNotThrow(() => { https.Agent(); });
https.Agent();
assert.ok(https.Agent() instanceof https.Agent);

View File

@ -6,7 +6,6 @@ const fixtures = require('../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const https = require('https');
function toArrayBuffer(buf) {
@ -65,11 +64,9 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[[{ pem: keyBuff }], false],
[[{ pem: keyBuff }, { pem: keyBuff }], false]
].forEach((params) => {
assert.doesNotThrow(() => {
https.createServer({
key: params[0],
cert: params[1]
});
https.createServer({
key: params[0],
cert: params[1]
});
});
@ -124,12 +121,10 @@ const invalidCertRE = /^The "cert" argument must be one of type string, Buffer,
[keyBuff, certBuff, caArrDataView],
[keyBuff, certBuff, false],
].forEach((params) => {
assert.doesNotThrow(() => {
https.createServer({
key: params[0],
cert: params[1],
ca: params[2]
});
https.createServer({
key: params[0],
cert: params[1],
ca: params[2]
});
});

View File

@ -34,13 +34,12 @@ const wptToASCIITests = require('../fixtures/url-toascii.js');
if (output === null) {
assert.throws(() => icu.toASCII(input),
errMessage, `ToASCII ${caseComment}`);
assert.doesNotThrow(() => icu.toASCII(input, true),
`ToASCII ${caseComment} in lenient mode`);
icu.toASCII(input, true);
} else {
assert.strictEqual(icu.toASCII(input), output, `ToASCII ${caseComment}`);
assert.strictEqual(icu.toASCII(input, true), output,
`ToASCII ${caseComment} in lenient mode`);
}
assert.doesNotThrow(() => icu.toUnicode(input), `ToUnicode ${caseComment}`);
icu.toUnicode(input);
}
}

View File

@ -138,36 +138,24 @@ common.expectsError(
message: invalidKey('true')
});
// Tests for common.expectsError
assert.doesNotThrow(() => {
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, { code: 'TEST_ERROR_1' });
});
assert.doesNotThrow(() => {
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, { code: 'TEST_ERROR_1',
type: TypeError,
message: /^Error for testing/ });
});
assert.doesNotThrow(() => {
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, { code: 'TEST_ERROR_1', type: TypeError });
});
assert.doesNotThrow(() => {
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, {
code: 'TEST_ERROR_1',
type: TypeError,
message: 'Error for testing purposes: a'
});
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, { code: 'TEST_ERROR_1' });
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, { code: 'TEST_ERROR_1',
type: TypeError,
message: /^Error for testing/ });
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, { code: 'TEST_ERROR_1', type: TypeError });
common.expectsError(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, {
code: 'TEST_ERROR_1',
type: TypeError,
message: 'Error for testing purposes: a'
});
common.expectsError(() => {

View File

@ -2,11 +2,10 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('internal/fs');
assert.doesNotThrow(() => fs.assertEncoding());
assert.doesNotThrow(() => fs.assertEncoding('utf8'));
fs.assertEncoding();
fs.assertEncoding('utf8');
common.expectsError(
() => fs.assertEncoding('foo'),
{ code: 'ERR_INVALID_OPT_VALUE_ENCODING', type: TypeError }

View File

@ -11,5 +11,5 @@ if (!process.versions.openssl) {
});
assert.throws(() => util.assertCrypto(), expectedError);
} else {
assert.doesNotThrow(() => util.assertCrypto());
util.assertCrypto();
}

View File

@ -12,12 +12,10 @@ const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
const decorateErrorStack = internalUtil.decorateErrorStack;
assert.doesNotThrow(function() {
decorateErrorStack();
decorateErrorStack(null);
decorateErrorStack(1);
decorateErrorStack(true);
});
decorateErrorStack();
decorateErrorStack(null);
decorateErrorStack(1);
decorateErrorStack(true);
// Verify that a stack property is not added to non-Errors
const obj = {};

View File

@ -11,7 +11,6 @@
const common = require('../common');
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
@ -60,6 +59,4 @@ fs.writeFileSync(path.join(moduleB, 'package.json'),
fs.writeFileSync(path.join(moduleB, 'index.js'),
'module.exports = 1;', 'utf8');
assert.doesNotThrow(() => {
require(path.join(app, 'index'));
});
require(path.join(app, 'index'));

View File

@ -34,16 +34,14 @@ server.listen(0, common.mustCall(function() {
c.on('close', common.mustCall(function() {
console.error('connection closed');
assert.strictEqual(c._handle, null);
assert.doesNotThrow(function() {
c.setNoDelay();
c.setKeepAlive();
c.bufferSize;
c.pause();
c.resume();
c.address();
c.remoteAddress;
c.remotePort;
});
c.setNoDelay();
c.setKeepAlive();
c.bufferSize;
c.pause();
c.resume();
c.address();
c.remoteAddress;
c.remotePort;
server.close();
}));
}));

View File

@ -171,27 +171,26 @@ function canConnect(port) {
// connect(port, cb) and connect(port)
const portArgBlocks = doConnect([port], noop);
for (const block of portArgBlocks) {
assert.doesNotThrow(block, `${block.name}(${port})`);
block();
}
// connect(port, host, cb) and connect(port, host)
const portHostArgBlocks = doConnect([port, 'localhost'], noop);
for (const block of portHostArgBlocks) {
assert.doesNotThrow(block, `${block.name}(${port})`);
block();
}
// connect({port}, cb) and connect({port})
const portOptBlocks = doConnect([{ port }], noop);
for (const block of portOptBlocks) {
assert.doesNotThrow(block, `${block.name}({port: ${port}})`);
block();
}
// connect({port, host}, cb) and connect({port, host})
const portHostOptBlocks = doConnect([{ port: port, host: 'localhost' }],
noop);
for (const block of portHostOptBlocks) {
assert.doesNotThrow(block,
`${block.name}({port: ${port}, host: 'localhost'})`);
block();
}
}
@ -205,25 +204,19 @@ function asyncFailToConnect(port) {
// connect(port, cb) and connect(port)
const portArgBlocks = doConnect([port], dont);
for (const block of portArgBlocks) {
assert.doesNotThrow(function() {
block().on('error', onError());
}, `${block.name}(${port})`);
block().on('error', onError());
}
// connect({port}, cb) and connect({port})
const portOptBlocks = doConnect([{ port }], dont);
for (const block of portOptBlocks) {
assert.doesNotThrow(function() {
block().on('error', onError());
}, `${block.name}({port: ${port}})`);
block().on('error', onError());
}
// connect({port, host}, cb) and connect({port, host})
const portHostOptBlocks = doConnect([{ port: port, host: 'localhost' }],
dont);
for (const block of portHostOptBlocks) {
assert.doesNotThrow(function() {
block().on('error', onError());
}, `${block.name}({port: ${port}, host: 'localhost'})`);
block().on('error', onError());
}
}

View File

@ -21,7 +21,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(function(socket) {
@ -33,11 +32,9 @@ server.listen(0, common.mustCall(function() {
server.close();
// server connection event has not yet fired
// client is still attempting to connect
assert.doesNotThrow(function() {
client.remoteAddress;
client.remoteFamily;
client.remotePort;
});
client.remoteAddress;
client.remoteFamily;
client.remotePort;
// exit now, do not wait for the client error event
process.exit(0);
}));

View File

@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
['foobar', 1, {}, []].forEach((input) => connectThrows(input));
@ -30,7 +29,5 @@ function connectDoesNotThrow(input) {
lookup: input
};
assert.doesNotThrow(() => {
net.connect(opts);
});
net.connect(opts);
}

View File

@ -1,7 +1,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
// First test. Check that after error event you can listen right away.
@ -16,12 +15,10 @@ const net = require('net');
}));
server.on('error', common.mustCall((e) => {
assert.doesNotThrow(
() => server.listen(common.mustCall(() => {
dummyServer.close();
server.close();
}))
);
server.listen(common.mustCall(() => {
dummyServer.close();
server.close();
}));
}));
}
@ -44,8 +41,6 @@ const net = require('net');
server.listen(common.mustCall(() => {
server.close();
assert.doesNotThrow(
() => server.listen(common.mustCall(() => server.close()))
);
server.listen(common.mustCall(() => server.close()));
}));
}

View File

@ -46,9 +46,7 @@ for (let i = 0; i < badRangeDelays.length; i++) {
}
for (let i = 0; i < validDelays.length; i++) {
assert.doesNotThrow(function() {
s.setTimeout(validDelays[i], () => {});
});
s.setTimeout(validDelays[i], () => {});
}
const server = net.Server();

View File

@ -64,7 +64,7 @@ assert.strictEqual(typeof performance.timeOrigin, 'number');
{
performance.mark('A');
[undefined, null, 'foo', 'initialize', 1].forEach((i) => {
assert.doesNotThrow(() => performance.measure('test', i, 'A'));
performance.measure('test', i, 'A');
});
[undefined, null, 'foo', 1].forEach((i) => {

View File

@ -77,7 +77,7 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
countdown.dec();
}
assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 1);
assert.doesNotThrow(() => observer.observe({ entryTypes: ['mark'] }));
observer.observe({ entryTypes: ['mark'] });
assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 2);
performance.mark('test1');
performance.mark('test2');
@ -125,13 +125,9 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
}
}
assert.doesNotThrow(() => {
observer.observe({ entryTypes: ['mark', 'measure'], buffered: true });
});
observer.observe({ entryTypes: ['mark', 'measure'], buffered: true });
// Do this twice to make sure it doesn't throw
assert.doesNotThrow(() => {
observer.observe({ entryTypes: ['mark', 'measure'], buffered: true });
});
observer.observe({ entryTypes: ['mark', 'measure'], buffered: true });
// Even tho we called twice, count should be 1
assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 2);
performance.mark('test1');

View File

@ -9,10 +9,4 @@ assert.throws(
/No such module: test/
);
assert.doesNotThrow(function() {
process.binding('buffer');
}, function(err) {
if (err instanceof Error) {
return true;
}
}, 'unexpected error');
process.binding('buffer');

View File

@ -44,7 +44,7 @@ class CustomWarning extends Error {
[testMsg, { type: testType, code: testCode, detail: null }],
[testMsg, { type: testType, code: testCode, detail: 1 }]
].forEach((i) => {
assert.doesNotThrow(() => process.emitWarning.apply(null, i));
process.emitWarning.apply(null, i);
});
const warningNoToString = new CustomWarning();

View File

@ -28,4 +28,4 @@ assert.strictEqual(symbol in process.env, false);
assert.strictEqual(delete process.env[symbol], true);
// Checks that well-known symbols like `Symbol.toStringTag` wont throw.
assert.doesNotThrow(() => Object.prototype.toString.call(process.env));
Object.prototype.toString.call(process.env);

View File

@ -21,10 +21,8 @@ assert.throws(() => {
// If we're not running as super user...
if (process.getuid() !== 0) {
assert.doesNotThrow(() => {
process.getegid();
process.geteuid();
});
process.getegid();
process.geteuid();
assert.throws(() => {
process.setegid('nobody');

View File

@ -39,10 +39,8 @@ assert.throws(() => {
// If we're not running as super user...
if (process.getuid() !== 0) {
assert.doesNotThrow(() => {
process.getgid();
process.getuid();
});
process.getgid();
process.getuid();
assert.throws(
() => { process.setgid('nobody'); },

View File

@ -300,9 +300,7 @@ assert.strictEqual('foo=', qs.stringify({ foo: Infinity }));
assert.strictEqual(f, 'a=b&q=x%3Dy%26y%3Dz');
}
assert.doesNotThrow(() => {
qs.parse(undefined);
});
qs.parse(undefined);
// nested in colon
{

View File

@ -61,15 +61,15 @@ assert.deepStrictEqual(writable.data, CSI.kClearLine);
assert.deepStrictEqual(writable.data, set[2]);
});
assert.doesNotThrow(() => readline.cursorTo(null));
assert.doesNotThrow(() => readline.cursorTo());
readline.cursorTo(null);
readline.cursorTo();
writable.data = '';
assert.doesNotThrow(() => readline.cursorTo(writable, 'a'));
readline.cursorTo(writable, 'a');
assert.strictEqual(writable.data, '');
writable.data = '';
assert.doesNotThrow(() => readline.cursorTo(writable, 'a', 'b'));
readline.cursorTo(writable, 'a', 'b');
assert.strictEqual(writable.data, '');
writable.data = '';
@ -83,9 +83,9 @@ common.expectsError(
assert.strictEqual(writable.data, '');
writable.data = '';
assert.doesNotThrow(() => readline.cursorTo(writable, 1, 'a'));
readline.cursorTo(writable, 1, 'a');
assert.strictEqual(writable.data, '\x1b[2G');
writable.data = '';
assert.doesNotThrow(() => readline.cursorTo(writable, 1, 2));
readline.cursorTo(writable, 1, 2);
assert.strictEqual(writable.data, '\x1b[3;2H');

View File

@ -823,23 +823,12 @@ function isWarned(emitter) {
fi.emit('data', 'asdf\n');
assert.ok(called);
assert.doesNotThrow(function() {
rli.setPrompt('ddd> ');
});
assert.doesNotThrow(function() {
rli.prompt();
});
assert.doesNotThrow(function() {
rli.write('really shouldnt be seeing this');
});
assert.doesNotThrow(function() {
rli.question('What do you think of node.js? ', function(answer) {
console.log('Thank you for your valuable feedback:', answer);
rli.close();
});
rli.setPrompt('ddd> ');
rli.prompt();
rli.write('really shouldnt be seeing this');
rli.question('What do you think of node.js? ', function(answer) {
console.log('Thank you for your valuable feedback:', answer);
rli.close();
});
}

View File

@ -21,8 +21,5 @@
'use strict';
require('../common');
const assert = require('assert');
assert.doesNotThrow(function() {
require('vm').runInNewContext('"use strict"; var v = 1; v = 2');
});
require('vm').runInNewContext('"use strict"; var v = 1; v = 2');

View File

@ -1,7 +1,6 @@
'use strict';
require('../common');
const repl = require('repl');
const assert = require('assert');
const replserver = new repl.REPLServer();
@ -10,8 +9,5 @@ replserver._inTemplateLiteral = true;
// `null` gets treated like an empty string. (Should it? You have to do some
// strange business to get it into the REPL. Maybe it should really throw?)
assert.doesNotThrow(() => {
replserver.emit('line', null);
});
replserver.emit('line', null);
replserver.emit('line', '.exit');

View File

@ -3,16 +3,11 @@ require('../common');
// This test ensures that the repl does not
// crash or emit error when throwing `null|undefined`
// ie `throw null` or `throw undefined`
// ie `throw null` or `throw undefined`.
const assert = require('assert');
const repl = require('repl');
const r = repl.start();
assert.doesNotThrow(() => {
r.write('throw null\n');
r.write('throw undefined\n');
}, TypeError, 'repl crashes/throw error on `throw null|undefined`');
const r = require('repl').start();
// Should not throw.
r.write('throw null\n');
r.write('throw undefined\n');
r.write('.exit\n');

View File

@ -22,7 +22,7 @@ if (common.isWindows) {
}
if (process.argv[2] === 'child') {
[0, 1, 2].forEach((i) => assert.doesNotThrow(() => fs.fstatSync(i)));
[0, 1, 2].forEach((i) => fs.fstatSync(i));
return;
}

View File

@ -27,14 +27,14 @@ common.expectsError(
}
);
assert.doesNotThrow(() => {
{
const m = new MyWritable({ objectMode: true }).on('error', (e) => {
assert.ok(e);
});
m.write(null, (err) => {
assert.ok(err);
});
});
}
common.expectsError(
() => {
@ -47,24 +47,25 @@ common.expectsError(
}
);
assert.doesNotThrow(() => {
{
const m = new MyWritable().on('error', (e) => {
assert.ok(e);
});
m.write(false, (err) => {
assert.ok(err);
});
});
}
assert.doesNotThrow(() => {
{
const m = new MyWritable({ objectMode: true });
m.write(false, (err) => assert.ifError(err));
});
assert.doesNotThrow(() => {
}
{
const m = new MyWritable({ objectMode: true }).on('error', (e) => {
assert.ifError(e || new Error('should not get here'));
});
m.write(false, (err) => {
assert.ifError(err);
});
});
}

View File

@ -1,18 +1,11 @@
'use strict';
require('../common');
const assert = require('assert');
// This test makes sure clearing timers with
// 'null' or no input does not throw error
assert.doesNotThrow(() => clearInterval(null));
assert.doesNotThrow(() => clearInterval());
assert.doesNotThrow(() => clearTimeout(null));
assert.doesNotThrow(() => clearTimeout());
assert.doesNotThrow(() => clearImmediate(null));
assert.doesNotThrow(() => clearImmediate());
clearInterval(null);
clearInterval();
clearTimeout(null);
clearTimeout();
clearImmediate(null);
clearImmediate();

View File

@ -22,7 +22,6 @@
'use strict';
const common = require('../common');
const assert = require('assert');
let unref_interval = false;
let unref_timer = false;
@ -31,13 +30,8 @@ let checks = 0;
const LONG_TIME = 10 * 1000;
const SHORT_TIME = 100;
assert.doesNotThrow(() => {
setTimeout(() => {}, 10).unref().ref().unref();
}, 'ref and unref are chainable');
assert.doesNotThrow(() => {
setInterval(() => {}, 10).unref().ref().unref();
}, 'ref and unref are chainable');
setTimeout(() => {}, 10).unref().ref().unref();
setInterval(() => {}, 10).unref().ref().unref();
setInterval(common.mustNotCall('Interval should not fire'), LONG_TIME).unref();
setTimeout(common.mustNotCall('Timer should not fire'), LONG_TIME).unref();

View File

@ -24,7 +24,6 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
const fixtures = require('../common/fixtures');
@ -32,8 +31,5 @@ const cert = fixtures.readSync('test_cert.pem');
const key = fixtures.readSync('test_key.pem');
const conn = tls.connect({ cert, key, port: 0 }, common.mustNotCall());
conn.on('error', function() {
});
assert.doesNotThrow(function() {
conn.destroy();
});
conn.on('error', function() {});
conn.destroy();

Some files were not shown because too many files have changed in this diff Show More