Skip to content

Commit

Permalink
test: fix tests that check error messages
Browse files Browse the repository at this point in the history
20285ad changed the format
of error messages throughout lib. However, the tests were not
updated to reflect these changes. This commit makes those
changes.

PR-URL: #3727
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and silverwind committed Nov 10, 2015
1 parent 7b89a3d commit 2c33819
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ posix.extname = function(path) {
posix.format = function(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new TypeError(
"Parameter 'pathObject' must be an object, not " + typeof pathObject
'Parameter "pathObject" must be an object, not ' + typeof pathObject
);
}

Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ function testBlockTypeError(method, block) {
method(block);
threw = false;
} catch (e) {
assert.equal(e.toString(), 'TypeError: block must be a function');
assert.equal(e.toString(),
'TypeError: "block" argument must be a function');
}

assert.ok(threw);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1222,11 +1222,11 @@ assert.throws(function() {

assert.throws(function() {
new Buffer();
}, /must start with number, buffer, array or string/);
}, /Must start with number, buffer, array or string/);

assert.throws(function() {
new Buffer(null);
}, /must start with number, buffer, array or string/);
}, /Must start with number, buffer, array or string/);


// Test prototype getters don't throw
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-spawn-typeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const common = require('../common');
const cmd = common.isWindows ? 'rundll32' : 'ls';
const invalidcmd = 'hopefully_you_dont_have_this_on_your_machine';
const invalidArgsMsg = /Incorrect value of args option/;
const invalidOptionsMsg = /options argument must be an object/;
const invalidOptionsMsg = /"options" argument must be an object/;
const empty = common.fixturesDir + '/empty.js';

assert.throws(function() {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-file-write-stream3.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function run_test_4() {
function() {
file = fs.createWriteStream(filepath, options);
},
/start must be/
/"start" must be/
);

}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ assert.throws(function() {

assert.throws(function() {
fs.access(__filename, fs.F_OK);
}, /callback must be a function/);
}, /"callback" argument must be a function/);

assert.throws(function() {
fs.access(__filename, fs.F_OK, {});
}, /callback must be a function/);
}, /"callback" argument must be a function/);

assert.doesNotThrow(function() {
fs.accessSync(__filename);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-null-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assert');
var fs = require('fs');

function check(async, sync) {
var expected = /Path must be a string without null bytes./;
var expected = /Path must be a string without null bytes/;
var argsSync = Array.prototype.slice.call(arguments, 2);
var argsAsync = argsSync.concat(function(er) {
assert(er && er.message.match(expected));
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-buffer-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stream.on('finish', common.mustCall(function() {
fd = fs.openSync(file, 'r');
fs.read(fd, kStringMaxLength + 1, 0, 'utf8', common.mustCall(function(err) {
assert.ok(err instanceof Error);
assert.strictEqual('toString failed', err.message);
assert.strictEqual('"toString()" failed', err.message);
}));
}));

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-stream-inherit.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ file6.on('end', function() {

assert.throws(function() {
fs.createReadStream(rangeFile, Object.create({start: 10, end: 2}));
}, /start must be <= end/);
}, /"start" option must be <= "end" option/);

var stream = fs.createReadStream(rangeFile, Object.create({ start: 0,
end: 0 }));
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-fs-read-stream-throw-type-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ assert.doesNotThrow(function() {

assert.throws(function() {
fs.createReadStream(example, null);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createReadStream(example, 123);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createReadStream(example, 0);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createReadStream(example, true);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createReadStream(example, false);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
2 changes: 1 addition & 1 deletion test/parallel/test-fs-read-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ file6.on('end', function() {

assert.throws(function() {
fs.createReadStream(rangeFile, {start: 10, end: 2});
}, /start must be <= end/);
}, /"start" option must be <= "end" option/);

var stream = fs.createReadStream(rangeFile, { start: 0, end: 0 });
stream.data = '';
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readfile-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ stream.on('finish', common.mustCall(function() {
// make sure that the toString does not throw an error
fs.readFile(file, 'utf8', common.mustCall(function(err, buf) {
assert.ok(err instanceof Error);
assert.strictEqual('toString failed', err.message);
assert.strictEqual('"toString()" failed', err.message);
}));
}));

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-watchfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const assert = require('assert');
// Basic usage tests.
assert.throws(function() {
fs.watchFile('./some-file');
}, /watchFile requires a listener function/);
}, /"watchFile\(\)" requires a listener function/);

assert.throws(function() {
fs.watchFile('./another-file', {}, 'bad listener');
}, /watchFile requires a listener function/);
}, /"watchFile\(\)" requires a listener function/);

assert.throws(function() {
fs.watchFile(new Object(), function() {});
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-fs-write-stream-throw-type-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ assert.doesNotThrow(function() {

assert.throws(function() {
fs.createWriteStream(example, null);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createWriteStream(example, 123);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createWriteStream(example, 0);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createWriteStream(example, true);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
assert.throws(function() {
fs.createWriteStream(example, false);
}, /options must be a string or an object/);
}, /"options" argument must be a string or an object/);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ assert.throws(function() {
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol "file:" not supported.' +
' Expected "http:".');
' Expected "http:"');
return true;
}
});
Expand All @@ -20,7 +20,7 @@ assert.throws(function() {
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol "mailto:" not supported.' +
' Expected "http:".');
' Expected "http:"');
return true;
}
});
Expand All @@ -30,7 +30,7 @@ assert.throws(function() {
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol "ftp:" not supported.' +
' Expected "http:".');
' Expected "http:"');
return true;
}
});
Expand All @@ -40,7 +40,7 @@ assert.throws(function() {
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol "javascript:" not supported.' +
' Expected "http:".');
' Expected "http:"');
return true;
}
});
Expand All @@ -50,7 +50,7 @@ assert.throws(function() {
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol "xmpp:" not supported.' +
' Expected "http:".');
' Expected "http:"');
return true;
}
});
Expand All @@ -60,7 +60,7 @@ assert.throws(function() {
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol "f:" not supported.' +
' Expected "http:".');
' Expected "http:"');
return true;
}
});
2 changes: 1 addition & 1 deletion test/parallel/test-http-write-head.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var s = http.createServer(function(req, res) {
res.setHeader('foo', undefined);
} catch (e) {
assert.ok(e instanceof Error);
assert.equal(e.message, '`value` required in setHeader("foo", value).');
assert.equal(e.message, '"value" required in setHeader("foo", value)');
threw = true;
}
assert.ok(threw, 'Undefined value should throw');
Expand Down
26 changes: 13 additions & 13 deletions test/parallel/test-net-create-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,55 +38,55 @@ server.listen(tcpPort, 'localhost', function() {

fail({
port: true
}, TypeError, 'port should be a number or string: true');
}, TypeError, '"port" option should be a number or string: true');

fail({
port: false
}, TypeError, 'port should be a number or string: false');
}, TypeError, '"port" option should be a number or string: false');

fail({
port: []
}, TypeError, 'port should be a number or string: ');
}, TypeError, '"port" option should be a number or string: ');

fail({
port: {}
}, TypeError, 'port should be a number or string: [object Object]');
}, TypeError, '"port" option should be a number or string: [object Object]');

fail({
port: null
}, TypeError, 'port should be a number or string: null');
}, TypeError, '"port" option should be a number or string: null');

fail({
port: ''
}, RangeError, 'port should be >= 0 and < 65536: ');
}, RangeError, '"port" option should be >= 0 and < 65536: ');

fail({
port: ' '
}, RangeError, 'port should be >= 0 and < 65536: ');
}, RangeError, '"port" option should be >= 0 and < 65536: ');

fail({
port: '0x'
}, RangeError, 'port should be >= 0 and < 65536: 0x');
}, RangeError, '"port" option should be >= 0 and < 65536: 0x');

fail({
port: '-0x1'
}, RangeError, 'port should be >= 0 and < 65536: -0x1');
}, RangeError, '"port" option should be >= 0 and < 65536: -0x1');

