benchmark,lib,test: use braces for multiline block
For if/else and loops where the bodies span more than one line, use curly braces. PR-URL: https://github.com/nodejs/node/pull/13828 Ref: https://github.com/nodejs/node/pull/13623#discussion_r123048602 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
e3ea0fc97b
commit
095c0de94d
@ -29,9 +29,11 @@ function main(conf) {
|
|||||||
function benchFor(buffer, n) {
|
function benchFor(buffer, n) {
|
||||||
bench.start();
|
bench.start();
|
||||||
|
|
||||||
for (var k = 0; k < n; k++)
|
for (var k = 0; k < n; k++) {
|
||||||
for (var i = 0; i < buffer.length; i++)
|
for (var i = 0; i < buffer.length; i++) {
|
||||||
assert(buffer[i] === 0);
|
assert(buffer[i] === 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
@ -39,10 +41,11 @@ function benchFor(buffer, n) {
|
|||||||
function benchForOf(buffer, n) {
|
function benchForOf(buffer, n) {
|
||||||
bench.start();
|
bench.start();
|
||||||
|
|
||||||
for (var k = 0; k < n; k++)
|
for (var k = 0; k < n; k++) {
|
||||||
for (var b of buffer)
|
for (var b of buffer) {
|
||||||
assert(b === 0);
|
assert(b === 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,18 +46,20 @@ function server() {
|
|||||||
var onsend = type === 'concat' ? onsendConcat : onsendMulti;
|
var onsend = type === 'concat' ? onsendConcat : onsendMulti;
|
||||||
|
|
||||||
function onsendConcat() {
|
function onsendConcat() {
|
||||||
if (sent++ % num === 0)
|
if (sent++ % num === 0) {
|
||||||
for (var i = 0; i < num; i++) {
|
for (var i = 0; i < num; i++) {
|
||||||
socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
|
socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onsendMulti() {
|
function onsendMulti() {
|
||||||
if (sent++ % num === 0)
|
if (sent++ % num === 0) {
|
||||||
for (var i = 0; i < num; i++) {
|
for (var i = 0; i < num; i++) {
|
||||||
socket.send(chunk, PORT, '127.0.0.1', onsend);
|
socket.send(chunk, PORT, '127.0.0.1', onsend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('listening', function() {
|
socket.on('listening', function() {
|
||||||
bench.start();
|
bench.start();
|
||||||
|
@ -45,10 +45,12 @@ function server() {
|
|||||||
var socket = dgram.createSocket('udp4');
|
var socket = dgram.createSocket('udp4');
|
||||||
|
|
||||||
function onsend() {
|
function onsend() {
|
||||||
if (sent++ % num === 0)
|
if (sent++ % num === 0) {
|
||||||
for (var i = 0; i < num; i++)
|
for (var i = 0; i < num; i++) {
|
||||||
socket.send(chunk, PORT, '127.0.0.1', onsend);
|
socket.send(chunk, PORT, '127.0.0.1', onsend);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('listening', function() {
|
socket.on('listening', function() {
|
||||||
bench.start();
|
bench.start();
|
||||||
|
@ -37,10 +37,12 @@ function server() {
|
|||||||
var socket = dgram.createSocket('udp4');
|
var socket = dgram.createSocket('udp4');
|
||||||
|
|
||||||
function onsend() {
|
function onsend() {
|
||||||
if (sent++ % num === 0)
|
if (sent++ % num === 0) {
|
||||||
for (var i = 0; i < num; i++)
|
for (var i = 0; i < num; i++) {
|
||||||
socket.send(chunk, 0, chunk.length, PORT, '127.0.0.1', onsend);
|
socket.send(chunk, 0, chunk.length, PORT, '127.0.0.1', onsend);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('listening', function() {
|
socket.on('listening', function() {
|
||||||
bench.start();
|
bench.start();
|
||||||
|
@ -37,10 +37,12 @@ function server() {
|
|||||||
var socket = dgram.createSocket('udp4');
|
var socket = dgram.createSocket('udp4');
|
||||||
|
|
||||||
function onsend() {
|
function onsend() {
|
||||||
if (sent++ % num === 0)
|
if (sent++ % num === 0) {
|
||||||
for (var i = 0; i < num; i++)
|
for (var i = 0; i < num; i++) {
|
||||||
socket.send(chunk, PORT, '127.0.0.1', onsend);
|
socket.send(chunk, PORT, '127.0.0.1', onsend);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('listening', function() {
|
socket.on('listening', function() {
|
||||||
bench.start();
|
bench.start();
|
||||||
|
@ -32,11 +32,12 @@ function iterator(n) {
|
|||||||
const noDead = [];
|
const noDead = [];
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (var i = 0; i < n; i += 1)
|
for (var i = 0; i < n; i += 1) {
|
||||||
for (var pair of params) {
|
for (var pair of params) {
|
||||||
noDead[0] = pair[0];
|
noDead[0] = pair[0];
|
||||||
noDead[1] = pair[1];
|
noDead[1] = pair[1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
|
|
||||||
assert.strictEqual(noDead[0], 'three');
|
assert.strictEqual(noDead[0], 'three');
|
||||||
|
@ -319,12 +319,13 @@ ClientRequest.prototype.abort = function abort() {
|
|||||||
this.aborted = Date.now();
|
this.aborted = Date.now();
|
||||||
|
|
||||||
// If we're aborting, we don't care about any more response data.
|
// If we're aborting, we don't care about any more response data.
|
||||||
if (this.res)
|
if (this.res) {
|
||||||
this.res._dump();
|
this.res._dump();
|
||||||
else
|
} else {
|
||||||
this.once('response', function(res) {
|
this.once('response', function(res) {
|
||||||
res._dump();
|
res._dump();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// In the event that we don't have a socket, we will pop out of
|
// In the event that we don't have a socket, we will pop out of
|
||||||
// the request queue through handling in onSocket.
|
// the request queue through handling in onSocket.
|
||||||
|
@ -219,12 +219,13 @@ OutgoingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
|
|||||||
// any messages, before ever calling this. In that case, just skip
|
// any messages, before ever calling this. In that case, just skip
|
||||||
// it, since something else is destroying this connection anyway.
|
// it, since something else is destroying this connection anyway.
|
||||||
OutgoingMessage.prototype.destroy = function destroy(error) {
|
OutgoingMessage.prototype.destroy = function destroy(error) {
|
||||||
if (this.socket)
|
if (this.socket) {
|
||||||
this.socket.destroy(error);
|
this.socket.destroy(error);
|
||||||
else
|
} else {
|
||||||
this.once('socket', function(socket) {
|
this.once('socket', function(socket) {
|
||||||
socket.destroy(error);
|
socket.destroy(error);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -505,8 +506,7 @@ function matchHeader(self, state, field, value) {
|
|||||||
|
|
||||||
function validateHeader(msg, name, value) {
|
function validateHeader(msg, name, value) {
|
||||||
if (typeof name !== 'string' || !name || !checkIsHttpToken(name))
|
if (typeof name !== 'string' || !name || !checkIsHttpToken(name))
|
||||||
throw new TypeError(
|
throw new TypeError(`Header name must be a valid HTTP Token ["${name}"]`);
|
||||||
'Header name must be a valid HTTP Token ["' + name + '"]');
|
|
||||||
if (value === undefined)
|
if (value === undefined)
|
||||||
throw new Error('"value" required in setHeader("' + name + '", value)');
|
throw new Error('"value" required in setHeader("' + name + '", value)');
|
||||||
if (msg._header)
|
if (msg._header)
|
||||||
|
@ -185,9 +185,10 @@ function writeHead(statusCode, reason, obj) {
|
|||||||
var originalStatusCode = statusCode;
|
var originalStatusCode = statusCode;
|
||||||
|
|
||||||
statusCode |= 0;
|
statusCode |= 0;
|
||||||
if (statusCode < 100 || statusCode > 999)
|
if (statusCode < 100 || statusCode > 999) {
|
||||||
throw new errors.RangeError('ERR_HTTP_INVALID_STATUS_CODE',
|
throw new errors.RangeError('ERR_HTTP_INVALID_STATUS_CODE',
|
||||||
originalStatusCode);
|
originalStatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (typeof reason === 'string') {
|
if (typeof reason === 'string') {
|
||||||
@ -224,9 +225,10 @@ function writeHead(statusCode, reason, obj) {
|
|||||||
headers = obj;
|
headers = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (common._checkInvalidHeaderChar(this.statusMessage))
|
if (common._checkInvalidHeaderChar(this.statusMessage)) {
|
||||||
throw new errors.Error('ERR_HTTP_INVALID_CHAR',
|
throw new errors.Error('ERR_HTTP_INVALID_CHAR',
|
||||||
'Invalid character in statusMessage.');
|
'Invalid character in statusMessage.');
|
||||||
|
}
|
||||||
|
|
||||||
var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF;
|
var statusLine = 'HTTP/1.1 ' + statusCode + ' ' + this.statusMessage + CRLF;
|
||||||
|
|
||||||
|
@ -207,13 +207,14 @@ Object.setPrototypeOf(Buffer, Uint8Array);
|
|||||||
function assertSize(size) {
|
function assertSize(size) {
|
||||||
let err = null;
|
let err = null;
|
||||||
|
|
||||||
if (typeof size !== 'number')
|
if (typeof size !== 'number') {
|
||||||
err = new TypeError('"size" argument must be a number');
|
err = new TypeError('"size" argument must be a number');
|
||||||
else if (size < 0)
|
} else if (size < 0) {
|
||||||
err = new RangeError('"size" argument must not be negative');
|
err = new RangeError('"size" argument must not be negative');
|
||||||
else if (size > binding.kMaxLength)
|
} else if (size > binding.kMaxLength) {
|
||||||
err = new RangeError('"size" argument must not be larger ' +
|
err = new RangeError('"size" argument must not be larger ' +
|
||||||
'than ' + binding.kMaxLength);
|
'than ' + binding.kMaxLength);
|
||||||
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
Error.captureStackTrace(err, assertSize);
|
Error.captureStackTrace(err, assertSize);
|
||||||
|
@ -533,17 +533,18 @@ function spawnSync(/*file, args, options*/) {
|
|||||||
var input = options.stdio[i] && options.stdio[i].input;
|
var input = options.stdio[i] && options.stdio[i].input;
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]);
|
var pipe = options.stdio[i] = util._extend({}, options.stdio[i]);
|
||||||
if (isUint8Array(input))
|
if (isUint8Array(input)) {
|
||||||
pipe.input = input;
|
pipe.input = input;
|
||||||
else if (typeof input === 'string')
|
} else if (typeof input === 'string') {
|
||||||
pipe.input = Buffer.from(input, options.encoding);
|
pipe.input = Buffer.from(input, options.encoding);
|
||||||
else
|
} else {
|
||||||
throw new TypeError(util.format(
|
throw new TypeError(util.format(
|
||||||
'stdio[%d] should be Buffer, Uint8Array or string not %s',
|
'stdio[%d] should be Buffer, Uint8Array or string not %s',
|
||||||
i,
|
i,
|
||||||
typeof input));
|
typeof input));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return child_process.spawnSync(opts);
|
return child_process.spawnSync(opts);
|
||||||
}
|
}
|
||||||
|
@ -1951,10 +1951,11 @@ ReadStream.prototype.open = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ReadStream.prototype._read = function(n) {
|
ReadStream.prototype._read = function(n) {
|
||||||
if (typeof this.fd !== 'number')
|
if (typeof this.fd !== 'number') {
|
||||||
return this.once('open', function() {
|
return this.once('open', function() {
|
||||||
this._read(n);
|
this._read(n);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
@ -2116,10 +2117,11 @@ WriteStream.prototype._write = function(data, encoding, cb) {
|
|||||||
if (!(data instanceof Buffer))
|
if (!(data instanceof Buffer))
|
||||||
return this.emit('error', new Error('Invalid data'));
|
return this.emit('error', new Error('Invalid data'));
|
||||||
|
|
||||||
if (typeof this.fd !== 'number')
|
if (typeof this.fd !== 'number') {
|
||||||
return this.once('open', function() {
|
return this.once('open', function() {
|
||||||
this._write(data, encoding, cb);
|
this._write(data, encoding, cb);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
fs.write(this.fd, data, 0, data.length, this.pos, function(er, bytes) {
|
fs.write(this.fd, data, 0, data.length, this.pos, function(er, bytes) {
|
||||||
@ -2151,10 +2153,11 @@ function writev(fd, chunks, position, callback) {
|
|||||||
|
|
||||||
|
|
||||||
WriteStream.prototype._writev = function(data, cb) {
|
WriteStream.prototype._writev = function(data, cb) {
|
||||||
if (typeof this.fd !== 'number')
|
if (typeof this.fd !== 'number') {
|
||||||
return this.once('open', function() {
|
return this.once('open', function() {
|
||||||
this._writev(data, cb);
|
this._writev(data, cb);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
const len = data.length;
|
const len = data.length;
|
||||||
|
@ -41,22 +41,26 @@ class Session extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
post(method, params, callback) {
|
post(method, params, callback) {
|
||||||
if (typeof method !== 'string')
|
if (typeof method !== 'string') {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`"method" must be a string, got ${typeof method} instead`);
|
`"method" must be a string, got ${typeof method} instead`);
|
||||||
|
}
|
||||||
if (!callback && util.isFunction(params)) {
|
if (!callback && util.isFunction(params)) {
|
||||||
callback = params;
|
callback = params;
|
||||||
params = null;
|
params = null;
|
||||||
}
|
}
|
||||||
if (params && typeof params !== 'object')
|
if (params && typeof params !== 'object') {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`"params" must be an object, got ${typeof params} instead`);
|
`"params" must be an object, got ${typeof params} instead`);
|
||||||
if (callback && typeof callback !== 'function')
|
}
|
||||||
|
if (callback && typeof callback !== 'function') {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`"callback" must be a function, got ${typeof callback} instead`);
|
`"callback" must be a function, got ${typeof callback} instead`);
|
||||||
|
}
|
||||||
|
|
||||||
if (!this[connectionSymbol])
|
if (!this[connectionSymbol]) {
|
||||||
throw new Error('Session is not connected');
|
throw new Error('Session is not connected');
|
||||||
|
}
|
||||||
const id = this[nextIdSymbol]++;
|
const id = this[nextIdSymbol]++;
|
||||||
const message = {id, method};
|
const message = {id, method};
|
||||||
if (params) {
|
if (params) {
|
||||||
|
@ -46,10 +46,12 @@ function setup_cpuUsage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If a previous value was passed in, return diff of current from previous.
|
// If a previous value was passed in, return diff of current from previous.
|
||||||
if (prevValue) return {
|
if (prevValue) {
|
||||||
|
return {
|
||||||
user: cpuValues[0] - prevValue.user,
|
user: cpuValues[0] - prevValue.user,
|
||||||
system: cpuValues[1] - prevValue.system
|
system: cpuValues[1] - prevValue.system
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// If no previous value passed in, return current value.
|
// If no previous value passed in, return current value.
|
||||||
return {
|
return {
|
||||||
|
12
lib/net.js
12
lib/net.js
@ -1005,20 +1005,24 @@ function lookupAndConnect(self, options) {
|
|||||||
var localAddress = options.localAddress;
|
var localAddress = options.localAddress;
|
||||||
var localPort = options.localPort;
|
var localPort = options.localPort;
|
||||||
|
|
||||||
if (localAddress && !cares.isIP(localAddress))
|
if (localAddress && !cares.isIP(localAddress)) {
|
||||||
throw new TypeError('"localAddress" option must be a valid IP: ' +
|
throw new TypeError('"localAddress" option must be a valid IP: ' +
|
||||||
localAddress);
|
localAddress);
|
||||||
|
}
|
||||||
|
|
||||||
if (localPort && typeof localPort !== 'number')
|
if (localPort && typeof localPort !== 'number') {
|
||||||
throw new TypeError('"localPort" option should be a number: ' + localPort);
|
throw new TypeError('"localPort" option should be a number: ' + localPort);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof port !== 'undefined') {
|
if (typeof port !== 'undefined') {
|
||||||
if (typeof port !== 'number' && typeof port !== 'string')
|
if (typeof port !== 'number' && typeof port !== 'string') {
|
||||||
throw new TypeError('"port" option should be a number or string: ' +
|
throw new TypeError('"port" option should be a number or string: ' +
|
||||||
port);
|
port);
|
||||||
if (!isLegalPort(port))
|
}
|
||||||
|
if (!isLegalPort(port)) {
|
||||||
throw new RangeError('"port" option should be >= 0 and < 65536: ' + port);
|
throw new RangeError('"port" option should be >= 0 and < 65536: ' + port);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
port |= 0;
|
port |= 0;
|
||||||
|
|
||||||
// If host is an IP, skip performing a lookup
|
// If host is an IP, skip performing a lookup
|
||||||
|
@ -285,16 +285,18 @@ Interface.prototype._onLine = function(line) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
|
Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
|
||||||
if (typeof stringToWrite !== 'string')
|
if (typeof stringToWrite !== 'string') {
|
||||||
throw new errors.TypeError(
|
throw new errors.TypeError(
|
||||||
'ERR_INVALID_ARG_TYPE',
|
'ERR_INVALID_ARG_TYPE',
|
||||||
'stringToWrite',
|
'stringToWrite',
|
||||||
'string',
|
'string',
|
||||||
stringToWrite
|
stringToWrite
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.output !== null && this.output !== undefined)
|
if (this.output !== null && this.output !== undefined) {
|
||||||
this.output.write(stringToWrite);
|
this.output.write(stringToWrite);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Interface.prototype._addHistory = function() {
|
Interface.prototype._addHistory = function() {
|
||||||
|
@ -122,9 +122,10 @@ function check(hostParts, pattern, wildcards) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check host parts from right to left first.
|
// Check host parts from right to left first.
|
||||||
for (var i = hostParts.length - 1; i > 0; i -= 1)
|
for (var i = hostParts.length - 1; i > 0; i -= 1) {
|
||||||
if (hostParts[i] !== patternParts[i])
|
if (hostParts[i] !== patternParts[i])
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const hostSubdomain = hostParts[0];
|
const hostSubdomain = hostParts[0];
|
||||||
const patternSubdomain = patternParts[0];
|
const patternSubdomain = patternParts[0];
|
||||||
|
@ -962,9 +962,10 @@ exports.inherits = function(ctor, superCtor) {
|
|||||||
if (superCtor === undefined || superCtor === null)
|
if (superCtor === undefined || superCtor === null)
|
||||||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'function');
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'function');
|
||||||
|
|
||||||
if (superCtor.prototype === undefined)
|
if (superCtor.prototype === undefined) {
|
||||||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype',
|
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor.prototype',
|
||||||
'function');
|
'function');
|
||||||
|
}
|
||||||
ctor.super_ = superCtor;
|
ctor.super_ = superCtor;
|
||||||
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
|
Object.setPrototypeOf(ctor.prototype, superCtor.prototype);
|
||||||
};
|
};
|
||||||
|
@ -429,9 +429,11 @@ function leakedGlobals() {
|
|||||||
const leaked = [];
|
const leaked = [];
|
||||||
|
|
||||||
// eslint-disable-next-line no-var
|
// eslint-disable-next-line no-var
|
||||||
for (var val in global)
|
for (var val in global) {
|
||||||
if (!knownGlobals.includes(global[val]))
|
if (!knownGlobals.includes(global[val])) {
|
||||||
leaked.push(val);
|
leaked.push(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (global.__coverage__) {
|
if (global.__coverage__) {
|
||||||
return leaked.filter((varname) => !/^(?:cov_|__cov)/.test(varname));
|
return leaked.filter((varname) => !/^(?:cov_|__cov)/.test(varname));
|
||||||
@ -700,9 +702,10 @@ Object.defineProperty(exports, 'hasSmallICU', {
|
|||||||
exports.expectsError = function expectsError({code, type, message}) {
|
exports.expectsError = function expectsError({code, type, message}) {
|
||||||
return function(error) {
|
return function(error) {
|
||||||
assert.strictEqual(error.code, code);
|
assert.strictEqual(error.code, code);
|
||||||
if (type !== undefined)
|
if (type !== undefined) {
|
||||||
assert(error instanceof type,
|
assert(error instanceof type,
|
||||||
`${error} is not the expected type ${type}`);
|
`${error} is not the expected type ${type}`);
|
||||||
|
}
|
||||||
if (message instanceof RegExp) {
|
if (message instanceof RegExp) {
|
||||||
assert(message.test(error.message),
|
assert(message.test(error.message),
|
||||||
`${error.message} does not match ${message}`);
|
`${error.message} does not match ${message}`);
|
||||||
@ -758,12 +761,14 @@ exports.getTTYfd = function getTTYfd() {
|
|||||||
if (!tty.isatty(tty_fd)) tty_fd++;
|
if (!tty.isatty(tty_fd)) tty_fd++;
|
||||||
else if (!tty.isatty(tty_fd)) tty_fd++;
|
else if (!tty.isatty(tty_fd)) tty_fd++;
|
||||||
else if (!tty.isatty(tty_fd)) tty_fd++;
|
else if (!tty.isatty(tty_fd)) tty_fd++;
|
||||||
else try {
|
else {
|
||||||
|
try {
|
||||||
tty_fd = require('fs').openSync('/dev/tty');
|
tty_fd = require('fs').openSync('/dev/tty');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// There aren't any tty fd's available to use.
|
// There aren't any tty fd's available to use.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return tty_fd;
|
return tty_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,10 +182,11 @@ if (process.argv[2] === 'child') {
|
|||||||
// Make sure that all expected messages were sent from the
|
// Make sure that all expected messages were sent from the
|
||||||
// child process
|
// child process
|
||||||
test.expectedMessages.forEach(function(expectedMessage) {
|
test.expectedMessages.forEach(function(expectedMessage) {
|
||||||
if (test.messagesReceived === undefined ||
|
const msgs = test.messagesReceived;
|
||||||
test.messagesReceived.indexOf(expectedMessage) === -1)
|
if (msgs === undefined || !msgs.includes(expectedMessage)) {
|
||||||
assert.fail(`test ${test.fn.name} should have sent message: ${
|
assert.fail(`test ${test.fn.name} should have sent message: ${
|
||||||
expectedMessage} but didn't`);
|
expectedMessage} but didn't`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (test.messagesReceived) {
|
if (test.messagesReceived) {
|
||||||
|
@ -33,14 +33,16 @@ function check(async, sync) {
|
|||||||
assert.strictEqual(er.code, 'ENOENT');
|
assert.strictEqual(er.code, 'ENOENT');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sync)
|
if (sync) {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
sync.apply(null, argsSync);
|
sync.apply(null, argsSync);
|
||||||
}, expected);
|
}, expected);
|
||||||
|
}
|
||||||
|
|
||||||
if (async)
|
if (async) {
|
||||||
async.apply(null, argsAsync);
|
async.apply(null, argsAsync);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
check(fs.access, fs.accessSync, 'foo\u0000bar');
|
check(fs.access, fs.accessSync, 'foo\u0000bar');
|
||||||
check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK);
|
check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK);
|
||||||
|
@ -46,9 +46,10 @@ function makeCallback(c) {
|
|||||||
if (called)
|
if (called)
|
||||||
throw new Error(`called callback #${c} more than once`);
|
throw new Error(`called callback #${c} more than once`);
|
||||||
called = true;
|
called = true;
|
||||||
if (c < lastCalled)
|
if (c < lastCalled) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`callbacks out of order. last=${lastCalled} current=${c}`);
|
`callbacks out of order. last=${lastCalled} current=${c}`);
|
||||||
|
}
|
||||||
lastCalled = c;
|
lastCalled = c;
|
||||||
cbcount++;
|
cbcount++;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user