run_parse_tests 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # TODO: move this into the client
  3. set -uo pipefail
  4. test_directory="parse_tests"
  5. function usage() {
  6. cat <<EOF >&2
  7. Usage:
  8. $(basename "$0") [-h] [-a] -- Run parser golden tests in $test_directory
  9. where:
  10. -h show this help text
  11. -a accept new results (override test files)
  12. EOF
  13. exit 1
  14. }
  15. accept=false
  16. while getopts ':ha' option; do
  17. case "$option" in
  18. h) usage
  19. ;;
  20. a) accept=true
  21. ;;
  22. :) printf "missing argument for -%s\n" "$OPTARG" >&2
  23. usage
  24. ;;
  25. \?) printf "illegal option: -%s\n" "$OPTARG" >&2
  26. usage
  27. ;;
  28. esac
  29. done
  30. shift $((OPTIND - 1))
  31. test_files=$(find "$test_directory" -type f | grep "\.test$")
  32. failed_tests=0
  33. for test in ${test_files[@]}; do
  34. test_name="${test%.*}"
  35. expected="$test_name.expected"
  36. result=$(mktemp)
  37. node build/main.js parse $(cat "$test") > "$result"
  38. if [ $accept = true ]; then
  39. echo "Updating $test_name"
  40. cat "$result" > "$expected"
  41. continue
  42. fi
  43. if [ ! -f "$expected" ]; then
  44. echo "Missing '$expected' (re-run with -a flag to create)"
  45. failed_tests=$(($failed_tests + 1))
  46. else
  47. echo "Testing $test_name"
  48. git --no-pager diff --no-index "$expected" "$result"
  49. failed_tests=$(($failed_tests + $?))
  50. fi
  51. done
  52. if [ ! $failed_tests = 0 ]; then
  53. echo "$failed_tests failed test(s)"
  54. exit 1
  55. else
  56. echo "All tests passed"
  57. fi