Skip to content

Commit 967c586

Browse files
committed
Test that ENOENT errors are ENOENTS
This is a test that would have caught the regression in stat uid handling, because any call to an async function should not throw, and any call to a sync function in these cases should throw the expected ENOENT error.
1 parent 9ef2148 commit 967c586

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/enoent.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// this test makes sure that various things get enoent, instead of
2+
// some other kind of throw.
3+
4+
var t = require('tap')
5+
var g = require('../')
6+
var file = 'this file does not exist even a little bit'
7+
var methods = [
8+
['open', 'r'],
9+
['readFile'],
10+
['stat'],
11+
['lstat'],
12+
['utimes', new Date(), new Date()],
13+
['readdir']
14+
]
15+
16+
// any version > v6 can do readdir(path, options, cb)
17+
if (process.version.match(/^v([6-9]|[1-9][0-9])\./)) {
18+
methods.push(['readdir', {}])
19+
}
20+
21+
t.plan(methods.length)
22+
methods.forEach(function (method) {
23+
t.test(method[0], runTest(method))
24+
})
25+
26+
function runTest (args) { return function (t) {
27+
var method = args.shift()
28+
args.unshift(file)
29+
var methodSync = method + 'Sync'
30+
t.isa(g[methodSync], 'function')
31+
t.throws(function () {
32+
g[methodSync].apply(g, args)
33+
}, { code: 'ENOENT' })
34+
// add the callback
35+
args.push(verify(t))
36+
t.isa(g[method], 'function')
37+
t.doesNotThrow(function () {
38+
g[method].apply(g, args)
39+
})
40+
}}
41+
42+
function verify (t) { return function (er) {
43+
t.isa(er, Error)
44+
t.equal(er.code, 'ENOENT')
45+
t.end()
46+
}}

0 commit comments

Comments
 (0)