test: improve test-fs-open-flags
* use arrow funcion instead of function expression * add second argument to method assert.throws * check error messages from beginning to the end using ^ and $ PR-URL: nodejs#10908 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
ff75e21662
commit
a024104eec
@ -37,20 +37,27 @@ assert.strictEqual(stringToFlags('xa+'), O_APPEND | O_CREAT | O_RDWR | O_EXCL);
|
|||||||
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
|
('+ +a +r +w rw wa war raw r++ a++ w++ x +x x+ rx rx+ wxx wax xwx xxx')
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.forEach(function(flags) {
|
.forEach(function(flags) {
|
||||||
assert.throws(function() { stringToFlags(flags); });
|
assert.throws(
|
||||||
|
() => stringToFlags(flags),
|
||||||
|
new RegExp(`^Error: Unknown file open flag: ${escapeRegExp(flags)}`)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => stringToFlags({}),
|
() => stringToFlags({}),
|
||||||
/Unknown file open flag: \[object Object\]/
|
/^Error: Unknown file open flag: \[object Object\]$/
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => stringToFlags(true),
|
() => stringToFlags(true),
|
||||||
/Unknown file open flag: true/
|
/^Error: Unknown file open flag: true$/
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => stringToFlags(null),
|
() => stringToFlags(null),
|
||||||
/Unknown file open flag: null/
|
/^Error: Unknown file open flag: null$/
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function escapeRegExp(string) {
|
||||||
|
return string.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user