autoupdate_testdata.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python3
  2. """Updates the CHECK: lines in tests with an AUTOUPDATE line."""
  3. __copyright__ = """
  4. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  5. Exceptions. See /LICENSE for license information.
  6. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. """
  8. import subprocess
  9. import sys
  10. from pathlib import Path
  11. def main() -> None:
  12. # Subprocess to the main script in order to avoid Python import behaviors.
  13. this_py = Path(__file__).resolve()
  14. autoupdate_py = this_py.parent.parent.parent.joinpath(
  15. "testing", "scripts", "autoupdate_testdata_base.py"
  16. )
  17. args = [
  18. str(autoupdate_py),
  19. # Flags to configure for lexer testing.
  20. "--tool=carbon",
  21. "--autoupdate_arg=dump",
  22. "--autoupdate_arg=tokens",
  23. # Ignore the resulting column of EndOfFile because it's typically the
  24. # end of the CHECK comment.
  25. "--extra_check_replacement",
  26. ".*'EndOfFile'",
  27. r"column: (?:\d+)",
  28. "column: {{[0-9]+}}",
  29. # Ignore spaces that are used to columnize lines.
  30. "--line_number_delta_prefix={{ *}}",
  31. "--line_number_pattern="
  32. r"(?P<prefix> line: )(?P<line> *\d+)(?P<suffix>,)",
  33. "--testdata=toolchain/lexer/testdata",
  34. ] + sys.argv[1:]
  35. exit(subprocess.call(args))
  36. if __name__ == "__main__":
  37. main()