tests: Fix warnings reported by shellcheck

This commit includes following fixes for a few shell scripts:

1. Follow the best practice of quoting variables everywhere unless they
   are used in places where word-splitting and globbing can never happen.

2. Replace `command` with $(command) because the latter is easier to use
   and read.

3. Don't use "$@" in places expecting a string because it is an array
   of strings instead of a single string.
This commit is contained in:
Ting-Wei Lan 2018-12-01 13:48:38 +08:00 committed by Georges Basile Stavracas Neto
parent b2e75b5da0
commit 319500e4f3
4 changed files with 45 additions and 46 deletions

View File

@ -2,14 +2,13 @@
outputfile=$1 outputfile=$1
shift shift
test_source_files="$@"
echo '/* ** This file is autogenerated. Do not edit. ** */' > $outputfile echo '/* ** This file is autogenerated. Do not edit. ** */' > "$outputfile"
echo '' >> $outputfile echo '' >> "$outputfile"
echo 'const char *test_unit_names[] = {' >> $outputfile echo 'const char *test_unit_names[] = {' >> "$outputfile"
for test_source_file in $test_source_files; do for test_source_file in "$@"; do
echo " \"$(echo $test_source_file | sed 's/.*\(test-[a-z0-9\-]\+\)\.c/\1/')\"," >> $outputfile echo " \"$(echo "$test_source_file" | sed 's/.*\(test-[a-z0-9\-]\+\)\.c/\1/')\"," >> "$outputfile"
done done
echo '};' >> $outputfile echo '};' >> "$outputfile"

View File

@ -5,6 +5,6 @@ outputfile="$2"
echo > "$outputfile" echo > "$outputfile"
sed -n -e 's/^ \{1,\}ADD_TEST *( *\([a-zA-Z0-9_]\{1,\}\).*/\1/p' "$1" | while read test; do sed -n -e 's/^ \{1,\}ADD_TEST *( *\([a-zA-Z0-9_]\{1,\}\).*/\1/p' "$inputfile" | while read -r test; do
echo $test >> $outputfile echo "$test" >> "$outputfile"
done done

View File

