diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-12-14 12:20:18 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-12-14 12:25:07 -0500 |
commit | 0074d5b0c064dbf6cfc7231fc5b74659d81b120e (patch) | |
tree | a09a0fb52762b50b0ddd6e21c1a0c139cd318948 /tests/tests.sh | |
parent | f21a9340cd0c615ead1954eb6b93845a4f8c0897 (diff) | |
download | bfs-0074d5b0c064dbf6cfc7231fc5b74659d81b120e.tar.xz |
tests: Fix crash when stderr is redirected
bash uses fileno(stderr) to keep track of $COLUMNS. With stderr
redirected, $COLUMNS will be unset, leading to
$ ./tests/tests.sh 2> >(cat)
./tests/tests.sh: line 635: COLUMNS: unbound variable
Fix it by using $(tput cols) if $COLUMNS is unset, which is almost
POSIX.
Link: https://www.austingroupbugs.net/view.php?id=1053
Diffstat (limited to 'tests/tests.sh')
-rwxr-xr-x | tests/tests.sh | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tests/tests.sh b/tests/tests.sh index 639822a..3fdf49b 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -630,9 +630,15 @@ BOL='\n' EOL='\n' function update_eol() { + # Bash gets $COLUMNS from stderr, so if it's redirected use tput instead + local cols="${COLUMNS-}" + if [ -z "$cols" ]; then + cols=$(tput cols) + fi + # Put the cursor at the last column, then write a space so the next # character will wrap - EOL="\\033[${COLUMNS}G " + EOL="\\033[${cols}G " } if [ "$VERBOSE_TESTS" ]; then |