Skip to content

Commit

Permalink
Fix SubprocessStdoutTests on Windows (#3289)
Browse files Browse the repository at this point in the history
The `echo` command isn't standalone in Windows, so it has to be called
through `cmd.exe` for example.
Interestingly the `echo abc >&2` prints a space at the end of line,
while linux doesnt..

Pull request: #3289

---------

Co-authored-by: Tobias Roeser <le.petit.fou@web.de>
  • Loading branch information
sake92 and lefou committed Jul 24, 2024
1 parent c74a3fa commit dffc34f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 17 additions & 4 deletions integration/feature/subprocess-stdout/repo/build.sc
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import scala.util.Properties
import mill._


def inheritInterleaved = T {
for (i <- Range.inclusive(1, 9)) {
println("print stdout" + i)
os.proc("echo", "proc stdout" + i).call(stdout = os.Inherit)
val echoCommandStdout =
if (Properties.isWin) Seq("cmd.exe", "/C", s"echo proc stdout${i}")
else Seq("echo", s"proc stdout${i}")
os.proc(echoCommandStdout).call(stdout = os.Inherit)
System.err.println("print stderr" + i)
os.proc("bash", "-c", s"echo proc stderr${i} >&2").call(stderr = os.Inherit)
val echoCommandStderr =
if (Properties.isWin) Seq("cmd.exe", "/C", s"echo proc stderr${i}>&2")
else Seq("bash", "-c", s"echo proc stderr${i} >&2")
os.proc(echoCommandStderr).call(stderr = os.Inherit)
}
}

def inheritRaw = T{
println("print stdoutRaw")
os.proc("echo", "proc stdoutRaw").call(stdout = os.InheritRaw)
val echoCommandStdoutRaw =
if (Properties.isWin) Seq("cmd.exe", "/C", "echo proc stdoutRaw")
else Seq("echo", "proc stdoutRaw")
os.proc(echoCommandStdoutRaw).call(stdout = os.InheritRaw)
System.err.println("print stderrRaw")
os.proc("bash", "-c", "echo proc stderrRaw >&2").call(stderr = os.InheritRaw)
val echoCommandStderrRaw =
if (Properties.isWin) Seq("cmd.exe", "/C", "echo proc stderrRaw>&2")
else Seq("bash", "-c", "echo proc stderrRaw >&2")
os.proc(echoCommandStderrRaw).call(stderr = os.InheritRaw)
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object SubprocessStdoutTests extends IntegrationTestSuite {
|print stdout9
|proc stdout9
|print stderr9
|proc stderr9""".stripMargin
|proc stderr9""".stripMargin.replaceAll("\r\n", "\n")
)
)

Expand All @@ -66,7 +66,7 @@ object SubprocessStdoutTests extends IntegrationTestSuite {
"""print stdoutRaw
|proc stdoutRaw
|print stderrRaw
|proc stderrRaw""".stripMargin
|proc stderrRaw""".stripMargin.replaceAll("\r\n", "\n")
)
)
} else {
Expand All @@ -77,7 +77,7 @@ object SubprocessStdoutTests extends IntegrationTestSuite {
"""print stdoutRaw
|print stderrRaw
|proc stdoutRaw
|proc stderrRaw""".stripMargin.linesIterator.toSet.subsetOf(
|proc stderrRaw""".stripMargin.replaceAll("\r\n", "\n").linesIterator.toSet.subsetOf(
res2.linesIterator.toSet
)
)
Expand Down

0 comments on commit dffc34f

Please sign in to comment.