Commit Graph

9 Commits

Author SHA1 Message Date
Giovanni Bucci
4d6d7d644b
assert: make assertion_error use Myers diff algorithm
Fixes: https://github.com/nodejs/node/issues/51733

Co-Authored-By: Pietro Marchini <pietro.marchini94@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/54862
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2024-10-17 16:02:54 +00:00
Ruben Bridgewater
0f6fed4f07
test: stricter assert color test
Make sure the assertion is actually triggered by using
`assert.throws()` instead of `try/catch`.

PR-URL: https://github.com/nodejs/node/pull/31429
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-02-09 13:39:55 +01:00
Ruben Bridgewater
81496567e7 assert: print more lines in the error diff
So far consequitive identical lines were collapsed if there were at
least three. Now they are only collapsed from five identical lines on.

This also simplifies the implementation a tiny bit by abstracting some
logic.

PR-URL: https://github.com/nodejs/node/pull/28058
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-06-12 19:50:03 -07:00
Ruben Bridgewater
7f2d2cdc0c
test: always activate colors if necessary
PR-URL: https://github.com/nodejs/node/pull/26264
Refs: https://github.com/nodejs/node/pull/26261
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-03-03 23:31:43 +01:00
Ruben Bridgewater
b8a8eedf32
assert: switch inputs to values
The wording seems clearer when using `values` instead of `inputs`.

PR-URL: https://github.com/nodejs/node/pull/23056
Refs: https://github.com/nodejs/node/issues/22763
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2018-09-27 13:25:18 +02:00
Ruben Bridgewater
0518b9edf3
assert: multiple improvements
1) Switched + / - and red / green in diffs. It seems like that style
   is more natural to most people.

2) Short primitives do not use the diff anymore. Especially short
   numbers can be read well like 1 !== 2. Cases that can not be
   displayed like that (e.g., -0 and +0) use the regular diff output.

3) Improved error descriptions. It was not always clear what the
   messages stood for. That should now be resolved.

4) Added a position indicator for single lines in case a tty is used
   and the line is shorter than the visual columns.

5) Color detection is now done by checking stderr instead of stdout.

PR-URL: https://github.com/nodejs/node/pull/21628
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
2018-08-04 10:04:32 +02:00
Ruben Bridgewater
8a0fb137d8
assert: make skipping indicator blue
If lines gets skipped, they are marked with three dots. This makes
sure they are better visualized to distinguish them from everything
else.

PR-URL: https://github.com/nodejs/node/pull/20315
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2018-04-29 17:05:51 +02:00
Ruben Bridgewater
bfe54df812 assert: improve default error messages
This improves the error messages for:
- assert.notDeepStrictEqual
- assert.deepStrictEqual
- assert.notStrictEqual
- assert.strictEqual

Those will now always use the same error message as used in the
strict mode.

PR-URL: https://github.com/nodejs/node/pull/19467
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-14 10:43:43 -07:00
Ruben Bridgewater
2e6dd93aaa
assert: fix diff color output
The color output was broken at some point and that was not detected
because it was not tested for properly so far. This makes sure the
colors work again and it adds a regression test as well.

PR-URL: https://github.com/nodejs/node/pull/19464
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-03-27 01:20:19 +01:00