|
| 1 | +/* |
| 2 | + * Scala (https://www.scala-lang.org) |
| 3 | + * |
| 4 | + * Copyright EPFL and Lightbend, Inc. |
| 5 | + * |
| 6 | + * Licensed under Apache License 2.0 |
| 7 | + * (http://www.apache.org/licenses/LICENSE-2.0). |
| 8 | + * |
| 9 | + * See the NOTICE file distributed with this work for |
| 10 | + * additional information regarding copyright ownership. |
| 11 | + */ |
| 12 | + |
| 13 | +package scala.compat.java8 |
| 14 | + |
| 15 | +import org.junit.Assert._ |
| 16 | +import org.junit.Assume.assumeTrue |
| 17 | +import org.junit.Test |
| 18 | +import org.junit.function.ThrowingRunnable |
| 19 | + |
| 20 | +import java.nio.file.{Files, Paths} |
| 21 | +import scala.compat.java8.StreamConverters._ |
| 22 | +import scala.compat.java8.issue247.Main |
| 23 | +import scala.sys.process._ |
| 24 | +import scala.util.Try |
| 25 | + |
| 26 | +class Issue247Test { |
| 27 | + @Test |
| 28 | + def runMainDirectly(): Unit = Main.main(Array.empty) |
| 29 | + |
| 30 | + val mainCls = "scala.compat.java8.issue247.Main" |
| 31 | + |
| 32 | + @Test |
| 33 | + def runMainMatrix(): Unit = { |
| 34 | + assumeTrue("only run in Linux/OSX", "which which".! == 0) |
| 35 | + |
| 36 | + val pwd = "pwd".!!.trim |
| 37 | + |
| 38 | + val coursier = Try { |
| 39 | + ("which cs" #|| "which coursier").!!.trim |
| 40 | + }.getOrElse { |
| 41 | + val cs = s"$pwd/target/coursier" |
| 42 | + if (!Files.isExecutable(Paths.get(cs))) |
| 43 | + ( s"curl -fLo $cs https://git.io/coursier-cli" #&& |
| 44 | + s"chmod +x $cs" |
| 45 | + ).!.ensuring(_ == 0) |
| 46 | + cs |
| 47 | + } |
| 48 | + |
| 49 | + for { |
| 50 | + scalaBinV <- Seq("2.11", "2.12", "2.13", "3") |
| 51 | + compatV <- Seq("0.9.1", "1.0.0", "1.0.1") |
| 52 | + // scala-java8-compat for scala3 don't have version 0.9.1 |
| 53 | + if scalaBinV != "3" || compatV != "0.9.1" |
| 54 | + scalaDir <- Files.list(Paths.get(pwd, "target")).toScala[List] |
| 55 | + if scalaDir.toFile.getName.startsWith(s"scala-$scalaBinV") |
| 56 | + classesDir = scalaDir.resolve("test-classes") |
| 57 | + if classesDir.resolve("scala/compat/java8/issue247/Main.class").toFile.isFile |
| 58 | + } { |
| 59 | + val classpath = Process( |
| 60 | + Seq( |
| 61 | + coursier, // may contain spaces |
| 62 | + "fetch", "--classpath", |
| 63 | + s"org.scala-lang.modules:scala-java8-compat_$scalaBinV:$compatV" |
| 64 | + ) |
| 65 | + ).!!.trim |
| 66 | + |
| 67 | + val testCmd = s"java -cp $classpath:$classesDir $mainCls" |
| 68 | + |
| 69 | + val run: ThrowingRunnable = new ThrowingRunnable { |
| 70 | + def run(): Unit = { |
| 71 | + println(testCmd) |
| 72 | + testCmd.!! |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + if ((scalaBinV, compatV) == ("2.13", "0.9.1")) { |
| 77 | + run.run() // no Exception |
| 78 | + } else { |
| 79 | + assertThrows(classOf[RuntimeException], run) |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments