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

Hook Eq up to scalactic/scalatest's equality #522

Merged
merged 4 commits into from
Sep 15, 2015

Conversation

ceedubs
Copy link
Contributor

@ceedubs ceedubs commented Sep 10, 2015

Fixes #219

This allows us to use matchers like should ===. I changed a few
random places to do this, but I didn't want to go through the effort
of changing tons of places until this PR was reviewed/merged.

I think we could clean a lot of things up now by having CatsSuite
extend GeneratorDrivenPropertyChecks, which will allow using matchers
like should === inside of forAll properties.

Fixes typelevel#219

This allows us to use matchers like `should ===`. I changed a few
random places to do this, but I didn't want to go through the effort
of changing tons of places until this PR was reviewed/merged.

I think we could clean a lot of things up now by having CatsSuite
extend GeneratorDrivenPropertyChecks, which will allow using matchers
like `should ===` inside of `forAll` properties.
@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 10, 2015

Thanks @bvenners for setting up a great example project for this. Bill, if you happen to take a look at this and see that I'm doing anything silly, let me know.

@codecov-io
Copy link

Current coverage is 63.82%

Merging #522 into master will not affect coverage as of dc9b870

@@            master    #522   diff @@
======================================
  Files          155     155       
  Stmts         2366    2366       
  Branches        66      66       
  Methods          0       0       
======================================
  Hit           1510    1510       
  Partial          0       0       
  Missed         856     856       

Review entire Coverage Diff as of dc9b870

Powered by Codecov. Updated on successful CI builds.

@adelbertc
Copy link
Contributor

I'm guessing should === gives better failure messages than just Object#== , similar to Specs2's mustEquals? We got a lot of usages of == scattered through our tests, though we can probably put that in a separate PR?

👍

@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 10, 2015

@adelbertc I think assert(a == b) actually returns good error messages because assert is a fancy scalatest macro. However, as you mentioned, it uses universal equality instead of Eq. This will allow us to have === provide a good error message and use our Eq instances (though I should test check that it's actually successfully requiring the Eq instance).

I agree that we should change a lot of == usage, and I can lead this effort, but I wanted this PR to go through first so the tedious effort wasn't in vain :)

@adelbertc
Copy link
Contributor

Yep sounds good, 👍 for me

@@ -0,0 +1,29 @@
package cats
Copy link

Choose a reason for hiding this comment

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

I think this whole file would be useful in tests that use the cats library, and not just cats itself. So, if that is the case, consider moving the file to main, so it could be exported - i.e. tests/shared/src/main/scala/cats/tests/CatsEquality.scala

@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 12, 2015

@inthenow I like the ideas in your comments. However, we currently aren't publishing the tests module at all. I've created #529 for this as a future idea. I think I'd prefer to keep this PR lightweight and hopefully uncontroversial and defer more complicated decisions/work. Does that sound okay?

Once this gets through I plan to update a lot of tests to take advantage of this syntax. I know that I've made type errors with == several times when writing Cats tests, and this seems like a mistake we shouldn't have to make when we have Eq instances available in all of our tests :)

@ghost
Copy link

ghost commented Sep 12, 2015

@ceedubs Absolutely OK! Note I used "consider" to introduce the concept, but more for a future issue/PR, where I shall now continue the conversation 👍

@non
Copy link
Contributor

non commented Sep 13, 2015

Thanks for this. Looks good! 👍

@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 14, 2015

I merged in master and resolved a couple merge conflicts due to #507 being merged. Since there are several 👍s, I'll merge once Travis goes green if there are no objections.

@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 14, 2015

The 2.11 build is failing with the following error:

[error] possible missing interpolator: detected interpolated identifier `$conforms`
[error] one error found
[error] (freeJVM/test:compileIncremental) Compilation failed

I don't see any reference to conforms in Cats, so I'm guessing this is coming from one of these changes not playing nicely with the recent macro/compiler plugins changes from #507. Any idea where this is coming from and what I've done to trigger it @non or @inthenow or @milessabin?

@ghost
Copy link

ghost commented Sep 14, 2015

@ceedubs in build.sbt, try using `"-Xlint:-missing-interpolator,_",```

For some reason we are getting the following error in the `free`
project:

```
possible missing interpolator: detected interpolated identifier `$conforms`
```

I think one of our macros/plugins is doing this. It would be nice to
figure out where it's coming from, but this should work around it
for now.
@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 15, 2015

@inthenow thanks for the suggestion. That makes it work for 2.11, but that isn't supported in 2.10, so now that build fails :(

We could hack around the compiler flags based on the cross-version, but it seems like it would be nice to figure out where this is coming from and fix it in a more elegant way. Any idea?

@ghost
Copy link

ghost commented Sep 15, 2015

@ceedubs I'm guessing it's the two calls to === in https://github.com/non/cats/blob/master/free/src/test/scala/cats/free/YonedaTests.scala and https://github.com/non/cats/blob/master/free/src/test/scala/cats/free/CoyonedaTests.scala that are noe using a different ===

If so, you can remove the "-Xlint:-missing-interpolator,_",

@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 15, 2015

@inthenow ah thanks good catch! I think that solved the issue. We'll see if Travis agrees.

@ceedubs
Copy link
Contributor Author

ceedubs commented Sep 15, 2015

We've gone green. I'm going to go ahead and merge since there are three +1s.

ceedubs added a commit that referenced this pull request Sep 15, 2015
Hook Eq up to scalactic/scalatest's equality
@ceedubs ceedubs merged commit 32783eb into typelevel:master Sep 15, 2015
@ceedubs ceedubs deleted the scalactic-equality branch September 15, 2015 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants