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

assert: fix deepEqual inconsistencies #14491

Closed
wants to merge 2 commits into from

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Jul 26, 2017

Fixes #14441

I moved some tests over to assert-deep as they now always test all variations and it makes more sense to keep the deep-equal tests in there anyway.

Note: the original test added in #13318 was actually faulty.

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
Affected core subsystem(s)

assert

@nodejs-github-bot nodejs-github-bot added the assert Issues and PRs related to the assert subsystem. label Jul 26, 2017
lib/assert.js Outdated
if (memos.actual.has(actual)) {
return memos.actual.get(actual) === memos.expected.get(expected);
// We prevent up to two set.has(x) calls by directly retrieving the value
// and checking for undefined.
Copy link
Member

Choose a reason for hiding this comment

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

What about sets that contain the undefined value?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should say map.has(x) and not set. The only values in the map are numbers as it is a internal value.

Copy link
Member

@targos targos Jul 26, 2017

Choose a reason for hiding this comment

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

Sorry, my question is: what if actual or expected is the undefined value (I'm not sure it can be)? In that case, map.has(actual) is not the same as map.get(actual) !== undefined.

Edit: forget it, I was really confused by this map/set thing...

@Trott
Copy link
Member

Trott commented Jul 27, 2017

@nodejs/testing

@Trott
Copy link
Member

Trott commented Jul 28, 2017

@nodejs/collaborators This could use some reviews.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Can you move the tests in a separate commit to simplifying reviews? Or fire a different PR that moves the tests? I would prefer the latter.

Looking at this PR it is not clear which case is added.

@BridgeAR
Copy link
Member Author

BridgeAR commented Jul 28, 2017

@mcollina I tried to do exactly that. The first commit changes the code and adds the regression tests. The second one moves them. The third one is a fixup for commit 1.

If you still prefer me to open a second PR as follow up, I'll do that.

@@ -303,6 +303,26 @@ assertOnlyDeepEqual(
new Set([undefined])
);

// Circular structures
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a link to the issues that originated this bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@mcollina
Copy link
Member

@BridgeAR one is fine then, but when landing we should keep them separate.

I saw 3 commits vs 2 that I was expecting. Can you squash the last one in the first? (the comment fixup)

@BridgeAR
Copy link
Member Author

@mcollina done

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@XadillaX XadillaX left a comment

Choose a reason for hiding this comment

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

LGTM if CI is green.

@XadillaX
Copy link
Contributor

Copy link
Member

@tniessen tniessen left a comment

Choose a reason for hiding this comment

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

Subsystem of the second commit should be `test´ IMO.

@BridgeAR
Copy link
Member Author

BridgeAR commented Aug 1, 2017

@tniessen you are absolutely correct. Fixed

tniessen pushed a commit to tniessen/node that referenced this pull request Aug 1, 2017
PR-URL: nodejs#14491
Fixes: nodejs#14441
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
tniessen pushed a commit to tniessen/node that referenced this pull request Aug 1, 2017
PR-URL: nodejs#14491
Fixes: nodejs#14441
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
@tniessen
Copy link
Member

tniessen commented Aug 1, 2017

@addaleax
Copy link
Member

addaleax commented Aug 1, 2017

Hi! 😄 Once again, this doesn’t land cleanly on 8.x; if you can, please follow the guide and raise a backport PR.

Fwiw, only the test: commit is making trouble, if necessary we can just skip it.

@BridgeAR
Copy link
Member Author

BridgeAR commented Aug 1, 2017

@addaleax I guess it is not be necessary to backport these as those tests are probably never touched

jasnell pushed a commit that referenced this pull request Sep 20, 2017
PR-URL: #14491
Fixes: #14441
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
@BridgeAR
Copy link
Member Author

@addaleax @jasnell it seems like this patch applies cleanly right now (even the tests). I think it does not make sense to open a PR for that in that case (just going through my PRs with the backporting label).

@addaleax
Copy link
Member

Great – in that case the label can be removed and this should be picked up by the tooling automatically again :)

jasnell pushed a commit that referenced this pull request Sep 25, 2017
PR-URL: #14491
Fixes: #14441
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if no let me know or add the dont-land-on label.

@BridgeAR
Copy link
Member Author

This should not be backported because the issue does not exist in v6.

@BridgeAR BridgeAR deleted the fix-assert-deep-equal branch April 1, 2019 23:37
// We prevent up to two map.has(x) calls by directly retrieving the value
// and checking for undefined. The map can only contain numbers, so it is
// safe to check for undefined only.
const expectedMemoA = memos.actual.get(actual);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @BridgeAR, old PR, I know, but I am trying to understand the implementation in latest master and am confused by this code. Why is this variable called expectedMemoA, if it comes from the actual Map? Shouldn't it be called actualMemo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants