Skip to content

Commit 6f14b3a

Browse files
committed
test: remove util from common
util is loaded just for one use of util.format(). Replace it with a string template. While we're at it, delete nearby lengthy comment justifying use of fs.readFileSync(). PR-URL: #3324 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed By: Evan Lucas <evanlucas@me.com>
1 parent 931118c commit 6f14b3a

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

test/common.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var fs = require('fs');
55
var assert = require('assert');
66
var os = require('os');
77
var child_process = require('child_process');
8-
var util = require('util');
98

109

1110
exports.testDir = path.dirname(__filename);
@@ -405,15 +404,9 @@ exports.getServiceName = function getServiceName(port, protocol) {
405404
var serviceName = port.toString();
406405

407406
try {
408-
/*
409-
* I'm not a big fan of readFileSync, but reading /etc/services
410-
* asynchronously here would require implementing a simple line parser,
411-
* which seems overkill for a simple utility function that is not running
412-
* concurrently with any other one.
413-
*/
414407
var servicesContent = fs.readFileSync(etcServicesFileName,
415408
{ encoding: 'utf8'});
416-
var regexp = util.format('^(\\w+)\\s+\\s%d/%s\\s', port, protocol);
409+
var regexp = `^(\\w+)\\s+\\s${port}/${protocol}\\s`;
417410
var re = new RegExp(regexp, 'm');
418411

419412
var matches = re.exec(servicesContent);

0 commit comments

Comments
 (0)