Skip to content

Commit 47879c6

Browse files
committed
Test --cross with the test sub-command
1 parent 2ea4041 commit 47879c6

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
1212
if (actualScalaVersion.startsWith("3.")) Seq("--jvm", "11")
1313
else Nil
1414
protected lazy val baseExtraOptions: Seq[String] = TestUtil.extraOptions ++ jvmOptions
15-
private lazy val extraOptions: Seq[String] = scalaVersionArgs ++ baseExtraOptions
15+
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ baseExtraOptions
1616

1717
private val utestVersion = "0.8.3"
1818

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.eed3si9n.expecty.Expecty.expect
44

55
import java.io.File
66

7+
import scala.cli.integration.Constants.munitVersion
8+
79
class TestTestsDefault extends TestTestDefinitions with TestDefault {
810
test("Pure Java with Scala tests") {
911
val inputs = TestInputs(
@@ -40,4 +42,31 @@ class TestTestsDefault extends TestTestDefinitions with TestDefault {
4042
.call(cwd = root, stdout = os.Inherit)
4143
}
4244
}
45+
46+
test(
47+
s"successful test --cross $actualScalaVersion with ${Constants.scala213} and ${Constants.scala212}"
48+
) {
49+
val crossVersions = Seq(actualScalaVersion, Constants.scala213, Constants.scala212)
50+
val expectedMessage = "Hello"
51+
TestInputs(
52+
os.rel / "Cross.test.scala" ->
53+
s"""//> using dep org.scalameta::munit::$munitVersion
54+
|class MyTests extends munit.FunSuite {
55+
| test("foo") {
56+
| assert(2 + 2 == 4)
57+
| println("$expectedMessage")
58+
| }
59+
|}
60+
|""".stripMargin,
61+
os.rel / "project.scala" -> s"//> using scala ${crossVersions.mkString(" ")}"
62+
).fromRoot { root =>
63+
val output = os.proc(TestUtil.cli, "test", extraOptions, ".", "--cross", "--power")
64+
.call(cwd = root).out.text()
65+
def countOccurrences(a: String, b: String): Int =
66+
if (b.isEmpty) 0 // Avoid infinite splitting
67+
else a.sliding(b.length).count(_ == b)
68+
expect(output.contains(expectedMessage))
69+
expect(countOccurrences(output, expectedMessage) == crossVersions.length)
70+
}
71+
}
4372
}

0 commit comments

Comments
 (0)