From 0074d5b0c064dbf6cfc7231fc5b74659d81b120e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 14 Dec 2022 12:20:18 -0500 Subject: 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 --- tests/tests.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/tests.sh') 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 -- cgit v1.2.3