Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update runtests (shellcheck) #3361

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions scripts/runtests.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export LANGUAGES=

TOPDIR="$(realpath "$(dirname "$0")/..")"

# $prefix is used in the substitutions of @...@ strings below
# shellcheck disable=SC2034
prefix=@prefix@
# Shellcheck does not know about substitutions
# shellcheck disable=SC2050
Expand Down Expand Up @@ -176,22 +178,22 @@ run_tests () {
find "$*" -name test.hal -or -name test.sh -or -name test \
| sort > "$TMPDIR/alltests"

while read testname; do
testdir=$(dirname $testname)
while read -r testname; do
testdir=$(dirname "$testname")
# check if there's a "musthave" file with prerequisites from config.h
if [ -e $testdir/musthave ] ; then
if [ -e "$testdir/musthave" ] ; then
# one prerequisite per line
while IFS= read -r prereq ; do
if ! grep --quiet --regexp "^#define HAVE_$prereq.*" "$TOPDIR/src/config.h" ; then
echo "Skipping test for missing prerequisite \"$prereq\": $testdir" 1>&2
SKIP=$(($SKIP+1))
SKIP=$((SKIP + 1))
continue 3
fi
done < $testdir/musthave
done < "$testdir/musthave"
fi
# skip test if there's a "skip" file
if [ -e $testdir/skip ]; then
if ! [ -x $testdir/skip ] || ! $testdir/skip; then
if [ -e "$testdir/skip" ]; then
if ! [ -x "$testdir/skip" ] || ! "$testdir/skip"; then

echo "Skipping disabled test: $testdir" 1>&2
SKIP=$((SKIP + 1))
Expand Down
63 changes: 40 additions & 23 deletions scripts/shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,54 @@ if ! command -v shellcheck > /dev/null; then
exit 1
fi

echo Shellcheck

# This script is supposed to be in the scripts subdirectory
TOPDIR=$(realpath --relative-to=. "$(dirname "$0")/..")

# Exclude tracking includes and don't complain about include paths
SHELLCHECK_OPTS="--exclude=SC1090,SC1091"
export SHELLCHECK_OPTS

#
# With the file command we can find all scripts.
# Note: perform shellcheck with a distclean tree. Some scripts are
# generated by configure from .in files.
#
# Without the file command we just look for script file names.
#
if [ -n "$(command -v file)" ]; then
mapfile -t FILES < <(find "$TOPDIR" -type f \
-not -path "*/.git/*" \
-not -path "*/autom4te.cache/*" \
-not -name "*~" \
-not -path "*/tcl/*" \
-not -name "*.tcl" \
-not -name "configure" \
-not -name "config.guess" \
-not -name "config.status" \
-not -name "config.sub" \
-not -name "install-sh" \
-exec file {} + | awk -F: '/shell script/{print $1}')
# Check if files are specified on the command line. If so, only use those.
if [ $# -gt 0 ]; then
case "$1" in
-h|--help*)
cat <<EOF
Shellcheck script to check LinuxCNC shell scripts.
Usage: shellcheck.sh [-h|--help] [files...]
-h, --help This help message

Specify one or more files on the command line if you only want those files
to be checked. The script will search all of the LinuxCNC source tree for
shell scripts if no files are specified on the command line.
EOF
exit 1
;;
esac
FILES=( "$@" )
else
mapfile -r FILES < <(find "$TOPDIR" -type f -name "*.sh")
#
# With the file command we can find all scripts.
# Note: perform shellcheck with a distclean tree. Some scripts are
# generated by configure from .in files.
#
# Without the file command we just look for script file names.
#
if [ -n "$(command -v file)" ]; then
mapfile -t FILES < <(find "$TOPDIR" -type f \
-not -path "*/.git/*" \
-not -path "*/autom4te.cache/*" \
-not -name "*~" \
-not -path "*/tcl/*" \
-not -name "*.tcl" \
-not -name "configure" \
-not -name "config.guess" \
-not -name "config.status" \
-not -name "config.sub" \
-not -name "install-sh" \
-exec file {} + | awk -F: '/shell script/{print $1}')
else
mapfile -r FILES < <(find "$TOPDIR" -type f -name "*.sh")
fi
fi

if [ "${#FILES[@]}" -gt 0 ]; then
Expand Down
Loading