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 <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
  • Loading branch information
sreepurnajasti authored and evanlucas committed Jan 30, 2018
1 parent b4e7260 commit 1dcae57
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 @@ -24,7 +24,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 @@ -25,7 +25,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 @@ -26,7 +26,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 @@ -50,7 +50,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 @@ -62,7 +62,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 @@ -87,7 +87,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 @@ -41,8 +41,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 @@ -78,7 +78,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 @@ -102,7 +102,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 @@ -42,8 +42,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 @@ -90,7 +90,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 @@ -58,19 +58,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 @@ -85,7 +85,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 @@ -55,7 +55,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 @@ -97,7 +97,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 @@ -93,7 +93,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 @@ -200,10 +200,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 @@ -38,7 +38,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 @@ -111,9 +111,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 @@ -45,7 +45,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 @@ -43,9 +43,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 @@ -68,7 +68,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 @@ -89,7 +89,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 @@ -51,7 +51,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 @@ -60,7 +60,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 @@ -142,6 +142,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 @@ -57,7 +57,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 @@ -259,7 +259,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 @@ -79,7 +79,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 @@ -94,7 +94,7 @@ 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 @@ -113,7 +113,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 @@ -29,7 +29,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 @@ -102,11 +102,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 @@ -72,8 +72,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 @@ -57,6 +57,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 @@ -52,7 +52,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 @@ -68,7 +68,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 @@ -38,7 +38,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 1dcae57

Please sign in to comment.