-
Notifications
You must be signed in to change notification settings - Fork 243
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
Experiment with shouldEqv
ScalaTest matcher
#294
Comments
Something like this ? I'm not (yet) doing a PR because I do not know the good strategy w.r.t. having dependencies on a particular version of scalatest from the Spire dependency. package org.scalatest
import MatchersHelper.newTestFailedException
import spire.algebra.Eq
trait EqMatchers {
final implicit class ShouldEqvWrapper[T](val lhs: T) {
def shouldEqv(rhs: T)(implicit ev: Eq[T]) {
if (!ev.eqv(lhs, rhs)) {
val (leftee, rightee) = Suite.getObjectsForFailureMessage(lhs, rhs)
throw newTestFailedException(FailureMessages("wasNotEqvTo", leftee, rightee))
}
}
}
} |
Note that |
Just noticed this. There's a better way to do this. I'm teaching a class today but will try and work up an example. In short, scalatest's (scalactic's really) equality is designed so you can plug in other equality tyoeclasses such as the ones in spite or scalaz and use that for === instead of the built-in one. |
I whipped up a demo and put it here: https://github.com/bvenners/equality-integration-demo |
It's cool that Would it be possible to offer a base trait for
|
I'm not sure I understand what you're suggesting. You can easily make a custom matcher that takes an Eq, which I think was your original idea. Say you call it spireEqual. You could then write: result should spireEqual (22) You could also use Spire's === operator already in assertions, like this: assert(a === b) But right now you won't get the nice good error message. What I think we could do is look at enabling a nice equality error message using any === operator, not just ScalaTest's. But this wouldn't help you using ScalaTest's Matchers for equal. I think enhancing our assert macro to handle any === operator is worth doing, if it is possible and doesn't add to compile time, but otherwise I suspect the extension points that will make sense is what I posted in the equality integration demo and custom matchers. However, I would like to make sure I understand what you're suggesting. Can you clarify? |
Regrouped. |
As @denisrosset suggested, it would be nice to have a custom matcher which uses our
Eq[A]
type class and which integrates with ScalaTest.The text was updated successfully, but these errors were encountered: