summaryrefslogtreecommitdiff
path: root/src/partest
diff options
context:
space:
mode:
authorJames Iry <james.iry@typesafe.com>2013-06-04 10:22:43 -0700
committerJames Iry <james.iry@typesafe.com>2013-06-04 10:22:43 -0700
commitac4e3ca19246ae3d983f99607b865c5ed3acb2b9 (patch)
tree71df59ffda407ea0e527aeec3cea38fe7edc4043 /src/partest
parentfc6da8d8b765ddc3c492d0884164561ca7a8b4d8 (diff)
downloadscala-ac4e3ca19246ae3d983f99607b865c5ed3acb2b9.tar.gz
scala-ac4e3ca19246ae3d983f99607b865c5ed3acb2b9.tar.bz2
scala-ac4e3ca19246ae3d983f99607b865c5ed3acb2b9.zip
Refactor testing logic for only running under certain JDK versions
We had several tests designed to only run if the JDK version was at least some specified version. This commit refactors that common logic into DirectTest.
Diffstat (limited to 'src/partest')
-rw-r--r--src/partest/scala/tools/partest/DirectTest.scala27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/partest/scala/tools/partest/DirectTest.scala b/src/partest/scala/tools/partest/DirectTest.scala
index e2dac2fd55..8fcaa6423c 100644
--- a/src/partest/scala/tools/partest/DirectTest.scala
+++ b/src/partest/scala/tools/partest/DirectTest.scala
@@ -6,6 +6,7 @@
package scala.tools.partest
import scala.tools.nsc._
+import settings.ScalaVersion
import io.Directory
import util.{ SourceFile, BatchSourceFile, CommandLineParser }
import reporters.{Reporter, ConsoleReporter}
@@ -101,4 +102,30 @@ abstract class DirectTest extends App {
final def log(msg: => Any) {
if (isDebug) Console.err println msg
}
+
+ /**
+ * Run a test only if the current java version is at least the version specified.
+ */
+ def testUnderJavaAtLeast[A](version: String)(yesRun: =>A) = new TestUnderJavaAtLeast(version, { yesRun })
+
+ class TestUnderJavaAtLeast[A](version: String, yesRun: => A) {
+ val javaVersion = System.getProperty("java.specification.version")
+
+ // the "ScalaVersion" class parses Java specification versions just fine
+ val requiredJavaVersion = ScalaVersion(version)
+ val executingJavaVersion = ScalaVersion(javaVersion)
+ val shouldRun = executingJavaVersion >= requiredJavaVersion
+ val preamble = if (shouldRun) "Attempting" else "Doing fallback for"
+
+ def logInfo() = log(s"$preamble java $version specific test under java version $javaVersion")
+
+ /*
+ * If the current java version is at least 'version' then 'yesRun' is evaluated
+ * otherwise 'fallback' is
+ */
+ def otherwise(fallback: =>A): A = {
+ logInfo()
+ if (shouldRun) yesRun else fallback
+ }
+ }
}