# Makes tests # Variables FILTER=dist/lin.lua FILES="tests/*.md" VERBOSE="" AST=false CMD="sh $0" # Prints help echo_help () { echo "Usage:" echo " $CMD [-vah] [FILES]" echo "Examples:" echo " $CMD Tests for 'tests/*.md'" echo " $CMD -v Verbose tests for 'tests/*.md'" echo " $CMD -a Tests and AST for 'tests/*.md'" echo " $CMD tests/fail* Tests for 'tests/fail*'" echo " $CMD -va tests/fail* Verbose tests and AST for '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 ':vah' opt; do case "$opt" in v) VERBOSE="--verbose" ; shift ;; a) AST=true ; shift ;; h) echo_help ;; ?) echo "ERROR: only -v, -a 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 $VERBOSE -L $FILTER -t json -o tmp.json $file) result=$(get_result $? $file) echo " Expect: $expectation" echo " Result: $result" [ "$VERBOSE" = "--verbose" ] && echo -e "$ast" [ "$AST" = true ] && pandoc -L $FILTER -t native $file rm tmp.json done