diff options
author | Luca Maraschi <luca.maraschi@gmail.com> | 2017-03-30 23:06:47 +0200 |
---|---|---|
committer | Michael Dawson <michael_dawson@ca.ibm.com> | 2017-04-03 13:32:19 -0400 |
commit | 53828e8bff277e138447d118c1b0167edd671c52 (patch) | |
tree | 455ada70c4afbf4e4d9172ad24b209fff3a2c6b3 | |
parent | 7eb1b4658ec8c7c4e16ecf8345aea4fccdac3891 (diff) | |
download | android-node-v8-53828e8bff277e138447d118c1b0167edd671c52.tar.gz android-node-v8-53828e8bff277e138447d118c1b0167edd671c52.tar.bz2 android-node-v8-53828e8bff277e138447d118c1b0167edd671c52.zip |
test: extended test to makeCallback cb type check
makeCallback and makeStatsCallback are both tested intedependently.
PR-URL: https://github.com/nodejs/node/pull/12140
Fixes: https://github.com/nodejs/node/issues/12136
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
-rw-r--r-- | test/parallel/test-fs-make-callback.js | 42 | ||||
-rw-r--r-- | test/parallel/test-fs-makeStatsCallback.js | 30 |
2 files changed, 47 insertions, 25 deletions
diff --git a/test/parallel/test-fs-make-callback.js b/test/parallel/test-fs-make-callback.js index aee980f877..8a19e1cc96 100644 --- a/test/parallel/test-fs-make-callback.js +++ b/test/parallel/test-fs-make-callback.js @@ -3,37 +3,29 @@ const common = require('../common'); const assert = require('assert'); const fs = require('fs'); const cbTypeError = /^TypeError: "callback" argument must be a function$/; +const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}]; -function test(cb) { +const { sep } = require('path'); +const warn = 'Calling an asynchronous function without callback is deprecated.'; + +common.refreshTmpDir(); + +function testMakeCallback(cb) { return function() { - // fs.stat() calls makeCallback() on its second argument - fs.stat(__filename, cb); + // fs.mkdtemp() calls makeCallback() on its third argument + fs.mkdtemp(`${common.tmpDir}${sep}`, {}, cb); }; } -// Verify the case where a callback function is provided -assert.doesNotThrow(test(common.noop)); - -process.once('warning', common.mustCall((warning) => { - assert.strictEqual( - warning.message, - 'Calling an asynchronous function without callback is deprecated.' - ); - - invalidArgumentsTests(); -})); +common.expectWarning('DeprecationWarning', warn); // Passing undefined/nothing calls rethrow() internally, which emits a warning -assert.doesNotThrow(test()); +assert.doesNotThrow(testMakeCallback()); -function invalidArgumentsTests() { - assert.throws(test(null), cbTypeError); - assert.throws(test(true), cbTypeError); - assert.throws(test(false), cbTypeError); - assert.throws(test(1), cbTypeError); - assert.throws(test(0), cbTypeError); - assert.throws(test('foo'), cbTypeError); - assert.throws(test(/foo/), cbTypeError); - assert.throws(test([]), cbTypeError); - assert.throws(test({}), cbTypeError); +function invalidCallbackThrowsTests() { + callbackThrowValues.forEach((value) => { + assert.throws(testMakeCallback(value), cbTypeError); + }); } + +invalidCallbackThrowsTests(); diff --git a/test/parallel/test-fs-makeStatsCallback.js b/test/parallel/test-fs-makeStatsCallback.js new file mode 100644 index 0000000000..84a46bb72e --- /dev/null +++ b/test/parallel/test-fs-makeStatsCallback.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const fs = require('fs'); +const cbTypeError = /^TypeError: "callback" argument must be a function$/; +const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}]; +const warn = 'Calling an asynchronous function without callback is deprecated.'; + +function testMakeStatsCallback(cb) { + return function() { + // fs.stat() calls makeStatsCallback() on its second argument + fs.stat(__filename, cb); + }; +} + +common.expectWarning('DeprecationWarning', warn); + +// Verify the case where a callback function is provided +assert.doesNotThrow(testMakeStatsCallback(common.noop)); + +// Passing undefined/nothing calls rethrow() internally, which emits a warning +assert.doesNotThrow(testMakeStatsCallback()); + +function invalidCallbackThrowsTests() { + callbackThrowValues.forEach((value) => { + assert.throws(testMakeStatsCallback(value), cbTypeError); + }); +} + +invalidCallbackThrowsTests(); |