Skip to content

Commit

Permalink
test: improve to use template string
Browse files Browse the repository at this point in the history
PR-URL: #18097
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
sreepurnajasti authored and MylesBorins committed Feb 27, 2018
1 parent 8f9362d commit 2004efd
Show file tree
Hide file tree
Showing 31 changed files with 50 additions and 53 deletions.
2 changes: 1 addition & 1 deletion test/message/error_exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require('../common');
const assert = require('assert');

process.on('exit', function(code) {
console.error('Exiting with code=%d', code);
console.error(`Exiting with code=${code}`);
});

assert.strictEqual(1, 2);
2 changes: 1 addition & 1 deletion test/message/max_tick_depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('../common');
process.maxTickDepth = 10;
let i = 20;
process.nextTick(function f() {
console.error('tick %d', i);
console.error(`tick ${i}`);
if (i-- > 0)
process.nextTick(f);
});
4 changes: 2 additions & 2 deletions test/parallel/test-cluster-net-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const fork = require('child_process').fork;
const net = require('net');

if (process.argv[2] !== 'child') {
console.error('[%d] master', process.pid);
console.error(`[${process.pid}] master`);

const worker = fork(__filename, ['child']);
let called = false;
Expand All @@ -29,7 +29,7 @@ if (process.argv[2] !== 'child') {
assert.ok(called);
});
} else {
console.error('[%d] worker', process.pid);
console.error(`[${process.pid}] worker`);

let socket;
let cbcalls = 0;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-domain-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ server.listen(0, next);

function next() {
const port = this.address().port;
console.log('listening on localhost:%d', port);
console.log(`listening on localhost:${port}`);

let requests = 0;
let responses = 0;
Expand All @@ -66,7 +66,7 @@ function next() {
dom.add(req);
req.on('response', function(res) {
responses++;
console.error('requests=%d responses=%d', requests, responses);
console.error(`requests=${requests} responses=${responses}`);
if (responses === requests) {
console.error('done, closing server');
// no more coming.
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-file-write-stream2.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ process.on('exit', function() {
removeTestFile();
if (cb_occurred !== cb_expected) {
console.log(' Test callback events missing or out of order:');
console.log(' expected: %j', cb_expected);
console.log(' occurred: %j', cb_occurred);
console.log(` expected: ${cb_expected}`);
console.log(` occurred: ${cb_occurred}`);
assert.strictEqual(
cb_occurred, cb_expected,
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);
Expand Down Expand Up @@ -57,7 +57,7 @@ file.on('drain', function() {
if (countDrains === 1) {
console.error('drain=1, write again');
assert.strictEqual(fs.readFileSync(filepath, 'utf8'), EXPECTED);
console.error('ondrain write ret=%j', file.write(EXPECTED));
console.error(`ondrain write ret= ${file.write(EXPECTED)}`);
cb_occurred += 'write ';
} else if (countDrains === 2) {
console.error('second drain, end');
Expand All @@ -81,7 +81,7 @@ file.on('error', function(err) {

for (let i = 0; i < 11; i++) {
const ret = file.write(String(i));
console.error('%d %j', i, ret);
console.error(`${i} ${ret}`);

// return false when i hits 10
assert.strictEqual(ret, i !== 10);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-file-write-stream3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const fileDataExpected_3 = 'abcdefghij\u2026\u2026qrstuvwxyz';
process.on('exit', function() {
if (cb_occurred !== cb_expected) {
console.log(' Test callback events missing or out of order:');
console.log(' expected: %j', cb_expected);
console.log(' occurred: %j', cb_occurred);
console.log(` expected: ${cb_expected}`);
console.log(` occurred: ${cb_occurred}`);
assert.strictEqual(
cb_occurred, cb_expected,
`events missing or out of order: "${cb_occurred}" !== "${cb_expected}"`);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-stream-fd-leak.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fs.close = function() {
};

function testLeak(endFn, callback) {
console.log('testing for leaks from fs.createReadStream().%s()...', endFn);
console.log(`testing for leaks from fs.createReadStream().${endFn}()...`);

let i = 0;
let check = 0;
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-write-string-coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
const found = fs.readFileSync(fn, 'utf8');
console.log('expected: "%s"', expected);
console.log('found: "%s"', found);
console.log(`expected: "${expected}"`);
console.log(`found: "${found}"`);
fs.unlinkSync(fn);
assert.strictEqual(expected, found);
}));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-timeout-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ server.listen(0, options.host, function() {
});

process.on('exit', function() {
console.error('done=%j sent=%j', requests_done, requests_sent);
console.error(`done=${requests_done} sent=${requests_sent}`);
assert.strictEqual(requests_done, requests_sent,
'timeout on http request called too much');
});
8 changes: 4 additions & 4 deletions test/parallel/test-http-outgoing-finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ function write(out) {
// that 'finish' isn't emitted until the stream is fully flushed.
out.on('finish', function() {
finishEvent = true;
console.error('%s finish event', name);
console.error(`${name} finish event`);
process.nextTick(function() {
assert(endCb, `${name} got finish event before endcb!`);
console.log('ok - %s finishEvent', name);
console.log(`ok - ${name} finishEvent`);
});
});

out.end(buf, function() {
endCb = true;
console.error('%s endCb', name);
console.error(`${name} endCb`);
process.nextTick(function() {
assert(finishEvent, `${name} got endCb event before finishEvent!`);
console.log('ok - %s endCb', name);
console.log(`ok - ${name} endCb`);
});
});
}
2 changes: 1 addition & 1 deletion test/parallel/test-listen-fd-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function test(cb) {
conn.end('hello from parent\n');
}).listen(0, function() {
const port = this.address().port;
console.error('server listening on %d', port);
console.error(`server listening on ${port}`);

const spawn = require('child_process').spawn;
const master = spawn(process.execPath, [__filename, 'master'], {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-server-max-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function makeConnection(index) {
}

c.on('close', function() {
console.error('closed %d', index);
console.error(`closed ${index}`);
closes++;

if (closes < N / 2) {
Expand Down Expand Up @@ -76,7 +76,7 @@ function makeConnection(index) {
if (common.isSunOS && (e.code === 'ECONNREFUSED')) {
c.connect(server.address().port);
}
console.error('error %d: %s', index, e);
console.error(`error ${index}: ${e}`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-exit-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function parent() {
assert.strictEqual(
code, exit,
`wrong exit for ${arg}\nexpected:${exit} but got:${code}`);
console.log('ok - %s exited with %d', arg, exit);
console.log(`ok - ${arg} exited with ${exit}`);
});
};

Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ const tests = [
let errors = 0;
const handleError = (error, name) => {
console.error(
'FAIL: %s expected %j, got %j',
name,
error.expected,
error.actual
`FAIL: ${name} expected ${error.expected}, got ${error.actual}`
);
errors++;
};
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-syntax-error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function parent() {

child.stderr.setEncoding('utf8');
child.stderr.on('data', function(c) {
console.error('%j', c);
console.error(`${c}`);
throw new Error('should not get stderr data');
});

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-unshift-read-race.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ w.on('finish', common.mustCall(function() {
// lacking that piece.
assert.strictEqual(written[0], 'asdfasdfas');
let asdf = 'd';
console.error('0: %s', written[0]);
console.error(`0: ${written[0]}`);
for (let i = 1; i < written.length; i++) {
console.error('%s: %s', i.toString(32), written[i]);
console.error(`${i.toString(32)}: ${written[i]}`);
assert.strictEqual(written[i].slice(0, 4), '1234');
for (let j = 4; j < written[i].length; j++) {
const c = written[i].charAt(j);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream-writev.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function run() {
}

function test(decode, uncork, multi, next) {
console.log('# decode=%j uncork=%j multi=%j', decode, uncork, multi);
console.log(`# decode=${decode} uncork=${uncork} multi=${multi}`);
let counter = 0;
let expectCount = 0;
function cnt(msg) {
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-stream2-large-read-stall.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ r.on('readable', function() {
console.error('>> readable');
let ret;
do {
console.error(' > read(%d)', READSIZE);
console.error(` > read(${READSIZE})`);
ret = r.read(READSIZE);
console.error(' < %j (%d remain)', ret && ret.length, rs.length);
console.error(` < ${ret && ret.length} (${rs.length} remain)`);
} while (ret && ret.length === READSIZE);

console.error('<< after read()',
Expand All @@ -47,7 +47,7 @@ function push() {
return r.push(null);
}

console.error(' push #%d', pushes);
console.error(` push #${pushes}`);
if (r.push(Buffer.allocUnsafe(PUSHSIZE)))
setTimeout(push, 1);
}
2 changes: 1 addition & 1 deletion test/parallel/test-stream2-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const expectWritten =
'asdfgasdfgasdfgasdfg' ];

writer._write = function(chunk, encoding, cb) {
console.error('WRITE %s', chunk);
console.error(`WRITE ${chunk}`);
written.push(chunk);
process.nextTick(cb);
};
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream2-readable-non-empty-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test.on('readable', function() {
const res = test.read(b);
if (res) {
bytesread += res.length;
console.error('br=%d len=%d', bytesread, len);
console.error(`br=${bytesread} len=${len}`);
setTimeout(next, 1);
}
test.read(0);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-stream3-pause-then-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function read100() {
}

function readn(n, then) {
console.error('read %d', n);
console.error(`read ${n}`);
expectEndingData -= n;
(function read() {
const c = r.read(n);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-client-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ runTest(0);


process.on('exit', function() {
console.log('successful tests: %d', successfulTests);
console.log(`successful tests: ${successfulTests}`);
assert.strictEqual(successfulTests, testCases.length);
});
2 changes: 1 addition & 1 deletion test/parallel/test-tls-pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ server.listen(0, function() {
function send() {
console.error('sending');
const ret = client.write(Buffer.allocUnsafe(bufSize));
console.error('write => %j', ret);
console.error(`write => ${ret}`);
if (false !== ret) {
console.error('write again');
sent += bufSize;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-server-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function runTest(port, testIndex) {
const tcase = testCases[testIndex];
if (!tcase) return;

console.error(`${prefix}Running '%s'`, tcase.title);
console.error(`${prefix}Running '${tcase.title}'`);

const cas = tcase.CAs.map(loadPEM);

Expand Down
6 changes: 3 additions & 3 deletions test/pummel/test-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exec('thisisnotavalidcommand', function(err, stdout, stderr) {
const sleeperStart = new Date();
exec(SLEEP3_COMMAND, { timeout: 50 }, function(err, stdout, stderr) {
const diff = (new Date()) - sleeperStart;
console.log('\'sleep 3\' with timeout 50 took %d ms', diff);
console.log(`'sleep 3' with timeout 50 took ${diff} ms`);
assert.ok(diff < 500);
assert.ok(err);
assert.ok(err.killed);
Expand All @@ -72,7 +72,7 @@ const startSleep3 = new Date();
const killMeTwice = exec(SLEEP3_COMMAND, {timeout: 1000}, killMeTwiceCallback);

process.nextTick(function() {
console.log('kill pid %d', killMeTwice.pid);
console.log(`kill pid ${killMeTwice.pid}`);
// make sure there is no race condition in starting the process
// the PID SHOULD exist directly following the exec() call.
assert.strictEqual('number', typeof killMeTwice._handle.pid);
Expand All @@ -91,7 +91,7 @@ function killMeTwiceCallback(err, stdout, stderr) {
assert.strictEqual(stderr, '');

// the timeout should still be in effect
console.log('\'sleep 3\' was already killed. Took %d ms', diff);
console.log(`'sleep 3' was already killed. Took ${diff} ms`);
assert.ok(diff < 1500);
}

Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-net-write-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const N = 500000;

const server = net.Server(function(socket) {
socket.on('data', function(d) {
console.error('got %d bytes', d.length);
console.error(`got ${d.length} bytes`);
});

socket.on('end', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/pummel/test-regress-GH-892.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ const server = https.Server(serverOptions, function(req, res) {
});

server.listen(common.PORT, function() {
console.log('expecting %d bytes', bytesExpected);
console.log(`expecting ${bytesExpected} bytes`);
makeRequest();
});

process.on('exit', function() {
console.error('got %d bytes', uploadCount);
console.error(`got ${uploadCount} bytes`);
assert.strictEqual(uploadCount, bytesExpected);
});
4 changes: 2 additions & 2 deletions test/pummel/test-tls-throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ server.listen(common.PORT, function() {


function displayCounts() {
console.log('body.length: %d', body.length);
console.log(' recvCount: %d', recvCount);
console.log(`body.length: ${body.length}`);
console.log(` recvCount: ${recvCount}`);
}


Expand Down
2 changes: 1 addition & 1 deletion test/pummel/test-vm-memleak.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ function testContextLeak() {
}

process.on('exit', function() {
console.error('max mem: %dmb', Math.round(maxMem / (1024 * 1024)));
console.error(`max mem: ${Math.round(maxMem / (1024 * 1024))}mb`);
assert.ok(maxMem < 64 * 1024 * 1024);
});
4 changes: 2 additions & 2 deletions test/sequential/test-require-cache-without-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require('../fixtures/a.js');
require('./../fixtures/a.js');
require('http');

console.log('counterBefore = %d', counter);
console.log(`counterBefore = ${counter}`);
const counterBefore = counter;

// Now load the module a bunch of times with equivalent paths.
Expand All @@ -47,7 +47,7 @@ for (let i = 0; i < 100; i++) {
require('http');
}

console.log('counterAfter = %d', counter);
console.log(`counterAfter = ${counter}`);
const counterAfter = counter;

assert.strictEqual(counterBefore, counterAfter);
2 changes: 1 addition & 1 deletion test/sequential/test-stream2-stderr-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function parent() {

child.on('close', function() {
assert.strictEqual(err, `child ${c}\nfoo\nbar\nbaz\n`);
console.log('ok %d child #%d', ++i, c);
console.log(`ok ${++i} child #${c}`);
if (i === children.length)
console.log(`1..${i}`);
});
Expand Down

0 comments on commit 2004efd

Please sign in to comment.