[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix SystemProcessTest to not require presence of echo program on …
Browse files Browse the repository at this point in the history
…Windows. (enso-org#3152)

Co-authored-by: Dmitry Bushev <bushevdv@gmail.com>
  • Loading branch information
mwu-tow and 4e6 committed Nov 16, 2021
1 parent 93f7362 commit 361882b
Showing 1 changed file with 91 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
interpreterContext: InterpreterContext
): Unit = {

"return success exit code" in {
"return success exit code (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
|
Expand All @@ -29,6 +29,19 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"return success exit code (Windows)" taggedAs OsWindows in {
val code =
"""from Standard.Builtins import all
|
|main =
| result = System.create_process "cmd" (Array.new_1 "/c") "" False False False
| result.exit_code
|""".stripMargin
eval(code) shouldEqual 0
consumeOut shouldEqual List()
consumeErr shouldEqual List()
}

"return error when creating nonexistent command" in {
val code =
"""from Standard.Builtins import all
Expand All @@ -41,7 +54,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"return error exit code" in {
"return error exit code (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
|
Expand All @@ -55,6 +68,20 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"return error exit code (Windows)" taggedAs OsWindows in {
val code =
"""from Standard.Builtins import all
|
|main =
| result = System.create_process "cmd" (Array.new_2 "/c" "exit 7") "" False False False
| result.exit_code
|""".stripMargin

eval(code) shouldEqual 7
consumeOut shouldEqual List()
consumeErr shouldEqual List()
}

"redirect stdin chars (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
Expand Down Expand Up @@ -101,7 +128,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"redirect stdin unused" in {
"redirect stdin unused (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
|
Expand All @@ -116,7 +143,22 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"redirect stdin empty" in {
"redirect stdin unused (Windows)" taggedAs OsWindows in {
val code =
"""from Standard.Builtins import all
|
|main =
| result = System.create_process "cmd" (Array.new_2 "/c" "echo 9") "" True True True
| result.exit_code
|""".stripMargin

feedInput("unused input")
eval(code) shouldEqual 0
consumeOut shouldEqual List("9")
consumeErr shouldEqual List()
}

"redirect stdin empty (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
|
Expand All @@ -130,6 +172,20 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"redirect stdin empty (Windows)" taggedAs OsWindows in {
val code =
"""from Standard.Builtins import all
|
|main =
| result = System.create_process "cmd" (Array.new_2 "/c" "echo 9") "" True True True
| result.exit_code
|""".stripMargin

eval(code) shouldEqual 0
consumeOut shouldEqual List("9")
consumeErr shouldEqual List()
}

"provide stdin string (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
Expand Down Expand Up @@ -158,7 +214,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"redirect stdout chars" in {
"redirect stdout chars (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
|
Expand All @@ -172,6 +228,20 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"redirect stdout chars (Windows)" taggedAs OsWindows in {
val code =
"""from Standard.Builtins import all
|
|main =
| result = System.create_process "cmd" (Array.new_2 "/c" "echo foobar") "" False True True
| result.exit_code
|""".stripMargin

eval(code) shouldEqual 0
consumeOut shouldEqual List("foobar")
consumeErr shouldEqual List()
}

"redirect stdout binary (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
Expand All @@ -186,7 +256,7 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErrBytes shouldEqual Array()
}

"return stdout string" in {
"return stdout string (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
|
Expand All @@ -201,6 +271,21 @@ class SystemProcessTest extends InterpreterTest with OsSpec {
consumeErr shouldEqual List()
}

"return stdout string (Windows)" taggedAs OsWindows in {
val code =
"""from Standard.Builtins import all
|
|main =
| result = System.create_process "cmd" (Array.new_2 "/c" "echo foobar") "" False False False
| result.stdout
|""".stripMargin

val result = eval(code).asString().replace("\r\n","\n")
result shouldEqual "foobar\n"
consumeOut shouldEqual List()
consumeErr shouldEqual List()
}

"redirect stderr chars (Unix)" taggedAs OsUnix in {
val code =
"""from Standard.Builtins import all
Expand Down

0 comments on commit 361882b

Please sign in to comment.