-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: fix internal logic judgment #27743
Conversation
review wanted. |
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.
The code change does not seem right to me. All added test cases work identical as before with this patch besides the last one which should ideally print 'Failed'
which it currently does.
The documentation could use an update though. My plane is about to take off so I'll review that later.
cde5202
to
dfe1904
Compare
Hello @zero1five, and thank you for the contribution! |
@zero1five |
dfe1904
to
9553caf
Compare
@BridgeAR Thank you very much for your review! I made some changes, can you please review it? |
7cb6eb0
to
f8314d6
Compare
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.
Thanks for sticking to it! I left a few more comments.
f8314d6
to
7994c95
Compare
Fix the logic judgment of assert.fail and add doc and the test cases for the performance of assert.fail on multiple parameter.
5534055
to
b87a772
Compare
@zero1five sorry that it took a while to look at this again. Some times it's difficult to keep an overview over all the PRs. This needs a rebase but I think this should otherwise be good to go. @Trott would you please take another look at the docs? |
doc/api/assert.md
Outdated
given, the default message `Failed` will be used. | ||
`expected` separated by the provided `operator`. If `operator` is falsy and no | ||
message is set, it'll default to `'!='`. If `message` is truthy the `operator` | ||
will default to `'fail'` and `message` will be used as error message. Other |
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.
will default to `'fail'` and `message` will be used as error message. Other | |
will default to `'fail'` and `message` will be used for the error message. Other |
I left some suggestions but they're all nits, This can land without them,. |
actual: undefined, | ||
expected: undefined, | ||
generatedMessage: true | ||
}); |
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.
This test currently passes without the other changes in this PR. Can we please add a test case that currently fails?
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.
Needs a test case that fails on current master branch.
We should probably come up with a more detailed commit message to use while landing. (@BridgeAR: Any thoughts on that?)
@zero1five, there are few review comments and this needs a rebase. |
} | ||
|
||
if (message instanceof Error) throw message; | ||
|
||
if (operator === undefined) { | ||
if (message) { |
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.
if (message) { | |
if (message != null) { |
assert.fail(undefined); | ||
}, { | ||
code: 'ERR_ASSERTION', | ||
name: 'AssertionError', | ||
message: 'Failed', | ||
operator: 'fail', | ||
actual: undefined, | ||
expected: undefined, |
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.
assert.fail(undefined); | |
}, { | |
code: 'ERR_ASSERTION', | |
name: 'AssertionError', | |
message: 'Failed', | |
operator: 'fail', | |
actual: undefined, | |
expected: undefined, | |
assert.fail(1, 2, undefined, undefined); | |
}, { | |
code: 'ERR_ASSERTION', | |
name: 'AssertionError', | |
message: '1 != 2', | |
operator: '!=', | |
actual: 1, | |
expected: 2, |
Ideally, another identical test could be added that sets message
to null
.
`expected` separated by the provided `operator`. If `operator` is falsy and no | ||
message is set, it will default to `'!='`. If `message` is truthy, the `operator` | ||
will default to `'fail'` and `message` will be used for the error message. Other | ||
arguments will be stored as properties on the thrown object. If `stackStartFn` | ||
is provided, all stack frames above that function will be removed from | ||
stacktrace (see [`Error.captureStackTrace`][]). |
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 suggest to change the operator
description above to explain when it's set to 'fail'
and when to '!='
.
I would also move the stackStartFn
description to the part above. That way the total description below concentrates on the general behavior instead of describing each individual option setting.
Right now we also miss to document that assert.fail(1, 2, new Error()
throws the passed through error. That could be described in the message
property above.
The comments should be addressed before this lands.
8ae28ff
to
2935f72
Compare
This would need a rebase in order to move forward |
Fix the logic judgment of assert.fail and add doc
and the test cases for the performance of assert.fail
on multiple parameter.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes