-
Notifications
You must be signed in to change notification settings - Fork 530
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
Replace specs2 with munit #4216
base: series/3.x
Are you sure you want to change the base?
Conversation
e671306
to
d2b73e9
Compare
// we try iterating a few times to get canceled in the middle | ||
if (i > Bound) { | ||
IO.pure(skipped(s"attempted $i times and could not reproduce scenario")) | ||
IO.println(s"attempted $i times and could not reproduce scenario") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, it's not a direct equivalent. But I cannot think of anything better.
4c319c2
to
7bc5906
Compare
…holy crap |
General 20k LOC changeset. Nothing to worry about 😅 |
Specs2 model feels more strict. With munit the following code compiles and the test is green, but it's never being executed: test("leaky io") {
IO(sys.error("boom"))
} The compiler doesn't throw any warning, either. I hope I didn't miss such cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NGL, I didn't read through all 11k lines. Did some spot checking around though and left some comments on things that I think probably apply more broadly. Agree we should review carefully. Overall looks good though.
|
||
if (!isWindows) { // these tests have all been emperically flaky on Windows CI builds, so they're disabled | ||
|
||
"evaluate and print hello world" in { | ||
test(s"IOApp (${platform.id}) - evaluate and print hello world") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit of bikeshedding: I think on this one (and a bunch of similars), we can simply discard the should
. With IOAppSpec
it just doesn't add any value.
This one is concerning, to be sure. We've historically had a bunch of problems with this, and we do have a ton of tests which throw exceptions in various cases. We should explore our own variant of |
|
||
override def munitValueTransforms: List[ValueTransform] = | ||
super.munitValueTransforms ++ List( | ||
new ValueTransform("IO", { case _: IO[_] => sys.error("Non-evaluated IO") }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These transformers prevent us from misuse like:
test("leaky io") {
IO(sys.error("boom"))
}
3d60f3f
to
9f68a30
Compare
I think the next step on this is probably to go through and surgically break some subtle things one at a time and make sure the test suite still catches it. |
@deprecated("Please use a type safe alternative, such as 'real' or 'ticked'", "3.6.0") | ||
override def test(name: String)(body: => Any)(implicit loc: Location): Unit = | ||
super.test(name)(body) | ||
|
||
@deprecated("Please use a type safe alternative, such as 'real' or 'ticked'", "3.6.0") | ||
override def test(options: TestOptions)(body: => Any)(implicit loc: Location): Unit = | ||
super.test(options)(body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deprecated the built-in options. Now, we are forced to use a type-safe alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just boink them entirely since it's internal, rather than deprecating.
override def test(name: String)(body: => Any)(implicit loc: Location): Unit = | ||
super.test(name)(body) | ||
|
||
@deprecated("Please use a type safe alternative, such as 'real' or 'ticked'", "3.6.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it type safe
, type-safe
, typsafe
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen all three. 😃 Which is your favorite?
Sorry, I snuck a new test in here. |
new ValueTransform( | ||
"Other", | ||
{ | ||
case r if !r.isInstanceOf[Unit] && !r.isInstanceOf[Prop] => | ||
sys.error(s"Unexpected value of type ${r.getClass.getName}: $r") | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This transformer ensures the result type is Unit
or Prop
.
From the munit perspective, that's a valid test:
test("some test") {
1 == 2
}
However, it should use assert
:
test("some test") {
assert(1 == 2)
}
Here are all the fixed tests that were exposed by this transformer: 9186d4b
def real[A: AsResult](test: => IO[A]): Execution = | ||
Execution.withEnvAsync { _ => | ||
val (fut, cancel) = test.unsafeToFutureCancelable()(runtime()) | ||
def ticked(options: TestOptions)(body: Ticker => Unit)(implicit loc: Location): Unit = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tightened the body type from Ticker => A
to Ticker => Unit
. Spotted a few non-evaluated assertions that way.
No worries. I've backported the test. |
So for some reason,
|
My best guess is that
If you didn't clean the project, it may use the old cached native artifacts. |
Follow up to #3787.
The whole PR is purely focused on the migration. There are options to build more usable test abstractions and utilities, but I don't want to do it without proper thinking.