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

Comparing uninitialized maps to nil #45

Closed
akyoto opened this issue May 20, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@akyoto
Copy link

commented May 20, 2019

This looks like a bug:

var shouldBeNil map[string]interface{}

if shouldBeNil == nil {
	c.Log("Indeed nil, according to Go")
}

c.Assert(shouldBeNil, qt.Equals, nil)

It generates:

Indeed nil, according to Go

       error:
          values are not equal
        got:
          map[string]interface {}{}
        want:
          nil
@akyoto

This comment has been minimized.

Copy link
Author

commented May 20, 2019

Nevermind, I should have taken a look at qt.IsNil.

However, does this still look like something you'd want to address or is this behaviour "by design"?
If it is, feel free to close.

@frankban

This comment has been minimized.

Copy link
Owner

commented May 20, 2019

Yes it is by design, see [0]. This way it is possible to check that something is actually nil or use IsNil for a less strict check.
[0] https://github.com/frankban/quicktest/blob/master/checker.go#L44

@frankban frankban closed this May 20, 2019

@akyoto

This comment has been minimized.

Copy link
Author

commented May 21, 2019

I see, so that's why both are needed. A strict and a less strict version.
Thank you for the clarification @frankban!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.