summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorMichaƫl Zasso <targos@protonmail.com>2018-04-12 11:54:19 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-04-26 19:42:55 +0200
commit2fd248f639981c72794efef397dfae5263ebdff5 (patch)
tree1197085154c2f2d1565ffa89099db66f7fc29833 /test/parallel
parente8361287030fbaa773761bb3798d45903bb160f6 (diff)
downloadnode-new-2fd248f639981c72794efef397dfae5263ebdff5.tar.gz
process: migrate methods to throw errors with code
Migrate some methods from node.cc to JS in order to properly throw errors with codes. PR-URL: https://github.com/nodejs/node/pull/19973 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-process-chdir.js15
-rw-r--r--test/parallel/test-process-euid-egid.js19
-rw-r--r--test/parallel/test-process-uid-gid.js17
-rw-r--r--test/parallel/test-process-umask.js (renamed from test/parallel/test-umask.js)17
4 files changed, 45 insertions, 23 deletions
diff --git a/test/parallel/test-process-chdir.js b/test/parallel/test-process-chdir.js
index c0a245ffd3..998147dd43 100644
--- a/test/parallel/test-process-chdir.js
+++ b/test/parallel/test-process-chdir.js
@@ -1,6 +1,6 @@
'use strict';
-require('../common');
+const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
@@ -33,10 +33,9 @@ process.chdir('..');
assert.strictEqual(process.cwd().normalize(),
path.resolve(tmpdir.path).normalize());
-const errMessage = /^TypeError: Bad argument\.$/;
-assert.throws(function() { process.chdir({}); },
- errMessage, 'Bad argument.');
-assert.throws(function() { process.chdir(); },
- errMessage, 'Bad argument.');
-assert.throws(function() { process.chdir('x', 'y'); },
- errMessage, 'Bad argument.');
+const err = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: /The "directory" argument must be of type string/
+};
+common.expectsError(function() { process.chdir({}); }, err);
+common.expectsError(function() { process.chdir(); }, err);
diff --git a/test/parallel/test-process-euid-egid.js b/test/parallel/test-process-euid-egid.js
index adae58abeb..84fbd03e32 100644
--- a/test/parallel/test-process-euid-egid.js
+++ b/test/parallel/test-process-euid-egid.js
@@ -13,11 +13,18 @@ if (common.isWindows) {
assert.throws(() => {
process.seteuid({});
-}, /^TypeError: seteuid argument must be a number or string$/);
+}, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "id" argument must be one of type number or string. ' +
+ 'Received type object'
+});
assert.throws(() => {
- process.seteuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf');
-}, /^Error: seteuid user id does not exist$/);
+ process.seteuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveyb');
+}, {
+ code: 'ERR_UNKNOWN_CREDENTIAL',
+ message: 'User identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
+});
// If we're not running as super user...
if (process.getuid() !== 0) {
@@ -27,11 +34,11 @@ if (process.getuid() !== 0) {
assert.throws(() => {
process.setegid('nobody');
- }, /^Error: (?:EPERM, .+|setegid group id does not exist)$/);
+ }, /(?:EPERM, .+|Group identifier does not exist: nobody)$/);
assert.throws(() => {
process.seteuid('nobody');
- }, /^Error: (?:EPERM, .+|seteuid user id does not exist)$/);
+ }, /^Error: (?:EPERM, .+|User identifier does not exist: nobody)$/);
return;
}
@@ -41,7 +48,7 @@ const oldgid = process.getegid();
try {
process.setegid('nobody');
} catch (err) {
- if (err.message !== 'setegid group id does not exist') {
+ if (err.message !== 'Group identifier does not exist: nobody') {
throw err;
} else {
process.setegid('nogroup');
diff --git a/test/parallel/test-process-uid-gid.js b/test/parallel/test-process-uid-gid.js
index d044c45a32..2475194309 100644
--- a/test/parallel/test-process-uid-gid.js
+++ b/test/parallel/test-process-uid-gid.js
@@ -35,11 +35,18 @@ if (common.isWindows) {
assert.throws(() => {
process.setuid({});
-}, /^TypeError: setuid argument must be a number or a string$/);
+}, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "id" argument must be one of type ' +
+ 'number or string. Received type object'
+});
assert.throws(() => {
- process.setuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf');
-}, /^Error: setuid user id does not exist$/);
+ process.setuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveyb');
+}, {
+ code: 'ERR_UNKNOWN_CREDENTIAL',
+ message: 'User identifier does not exist: fhqwhgadshgnsdhjsdbkhsdabkfabkveyb'
+});
// If we're not running as super user...
if (process.getuid() !== 0) {
@@ -49,12 +56,12 @@ if (process.getuid() !== 0) {
assert.throws(
() => { process.setgid('nobody'); },
- /^Error: (?:EPERM, .+|setgid group id does not exist)$/
+ /(?:EPERM, .+|Group identifier does not exist: nobody)$/
);
assert.throws(
() => { process.setuid('nobody'); },
- /^Error: (?:EPERM, .+|setuid user id does not exist)$/
+ /(?:EPERM, .+|User identifier does not exist: nobody)$/
);
return;
}
diff --git a/test/parallel/test-umask.js b/test/parallel/test-process-umask.js
index 1ac32cb701..869619f191 100644
--- a/test/parallel/test-umask.js
+++ b/test/parallel/test-process-umask.js
@@ -43,8 +43,17 @@ assert.strictEqual(old, process.umask());
assert.throws(() => {
process.umask({});
-}, /argument must be an integer or octal string/);
+}, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ message: 'The "mask" argument must be one of type number, string, or ' +
+ 'undefined. Received type object'
+});
-assert.throws(() => {
- process.umask('123x');
-}, /invalid octal string/);
+['123x', 'abc', '999'].forEach((value) => {
+ assert.throws(() => {
+ process.umask(value);
+ }, {
+ code: 'ERR_INVALID_ARG_VALUE',
+ message: `The argument 'mask' must be an octal string. Received '${value}'`
+ });
+});