-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: make assertion_error user myers diff algorithm #54862
assert: make assertion_error user myers diff algorithm #54862
Conversation
13b2f65
to
16a54cb
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54862 +/- ##
==========================================
- Coverage 88.41% 88.40% -0.02%
==========================================
Files 652 653 +1
Lines 186889 186952 +63
Branches 36059 36075 +16
==========================================
+ Hits 165239 165272 +33
- Misses 14901 14926 +25
- Partials 6749 6754 +5
|
@nodejs/assert |
16a54cb
to
537b61f
Compare
|
IMO in the assert documentation, the Myers algorithm should be mentioned as the algorithm in use? |
this is not changing what algorithm assert is using, but the algorithm to show the differences when an assertion fails 😄 |
537b61f
to
0494e00
Compare
There is a typo in commit title: user -> use. |
0494e00
to
ddb1cc0
Compare
oops, good catch! fixed 😄 |
nit: Commit |
ddb1cc0
to
3f36065
Compare
@RedYetiDev updated the messages about skipped lines and the commit message |
8a301ae
to
86d1745
Compare
Per https://openjs-foundation.slack.com/archives/C019Y2T6STH/p1726429431411589: Is this a breaking change? It modifies the output of an error, an programs may be relying on that output. |
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.
Are these prototypes needed?
+ one question
86d1745
to
27c553c
Compare
Is there anything left on my side to push this forward? |
Maybe @BridgeAR could be interested in this, considering this comment: #51733 (comment) 😁 |
9899708
to
ca1b5bc
Compare
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
ca1b5bc
to
508d1fe
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.
LGTM
@@ -127,7 +134,7 @@ test('date', () => { | |||
code: 'ERR_ASSERTION', | |||
message: `${defaultMsgStartFull}\n\n` + | |||
'+ 2016-01-01T00:00:00.000Z\n- MyDate 2016-01-01T00:00:00.000Z' + | |||
" {\n- '0': '1'\n- }" | |||
" {\n- '0': '1'\n- }\n" |
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: I've noticed that we now have several changes related to the trailing newline, was this introduced intentionally? 😁
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.
@pmarchini yessir, it is point 5 and it got approved by @BridgeAR as well :)
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.
lgtm
Landed in 4d6d7d6 |
Notable changes: assert: * (SEMVER-MINOR) make `assertion_error` use Myers diff algorithm (Giovanni Bucci) #54862 buffer: * (SEMVER-MINOR) make `Buffer` work with resizable `ArrayBuffer` (James M Snell) #55377 esm: * mark import attributes and JSON module as stable (Nicolò Ribaudo) #55333 lib: * (SEMVER-MINOR) add `UV_UDP_REUSEPORT` for udp (theanarkh) #55403 net: * (SEMVER-MINOR) add `UV_TCP_REUSEPORT` for tcp (theanarkh) #55408 test_runner: * mark `MockTimers` as stable (Erick Wendel) #55398 PR-URL: TODO
Notable changes: assert: * (SEMVER-MINOR) make `assertion_error` use Myers diff algorithm (Giovanni Bucci) #54862 buffer: * (SEMVER-MINOR) make `Buffer` work with resizable `ArrayBuffer` (James M Snell) #55377 esm: * mark import attributes and JSON module as stable (Nicolò Ribaudo) #55333 lib: * (SEMVER-MINOR) add `UV_UDP_REUSEPORT` for udp (theanarkh) #55403 net: * (SEMVER-MINOR) add `UV_TCP_REUSEPORT` for tcp (theanarkh) #55408 test_runner: * mark `MockTimers` as stable (Erick Wendel) #55398 PR-URL: #55513
Notable changes: assert: * (SEMVER-MINOR) make `assertion_error` use Myers diff algorithm (Giovanni Bucci) #54862 buffer: * (SEMVER-MINOR) make `Buffer` work with resizable `ArrayBuffer` (James M Snell) #55377 esm: * mark import attributes and JSON module as stable (Nicolò Ribaudo) #55333 lib: * (SEMVER-MINOR) add `UV_UDP_REUSEPORT` for udp (theanarkh) #55403 net: * (SEMVER-MINOR) add `UV_TCP_REUSEPORT` for tcp (theanarkh) #55408 test_runner: * mark `MockTimers` as stable (Erick Wendel) #55398 PR-URL: #55513
Fixes: nodejs#51733 Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com> PR-URL: nodejs#54862 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Notable changes: assert: * (SEMVER-MINOR) make `assertion_error` use Myers diff algorithm (Giovanni Bucci) nodejs#54862 buffer: * (SEMVER-MINOR) make `Buffer` work with resizable `ArrayBuffer` (James M Snell) nodejs#55377 esm: * mark import attributes and JSON module as stable (Nicolò Ribaudo) nodejs#55333 lib: * (SEMVER-MINOR) add `UV_UDP_REUSEPORT` for udp (theanarkh) nodejs#55403 net: * (SEMVER-MINOR) add `UV_TCP_REUSEPORT` for tcp (theanarkh) nodejs#55408 test_runner: * mark `MockTimers` as stable (Erick Wendel) nodejs#55398 PR-URL: nodejs#55513
Fixes: #51733
Co-Authored-By: Pietro Marchini pietro.marchini94@gmail.com
Why
As discussed in the linked issue, the diff algorithm used to display errors during assertions was a "quick, best-effort implementation." After researching, I found that there aren't many diff algorithms faster than Myers' algorithm, which I’ve implemented in this PR.
How
Following this article on Myers' diff algorithm: https://blog.jcoglan.com/2017/02/12/the-myers-diff-algorithm-part-1/, I implemented the algorithm. Myers' algorithm is relatively simple, based on a matrix of size N * M, where N is the length of the first string and M is the length of the second string. Although it’s primarily used for string comparison, I’ve adapted it here to handle the results of the assert function.
Differences with the old implementation
In addition to changing the diff algorithm, I also updated the way diffs are displayed:
example:
Old implementation:
New implementation:
Another example:
Old implementation:
New implementation:
^
indicator is now only displayed for string diffs when there is sufficient space in the terminal and colors are not supported, otherwise the new Myers algorithm is used for single strings too:example:
Old implementation:
New implementation:
OR