diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-11-27 13:08:05 +0900 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2017-12-28 03:08:25 +0800 |
commit | 6ca10de9468ed027f5e0b45f721d441df5972bc9 (patch) | |
tree | 52cafdbc2d1fb85f1267ec733d88cc31eac4fa73 /test | |
parent | c56972779b8c239a48df46b7caadf1ef1b9eacd2 (diff) | |
download | android-node-v8-6ca10de9468ed027f5e0b45f721d441df5972bc9.tar.gz android-node-v8-6ca10de9468ed027f5e0b45f721d441df5972bc9.tar.bz2 android-node-v8-6ca10de9468ed027f5e0b45f721d441df5972bc9.zip |
fs: simplify the error context collection in C++
- Simplify the SyncCall template function, only collect error
number and syscall in the C++ layer and collect the rest of context
in JS for flexibility.
- Remove the stringFromPath JS helper now that the unprefixed path is
directly put into the context before the binding is invoked with the
prefixed path.
- Validate more properties in fs.access tests.
PR-URL: https://github.com/nodejs/node/pull/17338
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-fs-access.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js index 719e1108fe..9811f93408 100644 --- a/test/parallel/test-fs-access.js +++ b/test/parallel/test-fs-access.js @@ -1,8 +1,14 @@ 'use strict'; + +// This tests that fs.access and fs.accessSync works as expected +// and the errors thrown from these APIs include the desired properties + const common = require('../common'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); +const uv = process.binding('uv'); + const doesNotExist = path.join(common.tmpDir, '__this_should_not_exist'); const readOnlyFile = path.join(common.tmpDir, 'read_only_file'); const readWriteFile = path.join(common.tmpDir, 'read_write_file'); @@ -130,6 +136,24 @@ assert.throws( `ENOENT: no such file or directory, access '${doesNotExist}'` ); assert.strictEqual(err.constructor, Error); + assert.strictEqual(err.syscall, 'access'); + assert.strictEqual(err.errno, uv.UV_ENOENT); + return true; + } +); + +assert.throws( + () => { fs.accessSync(Buffer.from(doesNotExist)); }, + (err) => { + assert.strictEqual(err.code, 'ENOENT'); + assert.strictEqual(err.path, doesNotExist); + assert.strictEqual( + err.message, + `ENOENT: no such file or directory, access '${doesNotExist}'` + ); + assert.strictEqual(err.constructor, Error); + assert.strictEqual(err.syscall, 'access'); + assert.strictEqual(err.errno, uv.UV_ENOENT); return true; } ); |