Skip to content

Commit 63b4748

Browse files
authored
Add Scala to pure Java test builds (#3009)
1 parent 2378310 commit 63b4748

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ object Build {
10291029
either {
10301030

10311031
val options0 =
1032-
if (sources.hasJava && !sources.hasScala)
1032+
// FIXME: don't add Scala to pure Java test builds (need to add pure Java test runner)
1033+
if (sources.hasJava && !sources.hasScala && scope != Scope.Test)
10331034
options.copy(
10341035
scalaOptions = options.scalaOptions.copy(
10351036
scalaVersion = options.scalaOptions.scalaVersion.orElse {

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,27 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
779779
}
780780
}
781781
}
782+
783+
test("successful pure Java test with JUnit") {
784+
val expectedMessage = "Hello from JUnit"
785+
TestInputs(
786+
os.rel / "test" / "MyTests.java" ->
787+
s"""//> using test.dependencies junit:junit:4.13.2
788+
|//> using test.dependencies com.novocode:junit-interface:0.11
789+
|import org.junit.Test;
790+
|import static org.junit.Assert.assertEquals;
791+
|
792+
|public class MyTests {
793+
| @Test
794+
| public void foo() {
795+
| assertEquals(4, 2 + 2);
796+
| System.out.println("$expectedMessage");
797+
| }
798+
|}
799+
|""".stripMargin
800+
).fromRoot { root =>
801+
val res = os.proc(TestUtil.cli, "test", extraOptions, ".").call(cwd = root)
802+
expect(res.out.text().contains(expectedMessage))
803+
}
804+
}
782805
}

0 commit comments

Comments
 (0)