#!/usr/bin/env bash echo "" > log.txt for f in *.grnd; do [ -e "$f" ] || continue # skip if no files match # Files to skip over if [[ "$f" == "lib.grnd" ]] || [[ "$f" == "string.grnd" ]] || [[ "$f" == "test.grnd" ]] || [[ "$f" == "to1000.grnd" ]] || [[ "$f" == "uhoh.grnd" ]]; then continue fi echo "Running $f" ground "$f" > log.txt FILE="log.txt" FAILED="\033[31mFailed:\n\033[0m" if [[ "$f" == "closure.grnd" ]]; then if !(cmp -s "$FILE" <(printf "13 10\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "convs.grnd" ]]; then if !(cmp -s "$FILE" <(printf "32\n12\n3.140000\na\n97\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "drop.grnd" ]]; then if !(cmp -s "$FILE" <(printf "dingus\nGround runtime error:\n ErrorType: UnknownVariable\n ErrorInstruction: println \$x\n ErrorLine: 4\n")); then printf "\033[31mFailed\n\033[0m" exit 1 fi elif [[ "$f" == "error.grnd" ]]; then if !(cmp -s "$FILE" <(printf "Ground runtime error:\n ErrorType: Hello\n ErrorContext: [1, 2, 3, Hi!]\n ErrorInstruction: error \"Hello\" [1, 2, 3, Hi!] 1\n ErrorLine: 2\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "fib.grnd" ]]; then if !(cmp -s "$FILE" <(printf "Fibonacci result: 7540113804746346429\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "function.grnd" ]]; then if !(cmp -s "$FILE" <(printf "dingle\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "list.grnd" ]]; then if !(cmp -s "$FILE" <(printf "[hello, there, general, kenobi]\nhello\nthere\ngeneral\nkenobi\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "recursivefib.grnd" ]]; then if !(cmp -s "$FILE" <(printf "Computing fib(20) recursively...\nResult: 6765\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "simple.grnd" ]]; then if !(cmp -s "$FILE" <(printf "dingus\ndinglefart\n5.840000\n464773025\n5164.120000\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "struct.grnd" ]]; then if !(cmp -s "$FILE" <(printf "53\n32\n")); then printf $FAILED exit 1 fi elif [[ "$f" == "use.grnd" ]]; then if !(cmp -s "$FILE" <(printf "Hello\n")); then printf $FAILED exit 1 fi else printf "\033[31mCould not find test case\n\033[0m" exit 1 fi done printf "\033[32mAll tests passed!\n\033[0m" exit 0