Skip to content

Commit 0876947

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

File tree

2 files changed

+31
-56
lines changed

2 files changed

+31
-56
lines changed

.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: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import munit.TestOptions
1919
import os.Shellable
2020

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

2325
abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
2426
self =>
@@ -44,6 +46,26 @@ abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
4446
t.tag(munit.Ignore)
4547
else
4648
t
49+
),
50+
new TestTransform(
51+
"JVMCompatibility",
52+
t =>
53+
t.tags
54+
.collectFirst { case JVMCompatibility(tools) =>
55+
tools
56+
}
57+
.map { tools =>
58+
val minJDK = Tool.minimumSupportedJdk(tools)
59+
val maxJDK = Tool
60+
.maximumSupportedJdk(tools)
61+
.getOrElse(Int.MaxValue)
62+
val javaVersion = BaseBuildToolSuite.externalJavaVersion
63+
if (javaVersion < minJDK || javaVersion > maxJDK)
64+
t.tag(munit.Ignore)
65+
else
66+
t
67+
}
68+
.getOrElse(t)
4769
)
4870
)
4971

@@ -79,28 +101,13 @@ abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) {
79101
targetRoot: Option[String] = None,
80102
tools: List[Tool] = Nil
81103
): 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)
104+
val testTags =
105+
if (tools.nonEmpty)
106+
options.tags ++ tags + JVMCompatibility(tools)
107+
else
108+
options.tags ++ tags
103109

110+
test(options.withTags(testTags)) {
104111
if (initCommand.nonEmpty) {
105112
os.proc(Shellable(initCommand)).call(os.Path(workingDirectory))
106113
}

0 commit comments

Comments
 (0)