Skip to content

Commit

Permalink
test: use common.expectsError in tests
Browse files Browse the repository at this point in the history
PR-URL: #17484
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
  • Loading branch information
mithunsasidharan authored and MylesBorins committed Dec 12, 2017
1 parent d15cdc6 commit 28b2d8a
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
6 changes: 3 additions & 3 deletions test/parallel/test-buffer-slow.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ const bufferMaxSizeMsg = common.expectsError({
assert.throws(function() {
SlowBuffer(Infinity);
}, bufferMaxSizeMsg);
assert.throws(function() {
common.expectsError(function() {
SlowBuffer(-1);
}, common.expectsError({
}, {
code: 'ERR_INVALID_OPT_VALUE',
type: RangeError,
message: 'The value "-1" is invalid for option "size"'
}));
});

assert.throws(function() {
SlowBuffer(buffer.kMaxLength + 1);
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-buffer-tostring-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ assert.strictEqual(rangeBuffer.toString({ toString: function() {
} }), 'abc');

// try toString() with 0 and null as the encoding
assert.throws(() => {
common.expectsError(() => {
rangeBuffer.toString(0, 1, 2);
}, common.expectsError({
}, {
code: 'ERR_UNKNOWN_ENCODING',
type: TypeError,
message: 'Unknown encoding: 0'
}));
assert.throws(() => {
});
common.expectsError(() => {
rangeBuffer.toString(null, 1, 2);
}, common.expectsError({
}, {
code: 'ERR_UNKNOWN_ENCODING',
type: TypeError,
message: 'Unknown encoding: null'
}));
});
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-send-type-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const assert = require('assert');
const cp = require('child_process');

function fail(proc, args) {
assert.throws(() => {
common.expectsError(() => {
proc.send.apply(proc, args);
}, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE', type: TypeError }));
}, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError });
}

let target = process;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-spawnsync-kill-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ if (process.argv[2] === 'child') {
}

// Verify that an error is thrown for unknown signals.
assert.throws(() => {
common.expectsError(() => {
spawn('SIG_NOT_A_REAL_SIGNAL');
}, common.expectsError({ code: 'ERR_UNKNOWN_SIGNAL', type: TypeError }));
}, { code: 'ERR_UNKNOWN_SIGNAL', type: TypeError });

// Verify that the default kill signal is SIGTERM.
{
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ options = { stdio: 'ignore' };
child = spawnSync('cat', [], options);
assert.deepStrictEqual(options, { stdio: 'ignore' });

assert.throws(() => {
common.expectsError(() => {
common.spawnPwd({ stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'ipc'] });
}, common.expectsError({ code: 'ERR_IPC_ONE_PIPE', type: Error }));
}, { code: 'ERR_IPC_ONE_PIPE', type: Error });
5 changes: 3 additions & 2 deletions test/parallel/test-child-process-validate-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ assert.throws(() => _validateStdio(600), expectedError);

// should throw if stdio has ipc and sync is true
const stdio2 = ['ipc', 'ipc', 'ipc'];
assert.throws(() => _validateStdio(stdio2, true),
common.expectsError({ code: 'ERR_IPC_SYNC_FORK', type: Error }));
common.expectsError(() => _validateStdio(stdio2, true),
{ code: 'ERR_IPC_SYNC_FORK', type: Error }
);

{
const stdio3 = [process.stdin, process.stdout, process.stderr];
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ assert.throws(function() {
}, /^TypeError: Invalid minimum value: \/foo\/$/);

// assert.fail() tests
assert.throws(
common.expectsError(
() => { assert.fail('fhqwhgads'); },
common.expectsError({
{
code: 'ERR_ASSERTION',
message: /^fhqwhgads$/
}));
});

const fnOnce = common.mustCall(() => {});
fnOnce();
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-console-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ assert.strictEqual('function', typeof Console);

// make sure that the Console constructor throws
// when not given a writable stream instance
assert.throws(
common.expectsError(
() => { new Console(); },
common.expectsError({
{
code: 'ERR_CONSOLE_WRITABLE_STREAM',
type: TypeError,
message: /stdout/
})
}
);

// Console constructor should throw if stderr exists but is not writable
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-dgram-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const dgram = require('dgram');
const socket = dgram.createSocket('udp4');

socket.on('listening', common.mustCall(() => {
assert.throws(() => {
common.expectsError(() => {
socket.bind();
}, common.expectsError({
}, {
code: 'ERR_SOCKET_ALREADY_BOUND',
type: Error,
message: /^Socket is already bound$/
}));
});

socket.close();
}));
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-dgram-create-socket-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const UDP = process.binding('udp_wrap').UDP;
const _createSocketHandle = dgram._createSocketHandle;

// Throws if an "existing fd" is passed in.
assert.throws(() => {
common.expectsError(() => {
_createSocketHandle(common.localhostIPv4, 0, 'udp4', 42);
}, common.expectsError({
}, {
code: 'ERR_ASSERTION',
message: /^false == true$/
}));
});

{
// Create a handle that is not bound.
Expand Down

0 comments on commit 28b2d8a

Please sign in to comment.