Skip to content

Commit

Permalink
Implement STDIN isolation among tests (#43)
Browse files Browse the repository at this point in the history
Isolate STDIN among tests and among a test and clitest itself.

This fixes the bug reported on issue #42 in which tests and clitest share STDIN,
causing unexpected results when the command specified on a test reads from
STDIN.
  • Loading branch information
vmmello authored Jul 29, 2020
1 parent da9d01d commit 78f17f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clitest
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ tt_run_test() {
tt_debug EVAL "$tt_test_command"

# Execute the test command, saving output (STDOUT and STDERR)
eval "$tt_test_command" > "$tt_test_output_file" 2>&1
eval "$tt_test_command" > "$tt_test_output_file" 2>&1 < /dev/null
tt_test_exit_code=$?

tt_debug OUTPUT "$(cat "$tt_test_output_file")"
Expand Down
8 changes: 8 additions & 0 deletions test.md
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,14 @@ OK: 10 of 10 tests passed
$
```
STDIN Isolation
```
$ ./clitest --quiet test/stdin-isolation.sh ; echo $?
0
$
```
Multiple commands in one line
```
Expand Down
12 changes: 12 additions & 0 deletions test/stdin-isolation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# This was a bug found on early versions of clitest in which tests shared
# STDIN with clitest and with each other, causing unexpected results when
# a test read from STDIN. This was reported on issue #42 on Github.
#
# Testing for a regression.
#

$ echo testing stdin isolation ; read stdin_isolation
testing stdin isolation
$ echo Failed\? Regression to stdin isolation added. ; unset stdin_isolation
Failed? Regression to stdin isolation added.

0 comments on commit 78f17f6

Please sign in to comment.