Skip to content

Commit 5ce08ff

Browse files
committed
Replace assume() with munit TestTransform that skips tests at discovery
1 parent 043f955 commit 5ce08ff

2 files changed

Lines changed: 26 additions & 56 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,16 @@ on:
55
- main
66
pull_request:
77
jobs:
8-
gradle_8:
8+
test:
99
runs-on: ${{ matrix.os }}
10-
name: Tests (Gradle 8)
10+
name: Tests (JDK ${{ matrix.java }})
1111
strategy:
1212
fail-fast: false
1313
matrix:
1414
# NOTE(olafurpg) Windows is not enabled because it times out due to reasons I don't understand.
1515
# os: [windows-latest, ubuntu-latest]
1616
os: [ubuntu-latest]
17-
java: [8, 11, 17, 21]
18-
steps:
19-
- uses: actions/checkout@v6
20-
21-
- uses: actions/setup-java@v5
22-
with:
23-
distribution: "temurin"
24-
cache: "sbt"
25-
java-version: ${{ matrix.java }}
26-
27-
- uses: sbt/setup-sbt@v1
28-
29-
- name: Setup Gradle 8.14.3
30-
uses: gradle/actions/setup-gradle@v5
31-
with:
32-
gradle-version: "8.14.3"
33-
34-
- name: Main project tests
35-
run: sbt test
36-
37-
gradle_9:
38-
runs-on: ${{ matrix.os }}
39-
name: Tests (Gradle 9)
40-
strategy:
41-
fail-fast: false
42-
matrix:
43-
os: [ubuntu-latest]
44-
java: [17, 21, 25]
17+
java: [8, 11, 17, 21, 25]
4518
steps:
4619
- uses: actions/checkout@v6
4720

@@ -53,11 +26,6 @@ jobs:
5326

5427
- uses: sbt/setup-sbt@v1
5528

56-
- name: Setup Gradle 9.2.1
57-
uses: gradle/actions/setup-gradle@v5
58-
with:
59-
gradle-version: "9.2.1"
60-
6129
- name: Main project tests
6230
run: sbt test
6331

tests/buildTools/src/test/scala/tests/BaseBuildToolSuite.scala

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import munit.TestOptions
1919
import os.Shellable
2020

2121
object Java8Only extends munit.Tag("Java8Only")
22+
case class JVMCompatibility(tools: List[Tool]) extends munit.Tag("JVMCompatibility")
2223

2324
abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
2425
self =>
@@ -44,6 +45,22 @@ abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
4445
t.tag(munit.Ignore)
4546
else
4647
t
48+
),
49+
new TestTransform(
50+
"JVMCompatibility",
51+
t =>
52+
t.tags
53+
.collectFirst { case JVMCompatibility(tools) => tools }
54+
.map { tools =>
55+
val minJDK = Tool.minimumSupportedJdk(tools)
56+
val maxJDK = Tool.maximumSupportedJdk(tools).getOrElse(Int.MaxValue)
57+
val javaVersion = BaseBuildToolSuite.externalJavaVersion
58+
if (javaVersion < minJDK || javaVersion > maxJDK)
59+
t.tag(munit.Ignore)
60+
else
61+
t
62+
}
63+
.getOrElse(t)
4764
)
4865
)
4966

@@ -79,28 +96,13 @@ abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
7996
targetRoot: Option[String] = None,
8097
tools: List[Tool] = Nil
8198
): Unit = {
82-
val minJDK = Tool.minimumSupportedJdk(tools)
83-
val maxJDK = Tool.maximumSupportedJdk(tools).getOrElse(Int.MaxValue)
84-
val externalJDKVersion = BaseBuildToolSuite.externalJavaVersion
85-
86-
val JDKSupported =
87-
externalJDKVersion >= minJDK && externalJDKVersion <= maxJDK
88-
89-
val ignoreMsg =
90-
s"Test ${options
91-
.name} was ignored because the external JDK version doesn't match the toolset requirements: " +
92-
s"Tools: $tools, min JDK = $minJDK, max JDK = $maxJDK, detected JDK = $externalJDKVersion"
93-
94-
test(options.withTags(options.tags ++ tags)) {
95-
// Unfortunately, MUnit doesn't seem to handle the ignore messages the
96-
// way we'd want: https://github.com/scalameta/munit/issues/549#issuecomment-2056751821
97-
// So instead, to give some indication that the test was actually ignored,
98-
// we print this message
99-
if (!JDKSupported)
100-
System.err.println(ignoreMsg)
101-
102-
assume(JDKSupported, ignoreMsg)
99+
val testTags =
100+
if (tools.nonEmpty)
101+
options.tags ++ tags + JVMCompatibility(tools)
102+
else
103+
options.tags ++ tags
103104

105+
test(options.withTags(testTags)) {
104106
if (initCommand.nonEmpty) {
105107
os.proc(Shellable(initCommand)).call(os.Path(workingDirectory))
106108
}

0 commit comments

Comments
 (0)