autoupdate_testdata.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. "--experimental_convenience_symlinks=ignore",
  18. "--ui_event_filters=-info,-stdout,-stderr,-finish",
  19. "//toolchain/testing:file_test",
  20. "--",
  21. "--autoupdate",
  22. ]
  23. # Support specifying tests to update, such as:
  24. # ./autoupdate_testdata.py lex/**/*
  25. if len(sys.argv) > 1:
  26. repo_root = Path(__file__).resolve().parent.parent
  27. file_tests = []
  28. # Filter down to just test files.
  29. for f in sys.argv[1:]:
  30. if f.endswith(".carbon"):
  31. path = str(Path(f).resolve().relative_to(repo_root))
  32. if path.count("/testdata/"):
  33. file_tests.append(path)
  34. if not file_tests:
  35. sys.exit(
  36. f"Args do not seem to be test files; for example, {sys.argv[1]}"
  37. )
  38. argv.append("--file_tests=" + ",".join(file_tests))
  39. # Provide an empty stdin so that the driver tests that read from stdin
  40. # don't block waiting for input. This matches the behavior of `bazel test`.
  41. subprocess.run(argv, check=True)
  42. if __name__ == "__main__":
  43. main()