Skip to content

Commit

Permalink
preserve/restore TTY attributes in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandwalker committed Aug 17, 2017
1 parent aa4b1ac commit 56f7434
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/tools/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ output_dir="$base_dir/tmp/$prefix_dir/$test"
tmp_dir="$base_dir/tmp"
output_dir="$tmp_dir/$prefix_dir/$test"
work_dir="work dir"
tty_attrs="$(stty -g </dev/tty)"

# The locale must specify UTF-8 for Ncurses to output correctly. Since C.UTF-8
# does not exist on Mac OS X, we end up with en_US as the only sane choice.
Expand Down Expand Up @@ -362,7 +363,7 @@ show_test_results()
fi | sed "s/^/$indent| /"
}

trap 'show_test_results' EXIT
trap "stty '$tty_attrs' </dev/tty; show_test_results" EXIT

test_skip()
{
Expand Down Expand Up @@ -534,6 +535,7 @@ test_tig()
(
# subshell handles cleanup of cwd, variables, redirections, set +e
cd "$work_dir" || die "chdir failed"
stty "$tty_attrs" </dev/tty
if [ -n "$debugger" ]; then
printf "*** Running tests in '%s/%s'\n" "$HOME" "$work_dir"
if [ -s "$HOME/${prefix}stdin" ]; then
Expand Down Expand Up @@ -565,6 +567,7 @@ test_tig()
wait "$tig_pid"
fi
status_code="$?"
stty "$tty_attrs" </dev/tty
if [ "$status_code" -eq "$(( 256 + signal))" ] || [ "$status_code" -eq "$(( 128 + signal))" ]; then
printf '[FAIL] Test timed out after %s seconds\n' "$timeout" >> "$HOME/.test-result"
elif [ "$status_code" != "$expected_status_code" ]; then
Expand Down

0 comments on commit 56f7434

Please sign in to comment.