make-ast-dump-check.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #! /bin/bash
  2. # This script is intended as a FileCheck replacement to update the test
  3. # expectations in a -ast-dump test.
  4. #
  5. # Usage:
  6. #
  7. # $ lit -DFileCheck=$PWD/utils/make-ast-dump-check.sh test/AST/ast-dump-openmp-*
  8. prefix=CHECK
  9. while [[ "$#" -ne 0 ]]; do
  10. case "$1" in
  11. --check-prefix)
  12. shift
  13. prefix="$1"
  14. ;;
  15. --implicit-check-not)
  16. shift
  17. ;;
  18. -*)
  19. ;;
  20. *)
  21. file="$1"
  22. ;;
  23. esac
  24. shift
  25. done
  26. testdir="$(dirname "$file")"
  27. read -r -d '' script <<REWRITE
  28. BEGIN {
  29. skipping_builtins = 0
  30. matched_last_line = 0
  31. }
  32. /^[\`|].* line:/ {
  33. skipping_builtins = 0
  34. }
  35. {
  36. if (skipping_builtins == 1) {
  37. matched_last_line = 0
  38. next
  39. }
  40. }
  41. /TranslationUnitDecl/ {
  42. skipping_builtins = 1
  43. }
  44. {
  45. s = \$0
  46. gsub("0x[0-9a-fA-F]+", "{{.*}}", s)
  47. gsub("$testdir/", "{{.*}}", s)
  48. }
  49. matched_last_line == 0 {
  50. print "// ${prefix}: " s
  51. }
  52. matched_last_line == 1 {
  53. print "// ${prefix}-NEXT: " s
  54. }
  55. {
  56. matched_last_line = 1
  57. }
  58. REWRITE
  59. echo "$script"
  60. {
  61. cat "$file" | grep -v "$prefix"
  62. awk "$script"
  63. } > "$file.new"
  64. mv "$file.new" "$file"