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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
931118c9d7
commit
6f14b3a7db
@ -5,7 +5,6 @@ var fs = require('fs');
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
var util = require('util');
|
|
||||||
|
|
||||||
|
|
||||||
exports.testDir = path.dirname(__filename);
|
exports.testDir = path.dirname(__filename);
|
||||||
@ -405,15 +404,9 @@ exports.getServiceName = function getServiceName(port, protocol) {
|
|||||||
var serviceName = port.toString();
|
var serviceName = port.toString();
|
||||||
|
|
||||||
try {
|
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,
|
var servicesContent = fs.readFileSync(etcServicesFileName,
|
||||||
{ encoding: 'utf8'});
|
{ 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 re = new RegExp(regexp, 'm');
|
||||||
|
|
||||||
var matches = re.exec(servicesContent);
|
var matches = re.exec(servicesContent);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user