@ -17,7 +17,7 @@ shift
UNIT_TESTS_FILE=$1 UNIT_TESTS_FILE=$1
shift shift
. $ENVIRONMENT_CONFIG . "$ENVIRONMENT_CONFIG"
set +m set +m
@ -65,35 +65,35 @@ get_status()
run_test() run_test()
{ {
$($TEST_BINARY $1 &>.log) "$TEST_BINARY" "$1" &>.log
TMP=$? TMP=$?
var_name=$2_result var_name=$2_result
eval $var_name=$TMP eval "$var_name=$TMP"
if grep -q "$MISSING_FEATURE" .log; then if grep -q "$MISSING_FEATURE" .log; then
if test $TMP -ne 0; then if test "$TMP" -ne 0; then
eval $var_name=500 eval "$var_name=500"
else else
eval $var_name=400 eval "$var_name=400"
fi fi
elif grep -q "$KNOWN_FAILURE" .log; then elif grep -q "$KNOWN_FAILURE" .log; then
if test $TMP -ne 0; then if test $TMP -ne 0; then
eval $var_name=300 eval "$var_name=300"
else else
eval $var_name=400 eval "$var_name=400"
fi fi
else else
if test $TMP -ne 0; then EXIT=$TMP; fi if test "$TMP" -ne 0; then EXIT=$TMP; fi
fi fi
} }
TITLE_FORMAT="%35s" TITLE_FORMAT="%35s"
printf $TITLE_FORMAT "Test" printf "$TITLE_FORMAT" "Test"
if test $HAVE_GL -eq 1; then if test "$HAVE_GL" -eq 1; then
GL_FORMAT=" %6s %8s %7s %6s %6s" GL_FORMAT=" %6s %8s %7s %6s %6s"
printf "$GL_FORMAT" "GL+GLSL" "GL-NPT" "GL3" printf "$GL_FORMAT" "GL+GLSL" "GL-NPT" "GL3"
fi fi
if test $HAVE_GLES2 -eq 1; then if test "$HAVE_GLES2" -eq 1; then
GLES2_FORMAT=" %6s %7s" GLES2_FORMAT=" %6s %7s"
printf "$GLES2_FORMAT" "ES2" "ES2-NPT" printf "$GLES2_FORMAT" "ES2" "ES2-NPT"
fi fi
@ -101,59 +101,59 @@ fi
echo "" echo ""
echo "" echo ""
if [ ! -f $UNIT_TESTS_FILE ]; then if [ ! -f "$UNIT_TESTS_FILE" ]; then
echo Missing unit-tests file echo Missing unit-tests file
exit 1 exit 1
fi fi
for test in `cat $UNIT_TESTS_FILE` for test in $(cat "$UNIT_TESTS_FILE")
do do
export COGL_DEBUG= export COGL_DEBUG=
if test $HAVE_GL -eq 1; then if test "$HAVE_GL" -eq 1; then
export COGL_DRIVER=gl export COGL_DRIVER=gl
# NB: we can't explicitly disable fixed + glsl in this case since # NB: we can't explicitly disable fixed + glsl in this case since
# the arbfp code only supports fragment processing so we need either # the arbfp code only supports fragment processing so we need either
# the fixed or glsl vertends # the fixed or glsl vertends
export COGL_DEBUG= export COGL_DEBUG=
run_test $test gl_arbfp run_test "$test" gl_arbfp
export COGL_DRIVER=gl export COGL_DRIVER=gl
export COGL_DEBUG=disable-fixed,disable-arbfp export COGL_DEBUG=disable-fixed,disable-arbfp
run_test $test gl_glsl run_test "$test" gl_glsl
export COGL_DRIVER=gl export COGL_DRIVER=gl
export COGL_DEBUG=disable-npot-textures export COGL_DEBUG=disable-npot-textures
run_test $test gl_npot run_test "$test" gl_npot
export COGL_DRIVER=gl3 export COGL_DRIVER=gl3
export COGL_DEBUG= export COGL_DEBUG=
run_test $test gl3 run_test "$test" gl3
fi fi
if test $HAVE_GLES2 -eq 1; then if test "$HAVE_GLES2" -eq 1; then
export COGL_DRIVER=gles2 export COGL_DRIVER=gles2
export COGL_DEBUG= export COGL_DEBUG=
run_test $test gles2 run_test "$test" gles2
export COGL_DRIVER=gles2 export COGL_DRIVER=gles2
export COGL_DEBUG=disable-npot-textures export COGL_DEBUG=disable-npot-textures
run_test $test gles2_npot run_test "$test" gles2_npot
fi fi
printf $TITLE_FORMAT "$test:" printf $TITLE_FORMAT "$test:"
if test $HAVE_GL -eq 1; then if test "$HAVE_GL" -eq 1; then
printf "$GL_FORMAT" \ printf "$GL_FORMAT" \
"`get_status $gl_glsl_result`" \ "$(get_status "$gl_glsl_result")" \
"`get_status $gl_npot_result`" \ "$(get_status "$gl_npot_result")" \
"`get_status $gl3_result`" "$(get_status "$gl3_result")"
fi fi
if test $HAVE_GLES2 -eq 1; then if test "$HAVE_GLES2" -eq 1; then
printf "$GLES2_FORMAT" \ printf "$GLES2_FORMAT" \
"`get_status $gles2_result`" \ "$(get_status "$gles2_result")" \
"`get_status $gles2_npot_result`" "$(get_status "$gles2_npot_result")"
fi fi
echo "" echo ""
done done
exit $EXIT exit "$EXIT"

View File

@ -9,20 +9,20 @@ shift
UNIT_TEST=$1 UNIT_TEST=$1
shift shift
test -z ${UNIT_TEST} && { test -z "${UNIT_TEST}" && {
echo "Usage: $0 UNIT_TEST" echo "Usage: $0 UNIT_TEST"
exit 1 exit 1
} }
BINARY_NAME=`basename $TEST_BINARY` BINARY_NAME=$(basename "$TEST_BINARY")
UNIT_TEST=`echo $UNIT_TEST|sed 's/-/_/g'` UNIT_TEST=$(echo "$UNIT_TEST"|sed 's/-/_/g')
echo "Running: ./$BINARY_NAME ${UNIT_TEST} $@" echo "Running: ./$BINARY_NAME ${UNIT_TEST} $*"
echo "" echo ""
COGL_TEST_VERBOSE=1 $TEST_BINARY ${UNIT_TEST} "$@" COGL_TEST_VERBOSE=1 "$TEST_BINARY" "${UNIT_TEST}" "$@"
exit_val=$? exit_val=$?
if test $exit_val -eq 0; then if test "$exit_val" -eq 0; then
echo "OK" echo "OK"
fi fi
@ -36,4 +36,4 @@ echo "$ env G_SLICE=always-malloc \\"
echo " libtool --mode=execute \\" echo " libtool --mode=execute \\"
echo " valgrind ./$BINARY_NAME ${UNIT_TEST}" echo " valgrind ./$BINARY_NAME ${UNIT_TEST}"
exit $exit_val exit "$exit_val"