-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert.fail() accept a single argument or two arguments #12293
Conversation
Isn't this |
I won't argue if someone thinks it's major. But to answer the question from my view: I think it's minor because using the current API with only one or two arguments will provide a message that I would describe as broken.
It's hard for me to imagine a situation where the current behavior is desirable or expected. |
A typo in the message of the first commit:
|
Code in the wild got used to it (maybe someone tests the exception text or whatever other silly things people do), I agree you only change the message, but it's not a "Bug Fix" per se. "not an actual bug fix" ⚖ "change only in message text" Although I'm an anarchist at heart, and am pro change, I would vote major Anyway this discussion is kinda mute since |
The plan with that was to call it |
Nodate isn't that a verb? Not that Nodge is unambiguous (darn it Ryan. And Douglas 😩) |
Yay, I just learned how to retrigger just |
For what it's worth:
|
@aqrln Typo in commit message fixed. Thanks! |
if (arguments.length === 1) | ||
message = actual; | ||
if (arguments.length === 2) | ||
operator = '!='; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just write message = actual, operator = '!=', stackStartFunction = undefined
as part of the function arguments, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are at least three issues with that.
First, that introduces additional behavior changes I was hoping to avoid.
Current behavior preserved in this PR:
> assert.fail()
AssertionError: undefined undefined undefined
With the default parameters change:
> assert.fail()
AssertionError: undefined != undefined
Second, it breaks the two-argument feature added here.
Current PR:
> assert.fail('first', 'second');
AssertionError: 'first' != 'second'
With the suggested change:
> assert.fail('first', 'second')
AssertionError: first
Third, and most importantly, it breaks one of the two current usable argument combinations for the function.
Current behavior also preserved in this PR:
> assert.fail('first', 'second', undefined, 'operator')
AssertionError: 'first' operator 'second'
With the default parameters as suggested replacing the arguments.length
checks:
> assert.fail('first', 'second', undefined, 'operator')
AssertionError: first
There's no doubt a way around this, and maybe the problem is my lack of familiarity with default parameters?
test/parallel/test-assert-fail.js
Outdated
|
||
// no third arg (but a fourth arg) | ||
assert.throws( | ||
assert.fail.bind(assert, 'first', 'second', undefined, 'operator'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d personally prefer arrow functions over .bind
for all of these… no strong opinion, though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion either so I'll change it to arrow functions. :-D
assert.fail() has two possible function signatures, both of which are not intuitive. It virtually guarantees that people who try to use assert.fail() without carefully reading the docs will end up using it incorrectly. This change maintains backwards compatibility with the two valid uses (arguments 1 2 and 4 supplied but argument 3 falsy, and argument 3 supplied but arguments 1 2 and 4 all falsy) but also adds the far more intuitive first-argument-only and first-two-arguments-only possibilities. assert.fail('boom'); // AssertionError: boom assert.fail('a', 'b'); // AssertionError: 'a' != 'b'
assert.fail() has been updated to accept a single argument so that is no longer an error. Remove lint rule that checks for assert.fail() with a single argument.
I think yes, it touched ~50 test files, if we don't backport it we'll get conflicts soon (or already?) when backporting tests. |
Gave a quick look, its got lots of conflicts, so will need some backport TLC if we agree we want it. |
I am also +1 for backporting. Out of my perspective this use case is the only suitable one for assert.fail() and it is actually weird that it used to use more arguments than one. |
Backport #15479 |
assert.fail() has two possible function signatures, both of which are not intuitive. It virtually guarantees that people who try to use assert.fail() without carefully reading the docs will end up using it incorrectly. This change maintains backwards compatibility with the two valid uses (arguments 1 2 and 4 supplied but argument 3 falsy, and argument 3 supplied but arguments 1 2 and 4 all falsy) but also adds the far more intuitive first-argument-only and first-two-arguments-only possibilities. assert.fail('boom'); // AssertionError: boom assert.fail('a', 'b'); // AssertionError: 'a' != 'b' PR-URL: nodejs#12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
assert.fail() has been updated to accept a single argument so that is no longer an error. Remove lint rule that checks for assert.fail() with a single argument. PR-URL: nodejs#12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
common.fail() was added to paste over issues with assert.fail() function signature. assert.fail() has been updated to accept a single argument so common.fail() is no longer necessary. PR-URL: nodejs#12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
assert.fail() has two possible function signatures, both of which are not intuitive. It virtually guarantees that people who try to use assert.fail() without carefully reading the docs will end up using it incorrectly. This change maintains backwards compatibility with the two valid uses (arguments 1 2 and 4 supplied but argument 3 falsy, and argument 3 supplied but arguments 1 2 and 4 all falsy) but also adds the far more intuitive first-argument-only and first-two-arguments-only possibilities. assert.fail('boom'); // AssertionError: boom assert.fail('a', 'b'); // AssertionError: 'a' != 'b' Backport-PR-URL: #15479 PR-URL: #12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
assert.fail() has been updated to accept a single argument so that is no longer an error. Remove lint rule that checks for assert.fail() with a single argument. Backport-PR-URL: #15479 PR-URL: #12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
common.fail() was added to paste over issues with assert.fail() function signature. assert.fail() has been updated to accept a single argument so common.fail() is no longer necessary. Backport-PR-URL: #15479 PR-URL: #12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
assert.fail() has two possible function signatures, both of which are not intuitive. It virtually guarantees that people who try to use assert.fail() without carefully reading the docs will end up using it incorrectly. This change maintains backwards compatibility with the two valid uses (arguments 1 2 and 4 supplied but argument 3 falsy, and argument 3 supplied but arguments 1 2 and 4 all falsy) but also adds the far more intuitive first-argument-only and first-two-arguments-only possibilities. assert.fail('boom'); // AssertionError: boom assert.fail('a', 'b'); // AssertionError: 'a' != 'b' Backport-PR-URL: #15479 PR-URL: #12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
assert.fail() has been updated to accept a single argument so that is no longer an error. Remove lint rule that checks for assert.fail() with a single argument. Backport-PR-URL: #15479 PR-URL: #12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
common.fail() was added to paste over issues with assert.fail() function signature. assert.fail() has been updated to accept a single argument so common.fail() is no longer necessary. Backport-PR-URL: #15479 PR-URL: #12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Notable Changes: * assert: - assert.fail() can now take one or two arguments (Rich Trott) #12293 * crypto: - add sign/verify support for RSASSA-PSS (Tobias Nießen) #11705 * deps: - upgrade openssl sources to 1.0.2m (Shigeki Ohtsu) #16691 - upgrade libuv to 1.15.0 (cjihrig) #15745 - upgrade libuv to 1.14.1 (cjihrig) #14866 - upgrade libuv to 1.13.1 (cjihrig) #14117 - upgrade libuv to 1.12.0 (cjihrig) #13306 * fs: - Add support for fs.write/fs.writeSync(fd, buffer, cb) and fs.write/fs.writeSync(fd, buffer, offset, cb) as documented (Andreas Lind) #7856 * inspector: - enable --inspect-brk (Refael Ackermann) #12615 * process: - add --redirect-warnings command line argument (James M Snell) #10116 * src: - allow CLI args in env with NODE_OPTIONS (Sam Roberts) #12028) - --abort-on-uncaught-exception in NODE_OPTIONS (Sam Roberts) #13932 - allow --tls-cipher-list in NODE_OPTIONS (Sam Roberts) #13172 - use SafeGetenv() for NODE_REDIRECT_WARNINGS (Sam Roberts) #12677 * test: - remove common.fail() (Rich Trott) #12293 PR-URL: #16263
Notable Changes: * assert: - assert.fail() can now take one or two arguments (Rich Trott) #12293 * crypto: - add sign/verify support for RSASSA-PSS (Tobias Nießen) #11705 * deps: - upgrade openssl sources to 1.0.2m (Shigeki Ohtsu) #16691 - upgrade libuv to 1.15.0 (cjihrig) #15745 - upgrade libuv to 1.14.1 (cjihrig) #14866 - upgrade libuv to 1.13.1 (cjihrig) #14117 - upgrade libuv to 1.12.0 (cjihrig) #13306 * fs: - Add support for fs.write/fs.writeSync(fd, buffer, cb) and fs.write/fs.writeSync(fd, buffer, offset, cb) as documented (Andreas Lind) #7856 * inspector: - enable --inspect-brk (Refael Ackermann) #12615 * process: - add --redirect-warnings command line argument (James M Snell) #10116 * src: - allow CLI args in env with NODE_OPTIONS (Sam Roberts) #12028) - --abort-on-uncaught-exception in NODE_OPTIONS (Sam Roberts) #13932 - allow --tls-cipher-list in NODE_OPTIONS (Sam Roberts) #13172 - use SafeGetenv() for NODE_REDIRECT_WARNINGS (Sam Roberts) #12677 * test: - remove common.fail() (Rich Trott) #12293 PR-URL: #16263
First commit:
Second commit: Remove lint rule that flags use of assert.fail() with a single argument.
Third commit: Remove common.fail() in tests since assert.fail() with a single argument works as expected.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)