BOSL2/scripts/run_tests.sh
Michael Diamond 0666f6482c 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
2021-05-21 01:01:15 -07:00

31 lines
799 B
Bash
Executable file

#!/bin/bash
OPENSCAD=openscad
if [ "$(uname -s)" == "Darwin" ]; then
OPENSCAD=/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD
fi
INFILES=("$@")
if (( ${#INFILES[@]} == 0 )); then
INFILES=(tests/test_*.scad)
fi
OUTCODE=0
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=$?
output=$(cat out.echo)
if (( retcode == 0 )) && [[ "$output" = "" ]]; then
echo "$repname: PASS"
else
echo "$repname: FAIL!"
echo "$output"
OUTCODE="$retcode"
fi
rm -f out.echo
fi
done
exit "$OUTCODE"