Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run warm up test before running default tests #1599

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect

class DefaultTests extends ScalaCliSuite {
class DefaultTests extends WithWarmUpScalaCliSuite {
override def warmUpExtraTestOptions: Seq[String] = TestUtil.extraOptions

test("running scala-cli with no args should default to repl") {
TestInputs.empty.fromRoot { root =>
val res = os.proc(TestUtil.cli, "--repl-dry-run").call(cwd = root, mergeErrIntoOut = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.jdk.CollectionConverters.*
import scala.util.Properties

abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
extends ScalaCliSuite
extends WithWarmUpScalaCliSuite
with TestScalaVersionArgs
with RunScriptTestDefinitions
with RunScalaJsTestDefinitions
Expand All @@ -23,25 +23,13 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
with RunScalaPyTestDefinitions
with RunZipTestDefinitions {

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

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

// warm-up run that downloads compiler bridges
// The "Downloading compiler-bridge (from bloop?) pollute the output, and would make the first test fail.
lazy val warmupTest: Unit = {
System.err.println("Running RunTests warmup test…")
simpleScriptTest(ignoreErrors = true)
System.err.println("Done running RunTests warmup test.")
}

override def test(name: String)(body: => Any)(implicit loc: munit.Location): Unit =
super.test(name) { warmupTest; body }(loc)
override def test(name: munit.TestOptions)(body: => Any)(implicit loc: munit.Location): Unit =
super.test(name) { warmupTest; body }(loc)

test("print command") {
val fileName = "simple.sc"
val message = "Hello"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect

abstract class WithWarmUpScalaCliSuite extends ScalaCliSuite {
Gedochao marked this conversation as resolved.
Show resolved Hide resolved

def warmUpExtraTestOptions: Seq[String]

// warm-up run that downloads compiler bridges
// The "Downloading compiler-bridge (from bloop?) pollute the output, and would make the first test fail.
lazy val warmupTest: Unit = {
System.err.println("Running warmup test…")
warmUpTests(ignoreErrors = true)
System.err.println("Done running warmup test.")
}

def warmUpTests(ignoreErrors: Boolean): Unit = {
val fileName = "simple.sc"
val message = "Hello"
val inputs = TestInputs(
os.rel / fileName ->
s"""val msg = "$message"
|println(msg)
|""".stripMargin
)
inputs.fromRoot { root =>
val output =
os.proc(TestUtil.cli, warmUpExtraTestOptions, fileName).call(cwd = root).out.trim()
if (!ignoreErrors)
expect(output == message)
}
}

override def test(name: String)(body: => Any)(implicit loc: munit.Location): Unit =
super.test(name) { warmupTest; body }(loc)

override def test(name: munit.TestOptions)(body: => Any)(implicit loc: munit.Location): Unit =
super.test(name) { warmupTest; body }(loc)
}