Skip to content

Commit

Permalink
Fix many shellcheck problems in test scripts.
Browse files Browse the repository at this point in the history
* use double quotes
* fix cd || exit
* use $() instead of back-tick
* read adds -r option
Unify format error/warn/info messages.
  • Loading branch information
BsAtHome committed Jan 30, 2025
1 parent 1c72d4b commit b740c62
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 103 deletions.
6 changes: 2 additions & 4 deletions tests/halcompile/names/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ set -x

# this one must succeed
rm -f names_match.c
halcompile names_match.comp
if [ $? -ne 0 ]; then
if ! halcompile names_match.comp; then
echo 'halcompile failed to process names_match.comp'
exit 1
fi
Expand All @@ -15,8 +14,7 @@ fi

# this one must fail
rm -f names_dont_match.c
halcompile names_dont_match.comp
if [ $? -eq 0 ]; then
if halcompile names_dont_match.comp; then
echo 'halcompile erroneously accepted names_dont_match.comp'
exit 1
fi
Expand Down
6 changes: 3 additions & 3 deletions tests/halcompile/personalities_mod/checkresult
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
cd $(dirname $1)
cd "$(dirname "$1")" || exit
RETVAL=0
for EXPECTED in *.expected ; do
BASE=$(basename $EXPECTED .expected)
BASE=$(basename "$EXPECTED" .expected)
RESULT=$BASE.result
diff -u $EXPECTED $RESULT
diff -u "$EXPECTED" "$RESULT"
if [ $? -ne 0 ]; then
RETVAL=1
fi
Expand Down
2 changes: 1 addition & 1 deletion tests/halcompile/relative-header-user/checkresult
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
[ -e "`dirname "$1"`/relative_header" ]
[ -e "$(dirname "$1")/relative_header" ]
2 changes: 1 addition & 1 deletion tests/halcompile/relative-header/checkresult
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
[ -e "`dirname "$1"`/relative_header.so" -o "`dirname "$1"`/relative_header.ko" ]
[ -e "$(dirname "$1")/relative_header.so" ] || [ -e "$(dirname "$1")/relative_header.ko" ]
6 changes: 3 additions & 3 deletions tests/halcompile/userspace-count-names/checkresult
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
cd $(dirname $1)
cd "$(dirname "$1")" || { echo "E: Could not change directory to '$(dirname "$1")'"; exit 1; }
RETVAL=0
for EXPECTED in *.expected ; do
BASE=$(basename $EXPECTED .expected)
BASE=$(basename "$EXPECTED" .expected)
RESULT=$BASE.result
diff -u $EXPECTED $RESULT
diff -u "$EXPECTED" "$RESULT"
if [ $? -ne 0 ]; then
RETVAL=1
fi
Expand Down
4 changes: 2 additions & 2 deletions tests/hm2-idrom/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Error[14]="hm2/hm2_test\.0: IDROM IOPorts is 0 but llio num_ioport_connectors is
result=0

TEST_PATTERN=0
while [ ! -z "${Error[$TEST_PATTERN]}" ]; do
while [ -n "${Error[$TEST_PATTERN]}" ]; do
export TEST_PATTERN
halrun -f broken-load-test.hal >halrun-stdout 2>halrun-stderr
./check-dmesg.py "${Error[$TEST_PATTERN]}" || exit $?
TEST_PATTERN=$(($TEST_PATTERN+1))
TEST_PATTERN=$((TEST_PATTERN + 1))
done

exit $result
4 changes: 2 additions & 2 deletions tests/interp/g71-endless-loop/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pid=$!
count=10
while [ 0 -lt $count ] && kill -0 $pid > /dev/null 2>&1 ; do
sleep 1
count=$(($count - 1))
count=$((count - 1))
done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
echo "error: g71-endless-loop.ngc program seem to be stuck, killing"
echo "E: g71-endless-loop.ngc program seem to be stuck, killing"
exit 1
fi

Expand Down
4 changes: 2 additions & 2 deletions tests/interp/g71-with-g70/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pid=$!
count=5
while [ 0 -lt $count ] && kill -0 $pid > /dev/null 2>&1 ; do
sleep 1
count=$(($count - 1))
count=$((count - 1))
done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
echo "error: g71_and_g70.ngc program seem to be stuck, killing"
echo "E: g71_and_g70.ngc program seem to be stuck, killing"
exit 1
fi

Expand Down
4 changes: 2 additions & 2 deletions tests/interp/g72-facing/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ pid=$!
count=10
while [ 0 -lt $count ] && kill -0 $pid > /dev/null 2>&1 ; do
sleep 1
count=$(($count - 1))
count=$((count - 1))
done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
echo "error: g71-iterations-present.ngc program seem to be stuck, killing"
echo "E: g71-iterations-present.ngc program seem to be stuck, killing"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion tests/interp/g72-missing-iteration/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ done

