diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-01-28 12:07:18 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-02 19:05:22 +0100 |
commit | 70dcacd7101be14321b8a1c05de75a78b4656704 (patch) | |
tree | f22759f4c906c8a1e5bf328d7ca265c25102bb19 /lib | |
parent | 89dd21a8ad7725b7a495160feed8e642241b1f00 (diff) | |
download | android-node-v8-70dcacd7101be14321b8a1c05de75a78b4656704.tar.gz android-node-v8-70dcacd7101be14321b8a1c05de75a78b4656704.tar.bz2 android-node-v8-70dcacd7101be14321b8a1c05de75a78b4656704.zip |
assert: deprecate assert.fail partially
Using `assert.fail()` with more than one argument is not intuitive
to use and has no benefit over using a message on its own.
Therefore this introduces a runtime deprecation in case it is used
in that way.
PR-URL: https://github.com/nodejs/node/pull/18418
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/assert.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/assert.js b/lib/assert.js index 8c38cfcd7a..75d2473c48 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -52,6 +52,8 @@ const ERR_DIFF_DEACTIVATED = 0; const ERR_DIFF_NOT_EQUAL = 1; const ERR_DIFF_EQUAL = 2; +let warned = false; + // The assert module provides functions that throw // AssertionError's when particular conditions are not met. The // assert module must conform to the following interface. @@ -80,8 +82,18 @@ function fail(actual, expected, message, operator, stackStartFn) { } else if (argsLen === 1) { message = actual; actual = undefined; - } else if (argsLen === 2) { - operator = '!='; + } else { + if (warned === false) { + warned = true; + process.emitWarning( + 'assert.fail() with more than one argument is deprecated. ' + + 'Please use assert.strictEqual() instead or only pass a message.', + 'DeprecationWarning', + 'DEP00XXX' + ); + } + if (argsLen === 2) + operator = '!='; } innerFail({ |