4 # SPDX-License-Identifier: GPL-2.0-only
6 #set -x # uncomment for debug
12 printf "Usage: %s <sub-command> [Options]\n" "$0"
13 printf " Sub-commands:\n"
14 printf " lint-stable : Run standard lint tests - should pass\n"
15 printf " lint-extended : Run extended lint tests - should pass\n"
16 printf " lint : Run full lint tests - Not expected to pass\n\n"
19 printf " -h | --help : Show this help message\n"
20 printf " -I | --invert : Invert results - used for testing linters\n"
21 printf " -J | --junit : Send test output to a JUnit file\n"
25 #write to the junit xml file if --junit was specified
27 if [ "$JUNIT" -eq 1 ]; then
28 echo "$1" >> "$XMLFILE"
32 # Look if we have getopt. If not, build it.
33 if [ "$(uname)" = "Darwin" ]; then
36 GETOPT
="getopt -l help,junit,invert -o hIJ"
39 if ! cmd_args
="$($GETOPT -- "$@
")"; then
43 eval set -- "${cmd_args}"
64 #verify the first command line parameter
66 echo "Error: A sub-command is needed."
69 elif [ "$1" != "lint" ] && [ "$1" != "lint-stable" ] &&
70 [ "$1" != "lint-extended" ]; then
71 echo "Error: $1 is not a valid sub-command."
76 LINTLOG
=$
(mktemp .tmpconfig.lintXXXXXX
);
77 XMLFILE
="$(dirname "$0")/junit.xml"
78 if [ "$1" = "lint-extended" ]; then
79 XMLFILE
="$(dirname "$0")/extended-junit.xml"
83 if [ "${JUNIT}" -eq 1 ]; then
84 echo '<?xml version="1.0" encoding="utf-8"?>' > "$XMLFILE"
85 junit_write
'<testsuite>'
88 #run all scripts of the requested type
89 for script in "$(dirname "$0")/${1}-"*; do
90 printf "%s " "$(grep '^# DESCR:' "$script" | sed 's,.*DESCR: *,,')"
91 printf "(%s): " "$(basename "$script")"
92 junit_write
" <testcase classname='lint' name='$(basename "$script")'>"
93 $script |
tee "$LINTLOG"
95 #if the lint script gives any output, that's a failure
96 if [ "${INVERT}" -eq 1 ] && [ "$(wc -l < "$LINTLOG")" -ne 0 ]; then
98 junit_write
" <system-out><![CDATA[success]]></system-out>"
99 elif [ "${INVERT}" -eq 0 ] && [ "$(wc -l < "$LINTLOG")" -eq 0 ]; then
101 junit_write
" <system-out><![CDATA[success]]></system-out>"
104 junit_write
" <failure type='testFailed'><![CDATA["
105 junit_write
"$(cat "$LINTLOG")"
106 junit_write
"]]></failure>"
108 FAILED
=$
(( FAILED
+ 1 ))
110 junit_write
' </testcase>'
114 junit_write
'</testsuite>'
115 test $FAILED -eq 0 ||
{ echo "ERROR: $FAILED test(s) failed."; exit 1; };