From 6f14b3a7db93d3d2e2c20b3489dd7ddb7171ee97 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 11 Oct 2015 22:14:01 -0700 Subject: [PATCH] test: remove util from common MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/3324 Reviewed-By: Michaël Zasso Reviewed-By: Johan Bergström Reviewed By: Evan Lucas --- test/common.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/common.js b/test/common.js index 1ec8fa8f30597f..b4aa4edaf3dca0 100644 --- a/test/common.js +++ b/test/common.js @@ -5,7 +5,6 @@ var fs = require('fs'); var assert = require('assert'); var os = require('os'); var child_process = require('child_process'); -var util = require('util'); exports.testDir = path.dirname(__filename); @@ -405,15 +404,9 @@ exports.getServiceName = function getServiceName(port, protocol) { var serviceName = port.toString(); try { - /* - * I'm not a big fan of readFileSync, but reading /etc/services - * asynchronously here would require implementing a simple line parser, - * which seems overkill for a simple utility function that is not running - * concurrently with any other one. - */ var servicesContent = fs.readFileSync(etcServicesFileName, { encoding: 'utf8'}); - var regexp = util.format('^(\\w+)\\s+\\s%d/%s\\s', port, protocol); + var regexp = `^(\\w+)\\s+\\s${port}/${protocol}\\s`; var re = new RegExp(regexp, 'm'); var matches = re.exec(servicesContent);