10000 JUnit: populate sbt.testing.Event.duration by dubinsky · Pull Request #5134 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

JUnit: populate sbt.testing.Event.duration #5134

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

Merged

Conversation

dubinsky
Copy link
Contributor

If duration associated with the test event is available, bubble it up through the SBT's test interface using the slot dedicated to just such information: sbt.testing.Event.duration.

In addition to it being a shame to throw away information about the duration that is literally in our hands, this avoids weird-looking negative duration values in test reports.

@dubinsky
Copy link
Contributor Author

@sjrd any comments?

Copy link
Member
@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Sorry for the late review. I've been swamped with other things.

@@ -117,12 +117,14 @@ private[junit] final class Reporter(eventHandler: EventHandler,
private def emitEvent(
method: Option[String],
status: Status,
throwable: OptionalThrowable = new OptionalThrowable
throwable: OptionalThrowable = new OptionalThrowable,
timeInSeconds: Double = 0.001
Copy link
Member

Choose a reason for hiding this comment

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

That default value looks very suspicious. I think it should be an Option[Double] = None, if anything, and that None really translates to the constant -1L, as specified in the doc of sbt.testing.Event:
https://github.com/sbt/test-interface/blob/e0db1f531713ac7b66d3159513d2c044bc2cdca0/src/main/java/sbt/testing/Event.java#L37-L40

Copy link
Contributor Author
@dubinsky dubinsky Mar 6, 2025

Choose a reason for hiding this comment

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

Thanks!! Not only was it ugly and suspicious, it was also wrong (positive instead of negative).
I reworked it the way you suggested.
I also reworked the throwable parameter the same way and dropped the defaults for both: let's be explicit.

This surfaced an issue: on JVM, time is reported for skipped tests (which TestMetadata calls ignored),
but on Scala.js it is not; this is why in JUnitTest I record duration as not populated for such tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, we can report duration of 0 in Reporter.reportIgnored()... Please advise ;)

Copy link
Member

Choose a reason for hiding this comment

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

Our design is to emulate what the original JUnit does to the greatest extent possible. So if JUnit-on-JVM reports a duration for ignored tests, we should do the same, even if it's 0 as you suggest.

Comment on lines 275 to 277
case Log(level, msg) => "l" + level + msg
case Done(msg) => "d" + msg
case Event(s, n, t) => "e" + s.ordinal + n + separator + t.getOrElse("")
case Event(s, n, t, d) => "e" + s.ordinal + n + separator + t.getOrElse("") + separator + d
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the arrows aligned:

Suggested change
case Log(level, msg) => "l" + level + msg
case Done(msg) => "d" + msg
case Event(s, n, t) => "e" + s.ordinal + n + separator + t.getOrElse("")
case Event(s, n, t, d) => "e" + s.ordinal + n + separator + t.getOrElse("") + separator + d
case Log(level, msg) => "l" + level + msg
case Done(msg) => "d" + msg
case Event(s, n, t) => "e" + s.ordinal + n + separator + t.getOrElse("")
case Event(s, n, t, d) => "e" + s.ordinal + n + separator + t.getOrElse("") + separator + d

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@dubinsky dubinsky force-pushed the JUnit-populate-sbt.testing.Event.duration branch from 1727e43 to 4a2d0e1 Compare March 6, 2025 20:44
@dubinsky
Copy link
Contributor Author
dubinsky commented Mar 6, 2025

Sorry for the late review. I've been swamped with other things.

No worries. Thank you for the review!

If duration associated with the test event is available, bubble it up through the SBT's test interface using the slot dedicated to just such information: sbt.testing.Event.duration.

In addition to it being a shame to throw away information about the duration that is literally in our hands, this avoids weird-looking negative duration values in test reports.
@dubinsky dubinsky force-pushed the JUnit-populate-sbt.testing.Event.duration branch from 4a2d0e1 to 8220951 Compare March 7, 2025 16:24
@dubinsky
Copy link
Contributor Author
dubinsky commented Mar 7, 2025

Thank you, @sjrd!

@sjrd sjrd merged commit e67a1a2 into scala-js:main Mar 7, 2025
3 checks passed
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.

2 participants
0