mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-13 08:04:30 +02:00
Refactor and tidy BOSL's shell scripts
* Fixed ShellCheck.net warnings, including * exit -1: https://github.com/koalaman/shellcheck/wiki/SC2242 * cd || exit: https://github.com/koalaman/shellcheck/wiki/SC2164 * "$foo": https://github.com/koalaman/shellcheck/wiki/SC2086 * $(( $foo )): https://github.com/koalaman/shellcheck/wiki/SC2004 * grep | wc -l: https://github.com/koalaman/shellcheck/wiki/SC2126 * Use arrays instead of unquoted strings for loops and command arguments * Use (( ... )) arithmetic context instead of string comparisons * Use bash's built-in regex support instead of grep+sed+awk * Write errors to stderr
This commit is contained in:
@@ -1,35 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$(uname -s)" != "Darwin" ]; then
|
||||
OPENSCAD=openscad
|
||||
else
|
||||
OPENSCAD=openscad
|
||||
if [ "$(uname -s)" == "Darwin" ]; then
|
||||
OPENSCAD=/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD
|
||||
fi
|
||||
|
||||
if [ "$*" != "" ] ; then
|
||||
INFILES="$*"
|
||||
else
|
||||
INFILES="tests/test_*.scad"
|
||||
INFILES=("$@")
|
||||
if (( ${#INFILES[@]} == 0 )); then
|
||||
INFILES=(tests/test_*.scad)
|
||||
fi
|
||||
|
||||
OUTCODE=0
|
||||
for testscript in $INFILES ; do
|
||||
repname="$(basename $testscript | sed 's/^test_//')"
|
||||
testfile="tests/test_$repname"
|
||||
if [ -f "$testfile" ] ; then
|
||||
${OPENSCAD} -o out.echo --hardwarnings --check-parameters true --check-parameter-ranges true $testfile 2>&1
|
||||
for testfile in "${INFILES[@]}"; do
|
||||
if [[ -f "$testfile" ]] ; then
|
||||
repname="$(basename "$testfile" | sed 's/^test_//')"
|
||||
"${OPENSCAD}" -o out.echo --hardwarnings --check-parameters true --check-parameter-ranges true "$testfile" 2>&1
|
||||
retcode=$?
|
||||
res=$(cat out.echo)
|
||||
if [ $retcode -eq 0 ] && [ "$res" = "" ] ; then
|
||||
output=$(cat out.echo)
|
||||
if (( retcode == 0 )) && [[ "$output" = "" ]]; then
|
||||
echo "$repname: PASS"
|
||||
else
|
||||
echo "$repname: FAIL!"
|
||||
cat out.echo
|
||||
echo
|
||||
OUTCODE=-1
|
||||
echo "$output"
|
||||
OUTCODE="$retcode"
|
||||
fi
|
||||
rm -f out.echo
|
||||
fi
|
||||
done
|
||||
exit $OUTCODE
|
||||
exit "$OUTCODE"
|
||||
|
||||
|
Reference in New Issue
Block a user