if kill -0 $pid > /dev/null 2>&1; then
kill -9 $pid
echo "error: g71-iterations-missing.ngc program seem to be stuck, killing"
echo "E: g71-iterations-missing.ngc program seem to be stuck, killing"
exit 1
fi

Expand Down
6 changes: 2 additions & 4 deletions tests/interp/iniparam-failassign/test.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/bash
export PYTHONUNBUFFERED=1
rs274 -i test.ini -g test.ngc 2>&1

# expected to fail
if [ $? -ne 0 ]; then
if ! rs274 -i test.ini -g test.ngc 2>&1; then
# expected to fail
exit 0
fi

Expand Down
6 changes: 2 additions & 4 deletions tests/interp/m98m99/03-error-M98-no-P-word/test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash
rs274 -g test.ngc 2>&1

# expected to fail
if [ $? -ne 0 ]; then
if ! rs274 -g test.ngc 2>&1; then
# expected to fail
exit 0
fi

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
cd $(dirname $1)
cd "$(dirname "$1")" || { echo "E: Could not change directory to '$(dirname "$1")'"; exit 1; }
diff -u expected.motion-logger out.motion-logger
4 changes: 2 additions & 2 deletions tests/interp/oword-mdi-sub-update/checkresult
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

TEST_DIR=$(dirname $1)
cd $TEST_DIR
TEST_DIR=$(dirname "$1")
cd "$TEST_DIR"

# Avoid false negatives: This string should be present
grep -q 'test RAN' result
Expand Down
4 changes: 2 additions & 2 deletions tests/linuxcncrsh-tcp/checkresult
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

TEST_DIR=$(dirname $1)
cd $TEST_DIR
TEST_DIR=$(dirname "$1")
cd "$TEST_DIR" || { echo "E: Could not change directory to '$TEST_DIR'"; exit 1; }

diff -u expected-gcode-output gcode-output
4 changes: 2 additions & 2 deletions tests/linuxcncrsh/checkresult
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

TEST_DIR=$(dirname $1)
cd $TEST_DIR
TEST_DIR=$(dirname "$1")
cd "$TEST_DIR" || { echo "E: Could not change directory to '$TEST_DIR'"; exit 1; }

