run.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/sh
  2. # Run the Statum markdown test suites.
  3. #
  4. # Builds the vendored QuickJS interpreter if no `qjs` is on PATH, then runs
  5. # the hand-written regression suite and the CommonMark spec conformance
  6. # suite. Exits non-zero when regressions fail or the spec score drops below
  7. # the target rate.
  8. #
  9. # Usage: tests/markdown/run.sh [-v] (-v lists every failing spec example)
  10. set -e
  11. cd "$(dirname "$0")/../.."
  12. ROOT=$(pwd)
  13. QJS="$ROOT/tools/qjs/qjs"
  14. TARGET=95
  15. if ! command -v qjs >/dev/null 2>&1; then
  16. echo "== building vendored QuickJS =="
  17. "$ROOT/tools/qjs/build.sh"
  18. else
  19. QJS=$(command -v qjs)
  20. fi
  21. echo "== regressions =="
  22. "$QJS" "$ROOT/tests/markdown/regressions.js"
  23. echo ""
  24. echo "== CommonMark 0.31.2 spec =="
  25. # -v (or any second argument) makes spec-test.js print each failing example
  26. "$QJS" "$ROOT/tests/markdown/spec-test.js" "${1:-}"
  27. # spec-test.js prints "TOTAL <pass>/<total> <rate>%"; re-derive the rate from
  28. # a quiet rerun so the gate below cannot be fooled by the verbose listing.
  29. SCORE=$("$QJS" "$ROOT/tests/markdown/spec-test.js" | grep '^ TOTAL' | sed 's/.* \([0-9.]*\)%$/\1/')
  30. echo ""
  31. echo "spec score: ${SCORE}% (target ${TARGET}%)"
  32. # compare as integers to avoid depending on awk float handling
  33. PASSING=$(echo "$SCORE" | cut -d. -f1)
  34. if [ "$PASSING" -lt "$TARGET" ]; then
  35. echo "FAIL: spec conformance ${SCORE}% is below the ${TARGET}% target"
  36. exit 1
  37. fi
  38. echo "OK"