fail({
port: NaN
}, RangeError, 'port should be >= 0 and < 65536: NaN');
}, RangeError, '"port" option should be >= 0 and < 65536: NaN');

fail({
port: Infinity
}, RangeError, 'port should be >= 0 and < 65536: Infinity');
}, RangeError, '"port" option should be >= 0 and < 65536: Infinity');

fail({
port: -1
}, RangeError, 'port should be >= 0 and < 65536: -1');
}, RangeError, '"port" option should be >= 0 and < 65536: -1');

fail({
port: 65536
}, RangeError, 'port should be >= 0 and < 65536: 65536');
}, RangeError, '"port" option should be >= 0 and < 65536: 65536');
});

// Try connecting to random ports, but do so once the server is closed
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-net-listen-port-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ net.Server().listen({ port: '' + common.PORT }, close);
'-Infinity' ].forEach(function(port) {
assert.throws(function() {
net.Server().listen({ port: port }, assert.fail);
}, /port should be >= 0 and < 65536/i);
}, /"port" option should be >= 0 and < 65536/i);
});

[null, true, false].forEach(function(port) {
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ var errors = [
{method: 'parse', input: [],
message: /Path must be a string. Received undefined/},
{method: 'format', input: [null],
message: /Parameter 'pathObject' must be an object, not/},
message: /Parameter "pathObject" must be an object, not/},
{method: 'format', input: [''],
message: /Parameter 'pathObject' must be an object, not string/},
message: /Parameter "pathObject" must be an object, not string/},
{method: 'format', input: [true],
message: /Parameter 'pathObject' must be an object, not boolean/},
message: /Parameter "pathObject" must be an object, not boolean/},
{method: 'format', input: [1],
message: /Parameter 'pathObject' must be an object, not number/},
message: /Parameter "pathObject" must be an object, not number/},
{method: 'format', input: [{root: true}],
message: /'pathObject.root' must be a string or undefined, not boolean/},
message: /"pathObject\.root" must be a string or undefined, not boolean/},
{method: 'format', input: [{root: 12}],
message: /'pathObject.root' must be a string or undefined, not number/},
message: /"pathObject\.root" must be a string or undefined, not number/},
];

checkParseFormat(path.win32, winPaths);
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function isWarned(emitter) {
});
}, function(err) {
if (err instanceof TypeError) {
if (/Argument \'completer\' must be a function/.test(err)) {
if (/Argument "completer" must be a function/.test(err)) {
return true;
}
}
Expand Down Expand Up @@ -380,4 +380,3 @@ function isWarned(emitter) {
});

});

Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const buf = new Buffer(kStringMaxLength + 1);

assert.throws(function() {
buf.toString('ascii');
}, /toString failed/);
}, /"toString\(\)" failed/);
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const buf = new Buffer(kStringMaxLength + 1);

assert.throws(function() {
buf.toString('base64');
}, /toString failed/);
}, /"toString\(\)" failed/);
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const buf = new Buffer(kStringMaxLength + 1);

assert.throws(function() {
buf.toString('binary');
}, /toString failed/);
}, /"toString\(\)" failed/);

var maxString = buf.toString('binary', 1);
assert.equal(maxString.length, kStringMaxLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const buf = new Buffer(kStringMaxLength + 1);

assert.throws(function() {
buf.toString('hex');
}, /toString failed/);
}, /"toString\(\)" failed/);
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const buf = new Buffer(kStringMaxLength + 1);

assert.throws(function() {
buf.toString();
}, /toString failed|Invalid array buffer length/);
}, /"toString\(\)" failed|Invalid array buffer length/);

assert.throws(function() {
buf.toString('utf8');
}, /toString failed/);
}, /"toString\(\)" failed/);
2 changes: 1 addition & 1 deletion test/parallel/test-stringbytes-external-exceed-max.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ const buf0 = new Buffer(kStringMaxLength * 2 + 2);

assert.throws(function() {
buf0.toString('utf16le');
}, /toString failed/);
}, /"toString\(\)" failed/);
Loading

0 comments on commit 2c33819

Please sign in to comment.