autoupdate_testdata.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. """Autoupdates testdata in toolchain."""
  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. argv = [
  13. "bazel",
  14. "run",
  15. "-c",
  16. "opt",
  17. "//toolchain/testing:file_test",
  18. "--",
  19. "--autoupdate",
  20. ]
  21. # Support specifying tests to update, such as:
  22. # ./autoupdate_testdata.py lex/**/*
  23. if len(sys.argv) > 1:
  24. repo_root = Path(__file__).resolve().parent.parent
  25. file_tests = []
  26. # Filter down to just test files.
  27. for f in sys.argv[1:]:
  28. if f.endswith(".carbon"):
  29. path = str(Path(f).resolve().relative_to(repo_root))
  30. if path.count("/testdata/"):
  31. file_tests.append(path)
  32. if not file_tests:
  33. sys.exit(
  34. f"Args do not seem to be test files; for example, {sys.argv[1]}"
  35. )
  36. argv.append("--file_tests=" + ",".join(file_tests))
  37. subprocess.run(argv, check=True)
  38. if __name__ == "__main__":
  39. main()