Skip to contentSkip to conversation

lib/tst_test.sh: fix ROD_SILENT command return status check

PATCH New Alexey Kodanev 2 participants 3 messages Aug 19, 2021 – Aug 20, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/tst_test.sh: fix ROD_SILENT command return status check

"local tst_out=$(some_command)" always returns status 0, i.e. not the return status of the command in the assignment, but the status for 'local' builtin command, which creates a new local variable inside the function.

As a result, the library calls and tests that invoke ROD_SILENT don't actually check the return status of commands passed to it.

The old API library function is also fixed.

---
 testcases/lib/test.sh     | 4 +++-
 testcases/lib/tst_test.sh | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
testcases/lib/test.sh +3 -1
index 92278d7aa..8947f47c1 100644
@@ -233,7 +233,9 @@ tst_timeout()
 
 ROD_SILENT()
 {
-	local tst_out="$($@ 2>&1)"
+	local tst_out
+
+	tst_out="$($@ 2>&1)"
 	if [ $? -ne 0 ]; then
 		echo "$tst_out"
 		tst_brkm TBROK "$@ failed"
testcases/lib/tst_test.sh +3 -1
index c6aa2c487..3710c857e 100644
@@ -126,7 +126,9 @@ tst_brk()
 
 ROD_SILENT()
 {
-	local tst_out="$(tst_rod $@ 2>&1)"
+	local tst_out
+
+	tst_out="$(tst_rod $@ 2>&1)"
 	if [ $? -ne 0 ]; then
 		echo "$tst_out"
 		tst_brk TBROK "$@ failed"
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 lib/tst_test.sh: fix ROD_SILENT command return status check

Hi Alexey,

Quoted 7 lines

"local tst_out=$(some_command)" always returns status 0, i.e. not the return status of the command in the assignment, but the status for 'local' builtin command, which creates a new local variable inside the function.

As a result, the library calls and tests that invoke ROD_SILENT don't actually check the return status of commands passed to it.

Very good catch, thanks!

Working the same in: bash, dash, busybox sh, mksh (android).

Quoted 1 line

The old API library function is also fixed.

+1

Kind regards,
Petr

author Applied
#2 lore raw

PATCH 1/1 lib/tst_test.sh: fix ROD_SILENT command return status check

Quoted 10 lines · Petr Vorel

Hi Alexey,

Quoted 7 lines

"local tst_out=$(some_command)" always returns status 0, i.e. not the return status of the command in the assignment, but the status for 'local' builtin command, which creates a new local variable inside the function.

As a result, the library calls and tests that invoke ROD_SILENT don't actually check the return status of commands passed to it.

Quoted 9 lines

Very good catch, thanks!

Working the same in: bash, dash, busybox sh, mksh (android).

Quoted 1 line

The old API library function is also fixed.

+1

Applied. Thanks Petr!