Skip to contentSkip to conversation

Remove another bashism from run_tests.sh

dtc Applied David Gibson 3 participants 3 messages Aug 30, 2010 – Sep 20, 2010

lore
Share & tools
lore
#0 lore raw

Current we check for various error codes with [ $x == "NN" ]. However '==' is not actually a correct operator for the [ (test) command. It should be either '=' for string comparison or '-eq' for integer comparison. It appears that the bash builtin version of test implements '==' though, so we were getting away with it, as long as /bin/sh was bash - or the testsuite generated no errors.

This patch fixes the usage of test so that it should work on non-bash shells.

tests/run_tests.sh +3 -3
Index: dtc/tests/run_tests.sh
===================================================================
@@ -24,11 +24,11 @@ base_run_test() {
 	tot_pass=$((tot_pass + 1))
     else
 	ret="$?"
-	if [ "$ret" == "1" ]; then
+	if [ "$ret" -eq 1 ]; then
 	    tot_config=$((tot_config + 1))
-	elif [ "$ret" == "2" ]; then
+	elif [ "$ret" -eq 2 ]; then
 	    tot_fail=$((tot_fail + 1))
-	elif [ "$ret" == "$VGCODE" ]; then
+	elif [ "$ret" -eq $VGCODE ]; then
 	    tot_vg=$((tot_vg + 1))
 	else
 	    tot_strange=$((tot_strange + 1))
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Acked-by
#1 lore raw
Quoted 32 lines · David Gibson

Current we check for various error codes with [ $x == "NN" ]. However '==' is not actually a correct operator for the [ (test) command. It should be either '=' for string comparison or '-eq' for integer comparison. It appears that the bash builtin version of test implements '==' though, so we were getting away with it, as long as /bin/sh was bash - or the testsuite generated no errors.

This patch fixes the usage of test so that it should work on non-bash shells.

Index: dtc/tests/run_tests.sh
===================================================================

tests/run_tests.sh 2010-08-30 12:43:34.741770203 +1000 renamed from tests/run_tests.sh 2010-08-30 12:43:03.133784380 +1000 +0 -0
@@ -24,11 +24,11 @@ base_run_test() {
 tot_pass=$((tot_pass + 1))

else
ret="$?"
- if [ "$ret" == "1" ]; then
+ if [ "$ret" -eq 1 ]; then
tot_config=$((tot_config + 1))
- elif [ "$ret" == "2" ]; then
+ elif [ "$ret" -eq 2 ]; then
tot_fail=$((tot_fail + 1))
- elif [ "$ret" == "$VGCODE" ]; then
+ elif [ "$ret" -eq $VGCODE ]; then
tot_vg=$((tot_vg + 1))
else
tot_strange=$((tot_strange + 1))

Quoted 9 lines

--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_!
http://www.ozlabs.org/~dgibson
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

Applied
#2 lore raw
In reply to David Gibson
Quoted 11 lines

Current we check for various error codes with [ $x == "NN" ]. However '==' is not actually a correct operator for the [ (test) command. It should be either '=' for string comparison or '-eq' for integer comparison. It appears that the bash builtin version of test implements '==' though, so we were getting away with it, as long as /bin/sh was bash - or the testsuite generated no errors.

This patch fixes the usage of test so that it should work on non-bash shells.

Applied. Sorry for the delay.

Thanks,
jdl