-
Notifications
You must be signed in to change notification settings - Fork 90
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
Move Fixture[T]
into a toplevel class.
#228
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
olafurpg
force-pushed
the
toplevel-fixture
branch
from
October 19, 2020 14:57
052cd8b
to
b917bd0
Compare
Previously, FailException had some custom nice-to-have features that ComparisonFailException didn't have.
This makes the error message clearer in some cases.
Previously, MUnit had a subtyping constraint on `assertEquals(a, b)` so that it would fail to compile if `a` was not a subtype of `b`. This was a suboptimal solution because the compile error messages could become cryptic in some cases. Additionally, this API didn't integrate with other libaries like Cats that has its own `cats.Eq[A,B]` type-class. Now, MUnit uses a new `munit.Compare[A,B]` type-class for comparing values of different types. By default, MUnit provides a "universal" instance that permits comparison between all types and uses the built-in `==` method. Users can optionally enable "strict equality" by adding the compiler option `"-Xmacro-settings.munit.strictEquality"` in Scala 2. In Scala 3, we use the `Eql[A, B]` type-classes instead to determine type equality.
This is a fourth attempt at improving strict equality in MUnit `assertEquals()` assertions. * First attempt (current release version): require second argument to be a supertype of the first argument. This has the flaw that the compile error message is cryptic and that the ordering of the arguments affects compilation. * Second attempt: use `Eql[A, B]` in Scala 3 and allow comparing any types in Scala 2. This has the flaw that it's a regression in some cases for Scala 2 users and that `Eql[A, B]` is not really usable in its current form, see related discussion https://contributors.scala-lang.org/t/should-multiversal-equality-provide-default-eql-instances/4574 * Third attempt: implement "strict equality" for Scala 2 with a macro and `Eql[T, T]` in Scala. This improves the situation for Scala 2, but would mean relying on a feature that we can't easily port to Scala 3. * Fourth attempt (this commit): improve the first attempt (current release) by allowing `Compare[A, B]` as long as `A <:< B` OR `B <:< A`. This is possible thanks to an observation by Gabriele Petronella that it's possible to layer the implicits to avoid diverging implicit search. The benefit of the fourth approach is that it works the same way for Scala 3 and Scala 3. It's very nice that we can avoid macros as well.
olafurpg
force-pushed
the
toplevel-fixture
branch
from
November 1, 2020 09:06
b917bd0
to
2f75403
Compare
Previously, `Fixture[T]` was declared as an inner class of `FunSuite`. This made it annoying to implement fixtures as normal toplevel classes. Now, `Fixture[T]` is just a normal toplevel class making it easier to reason about. Breaking change: In order to implement this change, we remove the ability to extend `Suite` with a custom `type TestValue`. The test value is now hardcoded to `Future[Any]`. I'm not aware of any library that extends `munit.Suite` with a custom `TestValue`. All the 3rdparty integrations that I have seen hardcode against `munit.FunSuite` anyways. Given this feature doesn't seem to be used anywhere and it complicates the public API, I feel it's best to remove it.
olafurpg
force-pushed
the
toplevel-fixture
branch
from
November 1, 2020 09:06
2f75403
to
a268af8
Compare
Superseded by #430 , which makes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously,
Fixture[T]
was declared as an inner class ofFunSuite
.This made it annoying to implement fixtures as normal toplevel classes.
Now,
Fixture[T]
is just a normal toplevel class making it easier toreason about.
Breaking change: In order to implement this change, we remove the
ability to extend
Suite
with a customtype TestValue
. The test valueis now hardcoded to
Future[Any]
. I'm not aware of any library thatextends
munit.Suite
with a customTestValue
. All the 3rdpartyintegrations that I have seen hardcode against
munit.FunSuite
anyways.Given this feature doesn't seem to be used anywhere and it complicates
the public API, I feel it's best to remove it.
Fixes #175
Waiting to merge #225 before moving further with this PR.