diff --git a/shell.js b/shell.js index f41fa32..046856b 100644 --- a/shell.js +++ b/shell.js @@ -584,15 +584,20 @@ function _test(options, path) { if (!canInterpret) error('could not interpret expression'); + if (options.link) { + try { + return fs.lstatSync(path).isSymbolicLink(); + } catch(e) { + return false; + } + } + if (!fs.existsSync(path)) return false; if (options.exists) return true; - if (options.link) - return fs.lstatSync(path).isSymbolicLink(); - var stats = fs.statSync(path); if (options.block) diff --git a/test/resources/badlink b/test/resources/badlink new file mode 120000 index 0000000..e3404fe --- /dev/null +++ b/test/resources/badlink @@ -0,0 +1 @@ +not_existed_file \ No newline at end of file diff --git a/test/test.js b/test/test.js index f5c83b9..a824edb 100644 --- a/test/test.js +++ b/test/test.js @@ -80,4 +80,12 @@ var result = shell.test('-L', 'resources/link'); assert.equal(shell.error(), null); assert.equal(result, true);//true +var result = shell.test('-L', 'resources/badlink'); +assert.equal(shell.error(), null); +assert.equal(result, true);//true + +var result = shell.test('-L', 'resources/404'); +assert.equal(shell.error(), null); +assert.equal(result, false);//false + shell.exit(123);