Skip to content

Commit

Permalink
use files
Browse files Browse the repository at this point in the history
  • Loading branch information
ezrizhu committed Sep 6, 2024
1 parent ef2f1f1 commit 8601a70
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions test/stdstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ EOF

chmod +x "$cmdfile"

# test stdout
result=$(echo 5 | "$TRY" "$cmdfile" 2>/dev/null)
expected=$(echo 5 | sh "$cmdfile" 2>/dev/null)

[ "$result" = "$expected" ] || exit 1
try_stdout=$(mktemp)
try_stderr=$(mktemp)
sh_stdout=$(mktemp)
sh_stderr=$(mktemp)

# test stdout + stderr
result=$(echo 5 | "$TRY" "$cmdfile" 2>&1)
# test stdout
echo 5 | "$TRY" "$cmdfile" >$try_stdout 2>$try_stderr
echo 5 | sh "$cmdfile" >$sh_stdout 2>$sh_stderr

# using grep because stdout also includes try err/warns
echo "$result" | grep 15 > /dev/null
diff $try_stdout $sh_stdout || exit 1
diff $try_stderr $sh_stderr || exit 1
rm $try_stdout $try_stderr $sh_stdout $sh_stderr

0 comments on commit 8601a70

Please sign in to comment.