From ee7e0c65cb6bd91fc1391a07d85b1afd8b4f96ea Mon Sep 17 00:00:00 2001 From: Omar Crisostomo Date: Thu, 28 Dec 2017 21:57:24 -0600 Subject: [PATCH 1/4] test:parameters of fs read and readsync added test-fs-read-sync-constructor-errors and test-fs-read-constructor-errors tests added to extend the code coverage testing of the project --- .../test-fs-read-parameters-errors.js | 37 +++++++++++++++++++ .../test-fs-read-sync-parameters-errors.js | 34 +++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 test/parallel/test-fs-read-parameters-errors.js create mode 100644 test/parallel/test-fs-read-sync-parameters-errors.js diff --git a/test/parallel/test-fs-read-parameters-errors.js b/test/parallel/test-fs-read-parameters-errors.js new file mode 100644 index 00000000000000..9363ca70b3d035 --- /dev/null +++ b/test/parallel/test-fs-read-parameters-errors.js @@ -0,0 +1,37 @@ +'use strict'; + +const common = require('../common'); +const fixtures = require('../common/fixtures'); +const fs = require('fs'); +const filepath = fixtures.path('x.txt'); +const fd = fs.openSync(filepath, 'r'); +const expected = Buffer.from('xyz\n'); + +[true, null, undefined, () => {}, {}].forEach((value) => { + common.expectsError(() => { + fs.read(value, + Buffer.allocUnsafe(expected.length), + 0, + expected.length, + 0, + common.mustNotCall()); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }); +}); + +common.expectsError(() => { + fs.read(fd, + Buffer.allocUnsafe(expected.length), + -1, + expected.length, + 0, + common.mustNotCall()); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); + +common.expectsError(() => { + fs.read(fd, + Buffer.allocUnsafe(expected.length), + 0, + -1, + 0, + common.mustNotCall()); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); diff --git a/test/parallel/test-fs-read-sync-parameters-errors.js b/test/parallel/test-fs-read-sync-parameters-errors.js new file mode 100644 index 00000000000000..568bde75441388 --- /dev/null +++ b/test/parallel/test-fs-read-sync-parameters-errors.js @@ -0,0 +1,34 @@ +'use strict'; + +const common = require('../common'); +const fixtures = require('../common/fixtures'); +const fs = require('fs'); +const filepath = fixtures.path('x.txt'); +const fd = fs.openSync(filepath, 'r'); +const expected = Buffer.from('xyz\n'); + +[true, null, undefined, () => {}, {}].forEach((value) => { + common.expectsError(() => { + fs.read(value, + Buffer.allocUnsafe(expected.length), + 0, + expected.length, + 0); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }); +}); + +common.expectsError(() => { + fs.readSync(fd, + Buffer.allocUnsafe(expected.length), + -1, + expected.length, + 0); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); + +common.expectsError(() => { + fs.readSync(fd, + Buffer.allocUnsafe(expected.length), + 0, + -1, + 0); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); From 7af27845ea2758e120a733a78f2ea989dd6ad7d3 Mon Sep 17 00:00:00 2001 From: Omar Crisostomo Date: Fri, 29 Dec 2017 09:50:42 -0600 Subject: [PATCH 2/4] test:parameters of fs read and readsync added test-fs-read-sync-constructor-errors and test-fs-read-constructor-errors tests added to extend the code coverage testing of the project --- .../parallel/test-fs-read-parameters-errors.js | 12 ++++++------ .../test-fs-read-sync-parameters-errors.js | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-fs-read-parameters-errors.js b/test/parallel/test-fs-read-parameters-errors.js index 9363ca70b3d035..736fcce7ed1e07 100644 --- a/test/parallel/test-fs-read-parameters-errors.js +++ b/test/parallel/test-fs-read-parameters-errors.js @@ -5,14 +5,14 @@ const fixtures = require('../common/fixtures'); const fs = require('fs'); const filepath = fixtures.path('x.txt'); const fd = fs.openSync(filepath, 'r'); -const expected = Buffer.from('xyz\n'); +const length = 4; [true, null, undefined, () => {}, {}].forEach((value) => { common.expectsError(() => { fs.read(value, - Buffer.allocUnsafe(expected.length), + Buffer.allocUnsafe(length), 0, - expected.length, + length, 0, common.mustNotCall()); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }); @@ -20,16 +20,16 @@ const expected = Buffer.from('xyz\n'); common.expectsError(() => { fs.read(fd, - Buffer.allocUnsafe(expected.length), + Buffer.allocUnsafe(length), -1, - expected.length, + length, 0, common.mustNotCall()); }, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); common.expectsError(() => { fs.read(fd, - Buffer.allocUnsafe(expected.length), + Buffer.allocUnsafe(length), 0, -1, 0, diff --git a/test/parallel/test-fs-read-sync-parameters-errors.js b/test/parallel/test-fs-read-sync-parameters-errors.js index 568bde75441388..eaac90f7491c08 100644 --- a/test/parallel/test-fs-read-sync-parameters-errors.js +++ b/test/parallel/test-fs-read-sync-parameters-errors.js @@ -5,29 +5,29 @@ const fixtures = require('../common/fixtures'); const fs = require('fs'); const filepath = fixtures.path('x.txt'); const fd = fs.openSync(filepath, 'r'); -const expected = Buffer.from('xyz\n'); +const length = 4; [true, null, undefined, () => {}, {}].forEach((value) => { common.expectsError(() => { - fs.read(value, - Buffer.allocUnsafe(expected.length), - 0, - expected.length, - 0); + fs.readSync(value, + Buffer.allocUnsafe(length), + 0, + length, + 0); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }); }); common.expectsError(() => { fs.readSync(fd, - Buffer.allocUnsafe(expected.length), + Buffer.allocUnsafe(length), -1, - expected.length, + length, 0); }, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); common.expectsError(() => { fs.readSync(fd, - Buffer.allocUnsafe(expected.length), + Buffer.allocUnsafe(length), 0, -1, 0); From 14e16608f98dab0cb82273725707ba6a04d24582 Mon Sep 17 00:00:00 2001 From: Omar Crisostomo Date: Fri, 29 Dec 2017 12:28:07 -0600 Subject: [PATCH 3/4] test:parameters of fs read and readsync added test-fs-read-sync-constructor-errors and test-fs-read-constructor-errors tests added to extend the code coverage testing of the project --- test/parallel/test-fs-read-parameters-errors.js | 9 ++++++--- test/parallel/test-fs-read-sync-parameters-errors.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-fs-read-parameters-errors.js b/test/parallel/test-fs-read-parameters-errors.js index 736fcce7ed1e07..8656c9291810a0 100644 --- a/test/parallel/test-fs-read-parameters-errors.js +++ b/test/parallel/test-fs-read-parameters-errors.js @@ -15,7 +15,8 @@ const length = 4; length, 0, common.mustNotCall()); - }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, + message: 'The "fd" argument must be of type integer' }); }); common.expectsError(() => { @@ -25,7 +26,8 @@ common.expectsError(() => { length, 0, common.mustNotCall()); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "offset" is out of range.' }); common.expectsError(() => { fs.read(fd, @@ -34,4 +36,5 @@ common.expectsError(() => { -1, 0, common.mustNotCall()); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "length" is out of range.' }); diff --git a/test/parallel/test-fs-read-sync-parameters-errors.js b/test/parallel/test-fs-read-sync-parameters-errors.js index eaac90f7491c08..20fe5f9b99726c 100644 --- a/test/parallel/test-fs-read-sync-parameters-errors.js +++ b/test/parallel/test-fs-read-sync-parameters-errors.js @@ -14,7 +14,8 @@ const length = 4; 0, length, 0); - }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError }); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, + message: 'The "fd" argument must be of type integer' }); }); common.expectsError(() => { @@ -23,7 +24,8 @@ common.expectsError(() => { -1, length, 0); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "offset" is out of range.' }); common.expectsError(() => { fs.readSync(fd, @@ -31,4 +33,5 @@ common.expectsError(() => { 0, -1, 0); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError }); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "length" is out of range.' }); From f4e9a8705b9ff86aca1379fd6855983ca858bb20 Mon Sep 17 00:00:00 2001 From: omar crisostomo Date: Wed, 17 Jan 2018 12:14:49 -0600 Subject: [PATCH 4/4] update fs read tests cases --- .../test-fs-read-parameters-errors.js | 40 ------------ .../test-fs-read-sync-parameters-errors.js | 37 ----------- test/parallel/test-fs-read-type.js | 63 +++++++++++++++++++ 3 files changed, 63 insertions(+), 77 deletions(-) delete mode 100644 test/parallel/test-fs-read-parameters-errors.js delete mode 100644 test/parallel/test-fs-read-sync-parameters-errors.js diff --git a/test/parallel/test-fs-read-parameters-errors.js b/test/parallel/test-fs-read-parameters-errors.js deleted file mode 100644 index 8656c9291810a0..00000000000000 --- a/test/parallel/test-fs-read-parameters-errors.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -const common = require('../common'); -const fixtures = require('../common/fixtures'); -const fs = require('fs'); -const filepath = fixtures.path('x.txt'); -const fd = fs.openSync(filepath, 'r'); -const length = 4; - -[true, null, undefined, () => {}, {}].forEach((value) => { - common.expectsError(() => { - fs.read(value, - Buffer.allocUnsafe(length), - 0, - length, - 0, - common.mustNotCall()); - }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fd" argument must be of type integer' }); -}); - -common.expectsError(() => { - fs.read(fd, - Buffer.allocUnsafe(length), - -1, - length, - 0, - common.mustNotCall()); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, - message: 'The value of "offset" is out of range.' }); - -common.expectsError(() => { - fs.read(fd, - Buffer.allocUnsafe(length), - 0, - -1, - 0, - common.mustNotCall()); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, - message: 'The value of "length" is out of range.' }); diff --git a/test/parallel/test-fs-read-sync-parameters-errors.js b/test/parallel/test-fs-read-sync-parameters-errors.js deleted file mode 100644 index 20fe5f9b99726c..00000000000000 --- a/test/parallel/test-fs-read-sync-parameters-errors.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -const common = require('../common'); -const fixtures = require('../common/fixtures'); -const fs = require('fs'); -const filepath = fixtures.path('x.txt'); -const fd = fs.openSync(filepath, 'r'); -const length = 4; - -[true, null, undefined, () => {}, {}].forEach((value) => { - common.expectsError(() => { - fs.readSync(value, - Buffer.allocUnsafe(length), - 0, - length, - 0); - }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, - message: 'The "fd" argument must be of type integer' }); -}); - -common.expectsError(() => { - fs.readSync(fd, - Buffer.allocUnsafe(length), - -1, - length, - 0); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, - message: 'The value of "offset" is out of range.' }); - -common.expectsError(() => { - fs.readSync(fd, - Buffer.allocUnsafe(length), - 0, - -1, - 0); -}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, - message: 'The value of "length" is out of range.' }); diff --git a/test/parallel/test-fs-read-type.js b/test/parallel/test-fs-read-type.js index cbbfe4824c1a0e..3338410bec5282 100644 --- a/test/parallel/test-fs-read-type.js +++ b/test/parallel/test-fs-read-type.js @@ -7,6 +7,7 @@ const filepath = fixtures.path('x.txt'); const fd = fs.openSync(filepath, 'r'); const expected = 'xyz\n'; + // Error must be thrown with string common.expectsError( () => fs.read(fd, expected.length, 0, 'utf-8', common.mustNotCall()), @@ -17,6 +18,39 @@ common.expectsError( } ); +[true, null, undefined, () => {}, {}].forEach((value) => { + common.expectsError(() => { + fs.read(value, + Buffer.allocUnsafe(expected.length), + 0, + expected.length, + 0, + common.mustNotCall()); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, + message: 'The "fd" argument must be of type integer' }); +}); + +common.expectsError(() => { + fs.read(fd, + Buffer.allocUnsafe(expected.length), + -1, + expected.length, + 0, + common.mustNotCall()); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "offset" is out of range.' }); + +common.expectsError(() => { + fs.read(fd, + Buffer.allocUnsafe(expected.length), + 0, + -1, + 0, + common.mustNotCall()); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "length" is out of range.' }); + + common.expectsError( () => fs.readSync(fd, expected.length, 0, 'utf-8'), { @@ -25,3 +59,32 @@ common.expectsError( message: 'The "buffer" argument must be one of type Buffer or Uint8Array' } ); + +[true, null, undefined, () => {}, {}].forEach((value) => { + common.expectsError(() => { + fs.readSync(value, + Buffer.allocUnsafe(expected.length), + 0, + expected.length, + 0); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, + message: 'The "fd" argument must be of type integer' }); +}); + +common.expectsError(() => { + fs.readSync(fd, + Buffer.allocUnsafe(expected.length), + -1, + expected.length, + 0); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "offset" is out of range.' }); + +common.expectsError(() => { + fs.readSync(fd, + Buffer.allocUnsafe(expected.length), + 0, + -1, + 0); +}, { code: 'ERR_OUT_OF_RANGE', type: RangeError, + message: 'The value of "length" is out of range.' });