Skip to contentSkip to conversation

tests: shell: Avoid escape chars when printing to non-terminals

PATCH In review Phil Sutter 1 participant 2 messages Mar 23, 2024 – Apr 12, 2024 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 tests: shell: Avoid escape chars when printing to non-terminals

Print the 'EXECUTING' status line only if stdout is a terminal, the mandatory following escape sequence to delete it messes up log file contents.

---
 tests/shell/run-tests.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/shell/run-tests.sh +2 -2
index 86c8312683ccb..6a9b518c3aed5 100755
@@ -860,7 +860,7 @@ job_start() {
 	local testfile="$1"
 	local testidx="$2"
 
-	if [ "$NFT_TEST_JOBS" -le 1 ] ; then
+	if [ "$NFT_TEST_JOBS" -le 1 ] && [[ -t 1 ]]; then
 		print_test_header I "$testfile" "$testidx" "EXECUTING"
 	fi
 
@@ -873,7 +873,7 @@ job_start() {
 	$NFT_TEST_UNSHARE_CMD "$NFT_TEST_BASEDIR/helpers/test-wrapper.sh" "$testfile"
 	local rc_got=$?
 
-	if [ "$NFT_TEST_JOBS" -le 1 ] ; then
+	if [ "$NFT_TEST_JOBS" -le 1 ] && [[ -t 1 ]]; then
 		echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line
 	fi
 
Signature · 1 line
2.43.0
author reviewer
#1 lore raw
Quoted 5 lines · Phil Sutter

Print the 'EXECUTING' status line only if stdout is a terminal, the mandatory following escape sequence to delete it messes up log file contents.

Patch applied.