Skip to content
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

util: assert: fix deepStrictEqual comparing a real array and fake array #30743

Closed
wants to merge 1 commit into from

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Dec 1, 2019

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

(following in the tradition of #29029)

@ljharb ljharb added the util Issues and PRs related to the built-in util module. label Dec 1, 2019
@Trott
Copy link
Member

Trott commented Dec 1, 2019

@nodejs/assert

ljharb added a commit to inspect-js/node-deep-equal that referenced this pull request Dec 1, 2019
@devsnek devsnek removed their request for review December 1, 2019 05:08
ljharb added a commit to inspect-js/node-deep-equal that referenced this pull request Dec 1, 2019
@ljharb ljharb requested a review from addaleax December 1, 2019 05:59
ljharb added a commit to inspect-js/node-deep-equal that referenced this pull request Dec 1, 2019
ljharb added a commit to inspect-js/node-deep-equal that referenced this pull request Dec 1, 2019
@@ -1064,7 +1079,7 @@ assert.throws(
Object.defineProperty(a, 'length', {
value: 2
});
assert.notDeepStrictEqual(a, [1, 1]);
assertOnlyDeepEqual(a, [1, 1]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the failing test, because it tries the arguments in reverse order

@@ -1050,6 +1050,21 @@ assert.throws(
assert.deepStrictEqual(a, b);
}

// Verify that an array and the equivalent fake array object
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test was previously passing, but it felt like a good addition anyways.

@Trott
Copy link
Member

Trott commented Dec 1, 2019

Does this require an update to the documented deepStrictEqual() algorithm in our documentation? https://github.com/nodejs/node/blob/d25db11312e9ef4392042380b812359fad103707/doc/api/assert.md#comparison-details-1

@codecov-io
Copy link

codecov-io commented Dec 2, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@d7b8ae7). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #30743   +/-   ##
=========================================
  Coverage          ?   97.36%           
=========================================
  Files             ?      187           
  Lines             ?    62171           
  Branches          ?        0           
=========================================
  Hits              ?    60532           
  Misses            ?     1639           
  Partials          ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7b8ae7...66a3dc4. Read the comment docs.

@ljharb
Copy link
Member Author

ljharb commented Dec 2, 2019

@Trott all this change does is makes sure that what already works for (a, b) also works for (b, a); i don't believe any part of that documentation needs to change.

@BridgeAR
Copy link
Member

BridgeAR commented Dec 2, 2019

I originally decided against doing full two sides checks because it's a very rare edge case and we can not check both sides for all types (we could do that for built-in types but that would be a lot of overhead).

I am fine to implement this at least for the currently used one sided type checks. That way it's always consistent, no matter what argument is first.

It would be good to keep the performance overhead in mind though. Especially the typed array type check is relatively expensive.

@ljharb I went ahead and opened #30764 as alternative to this one as it addresses all open one sides versions with the least overhead possible.

BridgeAR added a commit that referenced this pull request Dec 6, 2019
This veryfies that both input arguments are always of the identical
type. It was possible to miss a few cases before. This change applies
to all deep equal assert functions (e.g., `assert.deepStrictEqual()`)
and to `util.isDeepStrictEqual()`.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BridgeAR added a commit that referenced this pull request Dec 6, 2019
This makes sure the assertion does not depend on the argument order.
It also removes comments that do not apply anymore and verifies the
behavior for the loose and strict implementation.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@ljharb
Copy link
Member Author

ljharb commented Dec 7, 2019

Now that #30764 has landed, I'll update or close this PR soon, based on if there's anything of value left in it.

@ljharb
Copy link
Member Author

ljharb commented Dec 8, 2019

I updated the PR; there's just a single test case left. Feel free to land or close.

@ljharb ljharb added the test Issues and PRs related to the tests. label Dec 8, 2019
@nodejs-github-bot
Copy link
Collaborator

targos pushed a commit that referenced this pull request Dec 9, 2019
This veryfies that both input arguments are always of the identical
type. It was possible to miss a few cases before. This change applies
to all deep equal assert functions (e.g., `assert.deepStrictEqual()`)
and to `util.isDeepStrictEqual()`.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Dec 9, 2019
This makes sure the assertion does not depend on the argument order.
It also removes comments that do not apply anymore and verifies the
behavior for the loose and strict implementation.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@bmeck bmeck added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 11, 2019
bmeck pushed a commit that referenced this pull request Dec 11, 2019
PR-URL: #30743
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@bmeck
Copy link
Member

bmeck commented Dec 11, 2019

Landed in 916cc82

@bmeck bmeck closed this Dec 11, 2019
@ljharb ljharb deleted the deep_equal_arg_order branch December 11, 2019 23:06
MylesBorins pushed a commit that referenced this pull request Dec 13, 2019
PR-URL: #30743
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@MylesBorins MylesBorins mentioned this pull request Dec 13, 2019
targos pushed a commit that referenced this pull request Jan 14, 2020
PR-URL: #30743
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
targos pushed a commit that referenced this pull request Jan 14, 2020
This veryfies that both input arguments are always of the identical
type. It was possible to miss a few cases before. This change applies
to all deep equal assert functions (e.g., `assert.deepStrictEqual()`)
and to `util.isDeepStrictEqual()`.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Jan 14, 2020
This makes sure the assertion does not depend on the argument order.
It also removes comments that do not apply anymore and verifies the
behavior for the loose and strict implementation.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
PR-URL: #30743
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
This veryfies that both input arguments are always of the identical
type. It was possible to miss a few cases before. This change applies
to all deep equal assert functions (e.g., `assert.deepStrictEqual()`)
and to `util.isDeepStrictEqual()`.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
This makes sure the assertion does not depend on the argument order.
It also removes comments that do not apply anymore and verifies the
behavior for the loose and strict implementation.

PR-URL: #30764
Refs: #30743
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. test Issues and PRs related to the tests. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants