mirror of
https://github.com/json-c/json-c.git
synced 2026-11-08 06:30:17 +08:00
Add a shellcheck test, fix or ignore all warnings reported by shellcheck.
This commit is contained in:
1 parent
5a79fb68c2
commit
8f191846d5
21 files changed
+163
-94
No files matched your search
@@ -39,7 +39,9 @@ set(ALL_TEST_NAMES
|
||||
test_visit
|
||||
test_object_iterator)
|
||||
|
||||
set(NOBUILD_TEST_NAMES "")
|
||||
set(NOBUILD_TEST_NAMES
|
||||
shellcheck
|
||||
)
|
||||
if (BUILD_APPS)
|
||||
set(NOBUILD_TEST_NAMES ${NOBUILD_TEST_NAMES} test_json_parse_cli)
|
||||
endif()
|
||||
|
||||
+21
-7
@@ -8,6 +8,8 @@ test_lib = static_library(
|
||||
install: false,
|
||||
)
|
||||
|
||||
fs = import('fs')
|
||||
|
||||
test_deps = declare_dependency(
|
||||
include_directories: '..',
|
||||
link_with: test_lib,
|
||||
@@ -15,6 +17,7 @@ test_deps = declare_dependency(
|
||||
|
||||
# List of test sources and expected output files
|
||||
test_cases = [
|
||||
['shellcheck.test'],
|
||||
['test1', 'test1.expected'],
|
||||
['test2', 'test2.expected'],
|
||||
['test4', 'test4.expected'],
|
||||
@@ -47,7 +50,9 @@ test_cases = [
|
||||
# Copy expected files and test data
|
||||
expected_files = []
|
||||
foreach t : test_cases
|
||||
expected_files += t[1]
|
||||
if t.length() > 1
|
||||
expected_files += t[1]
|
||||
endif
|
||||
endforeach
|
||||
|
||||
foreach f : expected_files + ['valid.json', 'valid_nested.json', 'json_patch_spec_tests.json', 'json_patch_tests.json']
|
||||
@@ -65,15 +70,24 @@ message('Test data directory: ' + testdir)
|
||||
|
||||
foreach t : test_cases
|
||||
name = t[0]
|
||||
expected = t[1]
|
||||
exe = executable(name, name + '.c',
|
||||
dependencies: test_deps,
|
||||
build_by_default: false
|
||||
)
|
||||
env_expected = []
|
||||
if t.length() > 1
|
||||
expected = t[1]
|
||||
# XXX does this do anything?
|
||||
env_expected = ['EXPECTED_FILE=' + meson.current_build_dir() / expected]
|
||||
endif
|
||||
if fs.exists(name + '.c')
|
||||
exe = executable(name, name + '.c',
|
||||
dependencies: test_deps,
|
||||
build_by_default: false
|
||||
)
|
||||
else
|
||||
exe = find_program(name)
|
||||
endif
|
||||
|
||||
test(name, exe,
|
||||
args: special_args.get(name, []),
|
||||
env: ['EXPECTED_FILE=' + meson.current_build_dir() / expected],
|
||||
env: env_expected,
|
||||
workdir: testdir
|
||||
)
|
||||
endforeach
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run shellcheck on all shell scripts in the source tree
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
if ! type shellcheck > /dev/null ; then
|
||||
echo "$0: SKIPPED, shellcheck not found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test -z "$srcdir"; then
|
||||
srcdir="${0%/*}"
|
||||
test "$srcdir" = "$0" && srcdir=.
|
||||
test -z "$srcdir" && srcdir=.
|
||||
fi
|
||||
|
||||
: "${VERBOSE:=1}"
|
||||
. "$srcdir/test-defs.sh"
|
||||
TOP="$srcdir/.."
|
||||
|
||||
cd "$TOP"
|
||||
if find ./* -name \*.sh -o \
|
||||
\( -name \*.test -type f \) -print0 | \
|
||||
xargs -0 shellcheck ; then
|
||||
echo "$0: SUCCESS"
|
||||
exit 0
|
||||
else
|
||||
echo "$0: FAIL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
+18
-17
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ ! -z "$JSONC_TEST_TRACE" ] ; then
|
||||
if [ -n "$JSONC_TEST_TRACE" ] ; then
|
||||
VERBOSE=1
|
||||
set -x
|
||||
set -v
|
||||
@@ -10,7 +10,7 @@ fi
|
||||
# stand-alone!!
|
||||
#
|
||||
srcdir=${srcdir-.}
|
||||
if test ! -d $srcdir ; then
|
||||
if test ! -d "$srcdir" ; then
|
||||
echo "test-defs.sh: installation error" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -18,18 +18,17 @@ fi
|
||||
# Use absolute paths
|
||||
case "$srcdir" in
|
||||
/* | [A-Za-z]:\\*) ;;
|
||||
*) srcdir=`\cd $srcdir && pwd` ;;
|
||||
*) srcdir=$(cd "$srcdir" && pwd) ;;
|
||||
esac
|
||||
|
||||
case "$top_builddir" in
|
||||
/* | [A-Za-z]:\\*) ;;
|
||||
*) top_builddir=`\cd ${top_builddir-..} && pwd` ;;
|
||||
*) top_builddir=$(cd "${top_builddir-..}" && pwd) ;;
|
||||
esac
|
||||
|
||||
top_builddir=${top_builddir}/tests
|
||||
|
||||
progname=`echo "$0" | sed 's,^.*/,,'`
|
||||
testname=`echo "$progname" | sed 's,-.*$,,'`
|
||||
progname=$(echo "$0" | sed 's,^.*/,,')
|
||||
testsubdir=${testsubdir-testSubDir}
|
||||
testsubdir=${testsubdir}/${progname}
|
||||
|
||||
@@ -64,7 +63,7 @@ case "${use_valgrind}" in
|
||||
;;
|
||||
esac
|
||||
valgrind_path=$(which valgrind 2> /dev/null)
|
||||
if [ -z "${valgrind_path}" -o ! -x "${valgrind_path}" ] ; then
|
||||
if [ -z "${valgrind_path}" ] || [ ! -x "${valgrind_path}" ] ; then
|
||||
use_valgrind=0
|
||||
fi
|
||||
|
||||
@@ -99,11 +98,12 @@ run_output_test()
|
||||
fi
|
||||
|
||||
REDIR_OUTPUT="> \"${TEST_OUTPUT}.out\" 2>&1"
|
||||
if [ $VERBOSE -gt 1 ] ; then
|
||||
if [ "$VERBOSE" -gt 1 ] ; then
|
||||
REDIR_OUTPUT="2>&1 | tee \"${TEST_OUTPUT}.out\""
|
||||
fi
|
||||
|
||||
if [ $use_valgrind -eq 1 ] ; then
|
||||
local exitval
|
||||
if [ "$use_valgrind" -eq 1 ] ; then
|
||||
eval valgrind --tool=memcheck \
|
||||
--trace-children=yes \
|
||||
--demangle=yes \
|
||||
@@ -111,20 +111,21 @@ run_output_test()
|
||||
--leak-check=full \
|
||||
--show-reachable=yes \
|
||||
--run-libc-freeres=yes \
|
||||
"\"${top_builddir}/${TEST_COMMAND}\"" \"\$@\" ${REDIR_OUTPUT}
|
||||
"\"${top_builddir}/${TEST_COMMAND}\" \"\$@\" ${REDIR_OUTPUT}"
|
||||
exitval=$?
|
||||
|
||||
else
|
||||
eval "\"${top_builddir}/${TEST_COMMAND}"\" \"\$@\" ${REDIR_OUTPUT}
|
||||
eval "\"${top_builddir}/${TEST_COMMAND}\" \"\$@\" ${REDIR_OUTPUT}"
|
||||
exitval=$?
|
||||
fi
|
||||
|
||||
if [ $exitval -ne $EXPECTED_EXITVAL ] ; then
|
||||
echo "ERROR: \"${TEST_COMMAND} $@\" exited with incorrect exit status: $err != $EXPECTED_EXITVAL" 1>&2
|
||||
local err=0
|
||||
if [ "$exitval" -ne "$EXPECTED_EXITVAL" ] ; then
|
||||
echo "ERROR: \"${TEST_COMMAND} $*\" exited with incorrect exit status: $err != $EXPECTED_EXITVAL" 1>&2
|
||||
err=1
|
||||
fi
|
||||
|
||||
if [ $use_valgrind -eq 1 ] ; then
|
||||
if [ "$use_valgrind" -eq 1 ] ; then
|
||||
if ! tail -1 "${TEST_OUTPUT}.vg.out" | grep -q "ERROR SUMMARY: 0 errors" ; then
|
||||
echo "ERROR: valgrind found errors during execution:" 1>&2
|
||||
cat "${TEST_OUTPUT}.vg.out"
|
||||
@@ -133,12 +134,12 @@ run_output_test()
|
||||
fi
|
||||
|
||||
if ! "$CMP" -s "${srcdir}/${TEST_OUTPUT}.expected" "${TEST_OUTPUT}.out" ; then
|
||||
echo "ERROR: \"${TEST_COMMAND} $@\" (${TEST_OUTPUT}) failed (set VERBOSE=1 to see full output):" 1>&2
|
||||
(cd "${CURDIR}" ; set -x ; diff "${srcdir}/${TEST_OUTPUT}.expected" "$testsubdir/${TEST_OUTPUT}.out")
|
||||
echo "ERROR: \"${TEST_COMMAND} $*\" (${TEST_OUTPUT}) failed (set VERBOSE=1 to see full output):" 1>&2
|
||||
(cd "${CURDIR}" && set -x && diff "${srcdir}/${TEST_OUTPUT}.expected" "$testsubdir/${TEST_OUTPUT}.out")
|
||||
echo "cp \"$testsubdir/${TEST_OUTPUT}.out\" \"${srcdir}/${TEST_OUTPUT}.expected\"" 1>&2
|
||||
|
||||
err=1
|
||||
fi
|
||||
|
||||
return $err
|
||||
return "$err"
|
||||
}
|
||||
@@ -17,5 +17,5 @@ filename="${filename%.*}"
|
||||
# more stuff could be extended
|
||||
cp -f "$srcdir/valid.json" .
|
||||
|
||||
run_output_test $filename "$srcdir"
|
||||
run_output_test "$filename" "$srcdir"
|
||||
exit $?
|
||||
@@ -13,5 +13,5 @@ fi
|
||||
filename=$(basename "$0")
|
||||
filename="${filename%.*}"
|
||||
|
||||
run_output_test $filename "$srcdir"
|
||||
run_output_test "$filename" "$srcdir"
|
||||
exit $?
|
||||
@@ -11,5 +11,5 @@ fi
|
||||
filename=$(basename "$0")
|
||||
filename="${filename%.*}"
|
||||
|
||||
run_output_test $filename
|
||||
run_output_test "$filename"
|
||||
exit $?
|
||||
Reference in new issue
Block a user