Skip to content

Commit c87ffec

Browse files
authored
Fix - scripts accept as piped inout (#144)
1 parent 7f09e6e commit c87ffec

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

modules/build/src/main/scala/scala/build/Inputs.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,12 @@ object Inputs {
233233
lazy val dir = path / os.up
234234
lazy val subPath = path.subRelativeTo(dir)
235235
lazy val stdinOpt0 = stdinOpt
236-
val isStdin = (arg == "-" || arg == "-.scala" || arg == "_" || arg == "_.scala") &&
236+
val isStdin = (arg == "-.scala" || arg == "_" || arg == "_.scala") &&
237237
stdinOpt0.nonEmpty
238238
if (isStdin) Right(Seq(VirtualScalaFile(stdinOpt0.get, "<stdin>")))
239-
else if ((arg == "-.sc" || arg == "_.sc") && stdinOpt0.nonEmpty)
240-
Right(Seq(VirtualScript(stdinOpt0.get, "<stdin>", os.sub / "stdin.sc")))
239+
else if ((arg == "-" || arg == "-.sc" || arg == "_.sc") && stdinOpt0.nonEmpty) {
240+
Right(Seq(VirtualScript(stdinOpt0.get, "stdin", os.sub / "stdin.sc")))
241+
}
241242
else if (arg.contains("://")) {
242243
val url =
243244
if (githubGistsArchiveRegex.findFirstMatchIn(arg).nonEmpty) s"$arg/download" else arg

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,21 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
611611
}
612612
}
613613

614-
if (!Properties.isWin)
614+
if (!Properties.isWin) {
615615
test("piping") {
616616
piping()
617617
}
618+
test("Scripts accepted as piped input") {
619+
val message = "Hello"
620+
val input = s"println(\"$message\")"
621+
emptyInputs.fromRoot { root =>
622+
val output = os.proc(TestUtil.cli, "-", extraOptions)
623+
.call(cwd = root, stdin = input)
624+
.out.text.trim
625+
expect(output == message)
626+
}
627+
}
628+
}
618629

619630
def fd(): Unit = {
620631
emptyInputs.fromRoot { root =>

0 commit comments

Comments
 (0)