@@ -19,6 +19,8 @@ import munit.TestOptions
1919import os .Shellable
2020
2121object Java8Only extends munit.Tag (" Java8Only" )
22+ case class JVMCompatibility (tools : List [Tool ])
23+ extends munit.Tag (" JVMCompatibility" )
2224
2325abstract 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