Skip to content

Commit 41a4258

Browse files
Myles Borinsjasnell
Myles Borins
authored andcommitted
test: replace util with backtick strings
Now that we have backticks we no longer need to use util.format to template strings! This commit was inspired by #3324, and it replaces instances of util.format with backtick strings in a number of tests Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]> PR-URL: #3359
1 parent 31a9ecf commit 41a4258

4 files changed

+16
-18
lines changed

test/parallel/test-child-process-spawnsync-input.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
var common = require('../common');
33
var assert = require('assert');
44
var os = require('os');
5-
var util = require('util');
65

76
var spawnSync = require('child_process').spawnSync;
87

@@ -15,7 +14,7 @@ var msgErrBuf = new Buffer(msgErr + '\n');
1514

1615
var args = [
1716
'-e',
18-
util.format('console.log("%s"); console.error("%s");', msgOut, msgErr)
17+
`console.log("${msgOut}"); console.error("${msgErr}");`
1918
];
2019

2120
var ret;

test/parallel/test-child-process-spawnsync.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

5-
var spawnSync = require('child_process').spawnSync;
5+
const spawnSync = require('child_process').spawnSync;
66

77
// Echo does different things on Windows and Unix, but in both cases, it does
88
// more-or-less nothing if there are no parameters
9-
var ret = spawnSync('sleep', ['0']);
9+
const ret = spawnSync('sleep', ['0']);
1010
assert.strictEqual(ret.status, 0, 'exit status should be zero');
1111

1212
// Error test when command does not exist
13-
var ret_err = spawnSync('command_does_not_exist', ['bar']).error;
13+
const ret_err = spawnSync('command_does_not_exist', ['bar']).error;
1414

1515
assert.strictEqual(ret_err.code, 'ENOENT');
1616
assert.strictEqual(ret_err.errno, 'ENOENT');

test/parallel/test-repl-setprompt.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict';
2-
var common = require('../common'),
3-
assert = require('assert'),
4-
spawn = require('child_process').spawn,
5-
os = require('os'),
6-
util = require('util');
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const spawn = require('child_process').spawn;
5+
const os = require('os');
76

87
var args = [
98
'-e',
@@ -19,7 +18,7 @@ child.stdout.setEncoding('utf8');
1918
var data = '';
2019
child.stdout.on('data', function(d) { data += d; });
2120

22-
child.stdin.end(util.format("e.setPrompt('%s');%s", p, os.EOL));
21+
child.stdin.end(`e.setPrompt("${p}");${os.EOL}`);
2322

2423
child.on('close', function(code, signal) {
2524
assert.strictEqual(code, 0);

test/sequential/test-child-process-execsync.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22
var common = require('../common');
33
var assert = require('assert');
4-
var util = require('util');
54
var os = require('os');
65

76
var execSync = require('child_process').execSync;
@@ -13,10 +12,10 @@ var SLEEP = 2000;
1312
var start = Date.now();
1413
var err;
1514
var caught = false;
15+
1616
try
1717
{
18-
var cmd = util.format('"%s" -e "setTimeout(function(){}, %d);"',
19-
process.execPath, SLEEP);
18+
var cmd = `"${process.execPath}" -e "setTimeout(function(){}, ${SLEEP});"`;
2019
var ret = execSync(cmd, {timeout: TIMER});
2120
} catch (e) {
2221
caught = true;
@@ -38,7 +37,8 @@ var msg = 'foobar';
3837
var msgBuf = new Buffer(msg + '\n');
3938

4039
// console.log ends every line with just '\n', even on Windows.
41-
cmd = util.format('"%s" -e "console.log(\'%s\');"', process.execPath, msg);
40+
41+
cmd = `"${process.execPath}" -e "console.log(\'${msg}\');"`;
4242

4343
var ret = execSync(cmd);
4444

@@ -51,7 +51,7 @@ assert.strictEqual(ret, msg + '\n', 'execSync encoding result should match');
5151

5252
var args = [
5353
'-e',
54-
util.format('console.log("%s");', msg)
54+
`console.log("${msg}");`
5555
];
5656
ret = execFileSync(process.execPath, args);
5757

0 commit comments

Comments
 (0)