Skip to content

Commit 224b2ca

Browse files
committed
Add --debug option for integration tests
1 parent 06f07dc commit 224b2ca

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ Filter test suites with
4545
./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.Multiple scripts'
4646
```
4747

48+
Pass the `--debug` option to debug integration tests:
49+
```bash
50+
./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.*' --debug
51+
```
52+
53+
The debug option uses 5005 port by default. It is possible to change it as follows:
54+
```bash
55+
./mill integration.test.jvm 'scala.cli.integration.RunTestsDefault.*' --debug:5006
56+
```
57+
4858
#### Run integration tests with the native launcher
4959

5060
(generating the launcher can take several minutes)

build.sc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,24 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
855855
def test(args: String*) = {
856856
val argsTask = T.task {
857857
val launcher = launcherTask().path
858+
val debugReg = "^--debug$|^--debug:([0-9]+)$".r
859+
val debugPortOpt = args.find(debugReg.matches).flatMap {
860+
case debugReg(port) => Option(port).orElse(Some("5005"))
861+
case _ => None
862+
}
863+
val debugArgs = debugPortOpt match {
864+
case Some(port) =>
865+
System.err.println(
866+
s"--debug option has been passed. Listening for transport dt_socket at address: $port"
867+
)
868+
Seq(s"-Dtest.scala-cli.debug.port=$port")
869+
case _ => Seq.empty
870+
}
858871
val extraArgs = Seq(
859872
s"-Dtest.scala-cli.path=$launcher",
860873
s"-Dtest.scala-cli.kind=$cliKind"
861874
)
862-
args ++ extraArgs
875+
args ++ extraArgs ++ debugArgs
863876
}
864877
T.command {
865878
val res = testTask(argsTask, T.task(Seq.empty[String]))()

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ import scala.util.Properties
1212

1313
object TestUtil {
1414

15-
val cliKind: String = sys.props("test.scala-cli.kind")
16-
val isNativeCli: Boolean = cliKind.startsWith("native")
17-
val isCI: Boolean = System.getenv("CI") != null
18-
val cliPath: String = sys.props("test.scala-cli.path")
19-
val detectCliPath = if (TestUtil.isNativeCli) TestUtil.cliPath else "scala-cli"
20-
val cli: Seq[String] = cliCommand(cliPath)
15+
val cliKind: String = sys.props("test.scala-cli.kind")
16+
val isNativeCli: Boolean = cliKind.startsWith("native")
17+
val isCI: Boolean = System.getenv("CI") != null
18+
val cliPath: String = sys.props("test.scala-cli.path")
19+
val debugPortOpt: Option[String] = sys.props.get("test.scala-cli.debug.port")
20+
val detectCliPath = if (TestUtil.isNativeCli) TestUtil.cliPath else "scala-cli"
21+
val cli: Seq[String] = cliCommand(cliPath)
2122

2223
def cliCommand(cliPath: String): Seq[String] =
2324
if (isNativeCli)
2425
Seq(cliPath)
2526
else
26-
Seq("java", "-Xmx512m", "-Xms128m", "-jar", cliPath)
27+
debugPortOpt match {
28+
case Some(port) => Seq(
29+
"java",
30+
"-Xmx512m",
31+
"-Xms128m",
32+
s"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=$port,quiet=y",
33+
"-jar",
34+
cliPath
35+
)
36+
case _ => Seq("java", "-Xmx512m", "-Xms128m", "-jar", cliPath)
37+
}
2738

2839
// format: off
2940
val extraOptions: List[String] = List(

0 commit comments

Comments
 (0)