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