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

Add Scala to pure Java test builds #3009

Merged
merged 1 commit into from
Jul 9, 2024
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
3 changes: 2 additions & 1 deletion modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ object Build {
either {

val options0 =
if (sources.hasJava && !sources.hasScala)
// FIXME: don't add Scala to pure Java test builds (need to add pure Java test runner)
if (sources.hasJava && !sources.hasScala && scope != Scope.Test)
Gedochao marked this conversation as resolved.
Show resolved Hide resolved
options.copy(
scalaOptions = options.scalaOptions.copy(
scalaVersion = options.scalaOptions.scalaVersion.orElse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,4 +779,27 @@ abstract class TestTestDefinitions extends ScalaCliSuite with TestScalaVersionAr
}
}
}

test("successful pure Java test with JUnit") {
val expectedMessage = "Hello from JUnit"
TestInputs(
os.rel / "test" / "MyTests.java" ->
s"""//> using test.dependencies junit:junit:4.13.2
|//> using test.dependencies com.novocode:junit-interface:0.11
|import org.junit.Test;
|import static org.junit.Assert.assertEquals;
|
|public class MyTests {
| @Test
| public void foo() {
| assertEquals(4, 2 + 2);
| System.out.println("$expectedMessage");
| }
|}
|""".stripMargin
).fromRoot { root =>
val res = os.proc(TestUtil.cli, "test", extraOptions, ".").call(cwd = root)
expect(res.out.text().contains(expectedMessage))
}
}
}
Loading