Skip to content

Commit

Permalink
test: remove util from common
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Trott authored and jasnell committed Oct 28, 2015
1 parent 4c411ae commit d4fced7
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -410,15 +409,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);
Expand Down

0 comments on commit d4fced7

Please sign in to comment.