On 09/23/2013 06:09 AM, Max Reitz wrote:
In _img_info, filter out additional information specific to the image
format provided by qemu-img info, since tests designed for multiple
image formats would produce different outputs for every image format
else.
s/else/otherwise/
Signed-off-by: Max Reitz <address@hidden>
---
tests/qemu-iotests/common.rc | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 28b39e4..12d8882 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -181,12 +181,29 @@ _check_test_img()
_img_info()
{
+ discard=0
$QEMU_IMG info "$@" $TEST_IMG 2>&1 | \
sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
-e "s#$TEST_DIR#TEST_DIR#g" \
-e "s#$IMGFMT#IMGFMT#g" \
-e "/^disk size:/ D" \
- -e "/actual-size/ D"
+ -e "/actual-size/ D" | \
+ while IFS='' read line; do
+ if [ "$line" == "Format specific information:" ]; then
[ ... == ...] is a bashism (thank goodness this is already a bash
script); but I generally prefer you either stick to portable syntax:
if [ "$line" = "Format specific information:" ]
or make it obvious that you know you are using bash:
if [[ $line == "Format specific information:" ]]
+ discard=1
+ elif [ "`echo "$line" | sed -e 's/^ *//'`" == '"format-specific":
{' ]; then
Use $(), not ``.
This script is already a bash script; why not exploit that and avoid a fork:
elif [[ $line =~ '"format-specific": {' ]]
+ discard=2
+ json_indent="`echo "$line" | sed -e 's/^\( *\).*$/\1/'`"
Use $(), not ``.
Exploit bash to avoid a fork:
json_indent=${line%%[! ]*}
+ fi
+ if [ $discard == 0 ]; then
Again, I don't like the bashism of [ == ].
+ echo "$line"
+ elif [ $discard == 1 -a -z "$line" ]; then
[ ... -a ... ] is flat out non-portable. Even when you are already
requiring bash. For example:
[ "$str1" -a "$str2" ]
gives status 0 for most pairs of non-empty strings, but could give
status 1 for str1="!" and str2=".". Using a bashism, on the other hand,
is unambiguous:
elif [[ $discard == 1 && ! $line ]]