Skip to content

Commit 21e1cf4

Browse files
authored
Run warm up test before running default tests (#1599)
1 parent 7979e36 commit 21e1cf4

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

modules/integration/src/test/scala/scala/cli/integration/DefaultTests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package scala.cli.integration
22

33
import com.eed3si9n.expecty.Expecty.expect
44

5-
class DefaultTests extends ScalaCliSuite {
5+
class DefaultTests extends WithWarmUpScalaCliSuite {
6+
override def warmUpExtraTestOptions: Seq[String] = TestUtil.extraOptions
7+
68
test("running scala-cli with no args should default to repl") {
79
TestInputs.empty.fromRoot { root =>
810
val res = os.proc(TestUtil.cli, "--repl-dry-run").call(cwd = root, mergeErrIntoOut = true)

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.jdk.CollectionConverters.*
1111
import scala.util.Properties
1212

1313
abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
14-
extends ScalaCliSuite
14+
extends WithWarmUpScalaCliSuite
1515
with TestScalaVersionArgs
1616
with RunScriptTestDefinitions
1717
with RunScalaJsTestDefinitions
@@ -23,25 +23,13 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
2323
with RunScalaPyTestDefinitions
2424
with RunZipTestDefinitions {
2525

26-
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
27-
protected val emptyInputs: TestInputs = TestInputs(os.rel / ".placeholder" -> "")
26+
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
27+
protected val emptyInputs: TestInputs = TestInputs(os.rel / ".placeholder" -> "")
28+
override def warmUpExtraTestOptions: Seq[String] = extraOptions
2829

2930
protected val ciOpt: Seq[String] =
3031
Option(System.getenv("CI")).map(v => Seq("-e", s"CI=$v")).getOrElse(Nil)
3132

32-
// warm-up run that downloads compiler bridges
33-
// The "Downloading compiler-bridge (from bloop?) pollute the output, and would make the first test fail.
34-
lazy val warmupTest: Unit = {
35-
System.err.println("Running RunTests warmup test…")
36-
simpleScriptTest(ignoreErrors = true)
37-
System.err.println("Done running RunTests warmup test.")
38-
}
39-
40-
override def test(name: String)(body: => Any)(implicit loc: munit.Location): Unit =
41-
super.test(name) { warmupTest; body }(loc)
42-
override def test(name: munit.TestOptions)(body: => Any)(implicit loc: munit.Location): Unit =
43-
super.test(name) { warmupTest; body }(loc)
44-
4533
test("print command") {
4634
val fileName = "simple.sc"
4735
val message = "Hello"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package scala.cli.integration
2+
3+
import com.eed3si9n.expecty.Expecty.expect
4+
5+
abstract class WithWarmUpScalaCliSuite extends ScalaCliSuite {
6+
7+
def warmUpExtraTestOptions: Seq[String]
8+
9+
// warm-up run that downloads compiler bridges
10+
// The "Downloading compiler-bridge (from bloop?) pollute the output, and would make the first test fail.
11+
lazy val warmupTest: Unit = {
12+
System.err.println("Running warmup test…")
13+
warmUpTests(ignoreErrors = true)
14+
System.err.println("Done running warmup test.")
15+
}
16+
17+
def warmUpTests(ignoreErrors: Boolean): Unit = {
18+
val fileName = "simple.sc"
19+
val message = "Hello"
20+
val inputs = TestInputs(
21+
os.rel / fileName ->
22+
s"""val msg = "$message"
23+
|println(msg)
24+
|""".stripMargin
25+
)
26+
inputs.fromRoot { root =>
27+
val output =
28+
os.proc(TestUtil.cli, warmUpExtraTestOptions, fileName).call(cwd = root).out.trim()
29+
if (!ignoreErrors)
30+
expect(output == message)
31+
}
32+
}
33+
34+
override def test(name: String)(body: => Any)(implicit loc: munit.Location): Unit =
35+
super.test(name) { warmupTest; body }(loc)
36+
37+
override def test(name: munit.TestOptions)(body: => Any)(implicit loc: munit.Location): Unit =
38+
super.test(name) { warmupTest; body }(loc)
39+
}

0 commit comments

Comments
 (0)