[libvirt] [PATCH] tests: use portable shell code

Eric Blake eblake at redhat.com
Thu May 9 17:46:32 UTC 2013


'make check' fails since commit 470d5c46 on any system with dash
as /bin/sh, because '<<<' is a bash extension.  For example:

nwfilterschematest: 23: /home/eblake/libvirt/tests/schematestutils.sh: Syntax error: redirection unexpected

Also, there is no need to spawn a grep process when shell globbing
can do the same.

* tests/schematestutils.sh: Replace bashism and subprocess with a
faster and portable construct.

Signed-off-by: Eric Blake <eblake at redhat.com>
---

Pushing under the build-breaker rule.

 tests/schematestutils.sh | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/tests/schematestutils.sh b/tests/schematestutils.sh
index e739b99..e594f04 100644
--- a/tests/schematestutils.sh
+++ b/tests/schematestutils.sh
@@ -20,18 +20,12 @@ do
     result=`$cmd 2>&1`
     ret=$?

-    grep -- '-invalid.xml$' <<< "$xml" 2>&1 >/dev/null
-    invalid=$?
-
-    # per xmllint man page, the return codes for validation error
-    # are 3 and 4
-    if test $invalid -eq 0; then
-        if test $ret -eq 4 || test $ret -eq 3; then
-            ret=0
-        elif test $ret -eq 0; then
-            ret=3
-        fi
-    fi
+    # Alter ret if error was expected.
+    case $xml:$ret in
+        *-invalid.xml:[34]) ret=0 ;;
+        *-invalid.xml:0)    ret=3 ;;
+    esac
+
     test_result $n $(basename $(dirname $xml))"/"$(basename $xml) $ret
     if test "$verbose" = "1" && test $ret != 0 ; then
         printf '%s\n' "$cmd" "$result"
-- 
1.8.1.4




More information about the libvir-list mailing list