Skip to content

Commit c98f0d2

Browse files
committed
Rework command-line-settings tests
* The original test only coincidentally passed because the broken arg parsing didn't actually modify the command-line: * The -D argument _should_ have been consumed during argument parsing, but wasn't, so remained in residual. * The test app would not have outputted the -D argument had argument parsing been working, since it only output the app args, not the system properties. * There is now a specific test each for the system properties and the residual args. Signed-off-by: Greg Symons <[email protected]>
1 parent 4398779 commit c98f0d2

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/sbt-test/ash/command-line-settings/build.sbt

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ name := "command-line-app"
44

55
version := "0.1.0-SNAPSHOT"
66

7-
TaskKey[Unit]("runCheck") := {
8-
val configArg = "-Dconfig.resource=/config.conf"
7+
TaskKey[Unit]("checkSystemProperty") := {
8+
val configArg = "config.resource=/config.conf"
99
val cwd = (stagingDirectory in Universal).value
10-
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, configArg)
10+
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, s"-D$configArg")
1111

1212
val output = (sys.process.Process(cmd, cwd).!!).replaceAll("\n", "")
13-
assert(output.contains(configArg), s"Application did not receive command line configuration resource $configArg")
13+
assert(output.contains(configArg), s"Application did not receive system property arg '$configArg'")
14+
}
15+
16+
TaskKey[Unit]("checkResidual") := {
17+
val arg = "residualArg"
18+
val cwd = (stagingDirectory in Universal).value
19+
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, arg)
20+
21+
val output = (sys.process.Process(cmd, cwd).!!).replaceAll("\n", "")
22+
assert(output.contains(arg), s"Application did not receive residual arg '$arg'")
1423
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
object MainApp extends App {
1+
object MainApp extends App {
2+
println(sys.props.collect { case (k, v) => s"$k=$v" } mkString "\n")
23
println(args.mkString("|"))
34
}
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Run the staging and check the script.
22
> stage
33
$ exists target/universal/stage/bin/command-line-app
4-
> runCheck
4+
> checkSystemProperty
5+
> checkResidual

0 commit comments

Comments
 (0)