forked from sstephenson/bats
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for tests reading from stdin (sstephenson#227)
Fix for tests reading from stdin
- Loading branch information
Showing
5 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Fractional timeout supported in bash 4+ | ||
if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then | ||
timeout=1 | ||
else | ||
timeout=0.01 | ||
fi | ||
|
||
# Just reading from stdin | ||
while read -r -t $timeout foo; do | ||
if [ "$foo" == "EXIT" ]; then | ||
echo "Found" | ||
exit 0 | ||
fi | ||
done | ||
|
||
echo "Not found" | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "test 1" { | ||
# Don't print anything | ||
run bash -c "$BATS_TEST_DIRNAME/cmd_using_stdin.bash" | ||
[ "$status" -eq 1 ] | ||
[ "$output" = "Not found" ] | ||
} | ||
|
||
@test "test 2 with TAB in name" { | ||
run bash -c "echo EXIT | $BATS_TEST_DIRNAME/cmd_using_stdin.bash" | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "Found" ] | ||
} | ||
|
||
@test "test 3" { | ||
run bash -c "echo EXIT | $BATS_TEST_DIRNAME/cmd_using_stdin.bash" | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "Found" ] | ||
} |