Skip to content

Commit 2b492e7

Browse files
committed
Fix stdin tests
1 parent bc82277 commit 2b492e7

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

Examples/stdin.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/swift sh
2+
3+
import ScriptSwift // KS1019/Script.swift ~> main
4+
5+
Script()
6+
.stdin()
7+
.map { "Received input: \($0). Test is working. Yay." }
8+
.stdout()

Scripts/ExamplesTest.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ swift sh --clean-cache
55
try () {
66
expected="$1"
77
script="$2"
8-
actual="$(swift sh "$script" 2>/dev/null)"
8+
args="$3"
9+
10+
if [ "$args" ]; then
11+
actual="$(echo "$args" | swift sh "$script" 2>/dev/null)"
12+
else
13+
actual="$(swift sh "$script" 2>/dev/null)"
14+
fi
915

1016
if [ "$actual" = "$expected" ]; then
1117
echo "\xE2\x9C\x94 Success $script"
@@ -65,3 +71,5 @@ html="<!doctype html>
6571
</html>"
6672

6773
try "$html" "../Examples/curl.swift"
74+
75+
try "Received input: hh. Test is working. Yay." "../Examples/stdin.swift" "hh"

Sources/ScriptSwift/Script.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public struct Script<T> {
2222
return .init(success: array.joined(separator: " "))
2323
}
2424

25-
public func stdin() -> Script<[String]> {
26-
guard let array: [String] = readLine()?.split(separator: " ").map({ s in String(s) }) else { return .init(success: []) }
27-
return .init(success: array)
28-
}
25+
// public func stdin() -> Script<[String]> {
26+
// guard let array: [String] = readLine()?.split(separator: " ").map({ s in String(s) }) else { return .init(success: []) }
27+
// return .init(success: array)
28+
// }
2929

3030
public func stdout() {
3131
switch input {

0 commit comments

Comments
 (0)