-
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
test: use common.fail() instead of assert(false) #10899
Conversation
@@ -10,8 +10,7 @@ let disconnect_count = 0; | |||
const c = net.createConnection(common.PORT); | |||
|
|||
c.on('connect', function() { | |||
console.error('CLIENT connected'); | |||
assert.ok(false); | |||
common.fail('client should not have connected'); |
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.
Nit: any reason for not using c.on('connect', common.fail);
?
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.
common.fail()
expects a message for the first argument. If you do c.on('connect', common.fail);
, you end up with AssertionError: null undefined null
which is not nearly as useful as AssertionError: client should not have connected
.
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.
Yeah, but there are other cases where this is already done, for example https://github.com/nodejs/node/pull/10899/files#diff-74c7cfcd74dc6766c9877fac9daf0721R19.
I'm also not a fan of using common.fail()
when the argument is not a string for example when it used as a 'request'
listener or similar as you end up with AssertionError: [object Object]
.
PR-URL: nodejs#10899 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: #10899 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#10899 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: nodejs#10899 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This will need backport PRs to land on v6 or v4 |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test