# show deviation from expected output
diff -uwB expected-gcode-output gcode-output || exit 1
Expand Down
6 changes: 3 additions & 3 deletions tests/linuxcncrsh/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ linuxcnc -r linuxcncrsh-test.ini &
# let linuxcnc come up
TOGO=80
while [ $TOGO -gt 0 ]; do
echo trying to connect to linuxcncrsh TOGO=$TOGO
echo "trying to connect to linuxcncrsh TOGO=$TOGO"
if nc -z localhost 5007; then
break
fi
Expand All @@ -36,7 +36,7 @@ function testSet() {
# get before value
echo "get $1"
# set cmd
echo "set $@"
echo "set $*"
# get after value
echo "get $1"
# get error from server (or OK)
Expand All @@ -46,7 +46,7 @@ function testSet() {
# get command with collecting possible error from linuxcncsvr
function testGet() {
cmd="$@"
echo "get $@"
echo "get $*"
echo "get error"
}

Expand Down
38 changes: 20 additions & 18 deletions tests/mdi-queue/oword-queue-buster/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ while [ $TOGO -gt 0 ]; do
break
fi
sleep 0.25
TOGO=$(($TOGO - 1))
TOGO=$((TOGO - 1))
done
if [ $TOGO -eq 0 ]; then
echo "E: connection to linuxcncrsh timed out"
Expand All @@ -42,20 +42,22 @@ NUM_MDIS=1
NUM_MDIS_LEFT=$NUM_MDIS
TOOL=1
for i in $(seq 0 1000); do
NUM_MDIS_LEFT=$(($NUM_MDIS_LEFT - 1))
NUM_MDIS_LEFT=$((NUM_MDIS_LEFT - 1))
if [ $NUM_MDIS_LEFT -eq 0 ]; then
echo "set mdi o<queue-buster> call [$TOOL]" >> lots-of-gcode
echo "P is 12345.000000" >> expected-gcode-output
echo "P is $((-1 * $TOOL)).000000" >> expected-gcode-output
echo "P is 54321.000000" >> expected-gcode-output
{
echo "P is 12345.000000"
echo "P is $((-1 * TOOL)).000000"
echo "P is 54321.000000"
} >> expected-gcode-output

if [ $TOOL -eq 1 ]; then
TOOL=2
else
TOOL=1
fi

NUM_MDIS=$(($NUM_MDIS + 1))
NUM_MDIS=$((NUM_MDIS + 1))
if [ $NUM_MDIS -gt 10 ]; then
NUM_MDIS=1
fi
Expand All @@ -68,25 +70,25 @@ done
echo "P is -200.000000" >> expected-gcode-output

(
echo hello EMC mt 1.0
echo set enable EMCTOO
echo "hello EMC mt 1.0"
echo "set enable EMCTOO"

echo set mode manual
echo set estop off
echo set machine on
echo "set mode manual"
echo "set estop off"
echo "set machine on"

echo set mode auto
echo set open dummy.ngc
echo "set mode auto"
echo "set open dummy.ngc"

echo set mode mdi
echo set mdi m100 p-100
echo set wait done
echo "set mode mdi"
echo "set mdi m100 p-100"
echo "set wait done"

# here comes a big blob
dd bs=4096 if=lots-of-gcode

echo set mdi m100 p-200
echo set wait done
echo "set mdi m100 p-200"
echo "set wait done"

echo shutdown
) | nc localhost 5007
Expand Down
4 changes: 2 additions & 2 deletions tests/mdi-queue/shared-checkresult
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

TEST_DIR=$(dirname $1)
cd $TEST_DIR
TEST_DIR=$(dirname "$1")
cd "$TEST_DIR" || { echo "E: Could not change directory to '$TEST_DIR'"; exit 1; }

diff -u expected-gcode-output gcode-output
30 changes: 15 additions & 15 deletions tests/mdi-queue/simple-queue-buster/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ while [ $TOGO -gt 0 ]; do
break
fi
sleep 0.25
TOGO=$(($TOGO - 1))
TOGO=$((TOGO - 1))
done
if [ $TOGO -eq 0 ]; then
echo connection to linuxcncrsh timed out
Expand All @@ -42,7 +42,7 @@ NUM_MDIS=1
NUM_MDIS_LEFT=$NUM_MDIS
TOOL=1
for i in $(seq 0 1000); do
NUM_MDIS_LEFT=$(($NUM_MDIS_LEFT - 1))
NUM_MDIS_LEFT=$((NUM_MDIS_LEFT - 1))
if [ $NUM_MDIS_LEFT -eq 0 ]; then
echo "set mdi t$TOOL m6" >> lots-of-gcode
if [ $TOOL -eq 1 ]; then
Expand All @@ -51,7 +51,7 @@ for i in $(seq 0 1000); do
TOOL=1
fi

NUM_MDIS=$(($NUM_MDIS + 1))
NUM_MDIS=$((NUM_MDIS + 1))
if [ $NUM_MDIS -gt 10 ]; then
NUM_MDIS=1
fi
Expand All @@ -64,28 +64,28 @@ done
echo "P is -2.000000" >> expected-gcode-output

(
echo hello EMC mt 1.0
echo set enable EMCTOO
echo "hello EMC mt 1.0"
echo "set enable EMCTOO"

# ask linuxcncrsh to not read the next command until it's done running
# the current one
#echo set set_wait done
#echo "set set_wait done"

echo set mode manual
echo set estop off
echo set machine on
echo "set mode manual"
echo "set estop off"
echo "set machine on"

echo set mode mdi
echo set mdi m100 p-1
echo set wait done
echo "set mode mdi"
echo "set mdi m100 p-1"
echo "set wait done"

# here comes a big blob
dd bs=4096 if=lots-of-gcode

echo set mdi m100 p-2
echo set wait done
echo "set mdi m100 p-2"
echo "set wait done"

echo shutdown
echo "shutdown"
) | nc localhost 5007


Expand Down
4 changes: 3 additions & 1 deletion tests/mdi-while-queuebuster-waitflag/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash -e

for i in `seq 20`; do
# Variable 'i' is unused, just a loop count
# shellcheck disable=SC2034
for i in $(seq 20); do
linuxcnc -r test.ini
if grep -q '^[^+].*Segmentation fault' stderr; then
exit 1
Expand Down
2 changes: 1 addition & 1 deletion tests/motion-logger/mountaindew/checkresult
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
cd $(dirname $1)
cd "$(dirname "$1")" || { echo "E: Could not change directory to '$(dirname "$1")'"; exit 1; }
diff -u expected.motion-logger out.motion-logger
2 changes: 1 addition & 1 deletion tests/motion-logger/startup-gcode-abort/checkresult
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
cd $(dirname $1)
cd "$(dirname "$1")" || { echo "E: Could not change directory to '$(dirname "$1")'"; exit 1; }
diff -u expected.motion-logger out.motion-logger
8 changes: 4 additions & 4 deletions tests/overrun/test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
TMPDIR=`mktemp -d /tmp/overrun.XXXXXX`
trap "rm -rf $TMPDIR" 0 1 2 3 9 15
TMPDIR=$(mktemp -d /tmp/overrun.XXXXXX)
trap 'rm -rf "$TMPDIR"' 0 1 2 3 15

TEST_HAL=$TMPDIR/test.hal
echo loadusr -w echo overrun > $TMPDIR/test.hal
echo loadusr -w echo overrun > "$TMPDIR/test.hal"

! $RUNTESTS $TMPDIR 2>&1
! $RUNTESTS "$TMPDIR" 2>&1
Loading

0 comments on commit b740c62

Please sign in to comment.