Skip to content

Commit

Permalink
Add --debug option for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wleczny committed Sep 20, 2022
1 parent 0294932 commit 8dba1da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 15 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,23 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
def test(args: String*) = {
val argsTask = T.task {
val launcher = launcherTask().path
val debugReg = "--debug(:[0-9]+)?".r
val debugOpt = args.filter(a => debugReg.pattern.matcher(a).matches).headOption
val (isDebug, debugPort) = debugOpt match {
case Some(opt: String) => opt.split(":", 2) match {
case Array(_, p) => (true, p)
case _ => (true, "5005")
}
case _ => (false, "")
}
if (isDebug) System.err.println(
"--debug option has been passed. Listening for transport dt_socket at address: 5005"
)
val extraArgs = Seq(
s"-Dtest.scala-cli.path=$launcher",
s"-Dtest.scala-cli.kind=$cliKind"
s"-Dtest.scala-cli.kind=$cliKind",
s"-Dtest.scala-cli.debug.is-debug=$isDebug",
s"-Dtest.scala-cli.debug.port=$debugPort"
)
args ++ extraArgs
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ object TestUtil {
val cliKind: String = sys.props("test.scala-cli.kind")
val isNativeCli: Boolean = cliKind.startsWith("native")
val isCI: Boolean = System.getenv("CI") != null
val isDebug: Boolean = sys.props("test.scala-cli.debug.is-debug") == "true"
val debugPort: String = sys.props("test.scala-cli.debug.port")
val cliPath: String = sys.props("test.scala-cli.path")
val detectCliPath = if (TestUtil.isNativeCli) TestUtil.cliPath else "scala-cli"
val cli: Seq[String] = cliCommand(cliPath)

def cliCommand(cliPath: String): Seq[String] =
if (isNativeCli)
Seq(cliPath)
else
Seq("java", "-Xmx512m", "-Xms128m", "-jar", cliPath)
else if (isDebug) Seq(
"java",
"-Xmx512m",
"-Xms128m",
s"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=$debugPort",
"-jar",
cliPath
)
else Seq("java", "-Xmx512m", "-Xms128m", "-jar", cliPath)

// format: off
val extraOptions: List[String] = List(
Expand Down

0 comments on commit 8dba1da

Please sign in to comment.