Skip to content

Commit

Permalink
Modify shell environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloox committed Mar 31, 2021
1 parent 4792024 commit dcf6c38
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import flank.common.isLinux
import flank.common.isMacOS
import flank.common.isWindows
import ftl.util.Bash
import ftl.util.ShellEnvironment

internal fun parseSwiftTests(binary: String): List<String> {
installBinaries
Expand All @@ -28,7 +29,9 @@ internal fun parseSwiftTests(binary: String): List<String> {
} else emptyList()

// https://github.com/linkedin/bluepill/blob/37e7efa42472222b81adaa0e88f2bd82aa289b44/Source/Shared/BPXCTestFile.m#L17-18
val demangledOutput = Bash.execute(cmd, path)
val shell = if (isWindows) ShellEnvironment.Cmd else ShellEnvironment.Default

val demangledOutput = Bash.execute(cmd, path, shell)
demangledOutput.lines().forEach { line ->
// _T025EarlGreyExampleTestsSwift0abceD0C10testLayoutyyF ---> EarlGreyExampleTestsSwift.EarlGreyExampleSwiftTests.testLayout() -> ()
// _T025EarlGreyExampleTestsSwift0abceD0C16testCustomActionyyF ---> EarlGreyExampleTestsSwift.EarlGreyExampleSwiftTests.testCustomAction() -> ()
Expand Down
19 changes: 13 additions & 6 deletions test_runner/src/main/kotlin/ftl/util/Bash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import ftl.run.exception.FlankGeneralError
import java.lang.ProcessBuilder.Redirect.PIPE

object Bash {

fun execute(cmd: String, additionalPath: List<Pair<String, String>> = emptyList()): String {
fun execute(
cmd: String,
additionalPath: List<Pair<String, String>> = emptyList(),
shellEnvironment: ShellEnvironment = ShellEnvironment.Default
): String {
logLn(cmd)

val bashPath = if (isWindows) "bash.exe" else "/bin/bash"

val process = ProcessBuilder(bashPath, "-c", cmd).also {
val process = ProcessBuilder(shellEnvironment.execution, "-c", cmd).also {
if (additionalPath.isNotEmpty()) {
val envs: MutableMap<String, String> = it.environment()
additionalPath.forEach { extra ->
Expand All @@ -31,3 +31,10 @@ object Bash {
return result.stdout.trim() + result.stderr.trim()
}
}

sealed class ShellEnvironment(val execution: String) {
object Bash : ShellEnvironment("Bash.exe")
object BinBash : ShellEnvironment("/bin/bash")
object Cmd : ShellEnvironment("cmd.exe")
object Default : ShellEnvironment(if (isWindows) Bash.execution else BinBash.execution)
}

0 comments on commit dcf6c38

Please sign in to comment.