# Makes tests # Variables FILTER=dist/lin.lua FILES="tests/*.md" VERBOSE=false CMD="sh $0" # Prints help echo_help () { echo "Usage:" echo " $CMD [-vh] [FILES]" echo "Examples:" echo " $CMD Tests with 'tests/*.md'" echo " $CMD -v Verbose tests with 'tests/*.md'" echo " $CMD tests/fail* Tests with 'tests/fail*'" echo " $CMD -v tests/fail* Verbose tests with 'tests/fail*'" echo " $CMD -h Display this help" exit } # Obtains result as "pass" | "fail" | "diff" (AST doesn't match) get_result () { result=$([[ $1 -ne 0 ]] && echo "fail" || echo "pass") if [ -f $2.json ]; then diff1=$(cat tmp.json | jq) diff2=$(cat $2.json | jq) difference=$(diff <( printf '%s\n' "$diff1" ) <( printf '%s\n' "$diff2" )) result=$([[ $? -eq 0 ]] && echo "pass" || echo "diff") fi echo $result } # Checks options while getopts ':vh' opt; do case "$opt" in v) VERBOSE=true ; shift ;; h) echo_help ;; ?) echo "ERROR: only -v or -h is allowed" ; exit 1 ;; esac done # Checks for files if [ $# -ne 0 ]; then for file in $*; do if [ ! -f $file ]; then echo "ERROR: '$file' is not a file; do '$CMD -h' for more info" ; exit 1 fi done FILES=$* fi # Makes distribution bundle sh scripts/make_dist.sh # Does tests clear && echo "🐾 Starting tests" for file in $FILES; do echo "⚗️ $file:" expectation=${file:6:4} ast=$(pandoc -L $FILTER -t json -o tmp.json $file) result=$(get_result $? $file) echo " Expect: $expectation" echo " Result: $result" if [ "$VERBOSE" = true ]; then pandoc -L $FILTER -t native $file fi rm tmp.json done