Skip to content

Commit 51d6caf

Browse files
authored
update_checks.py: allow passing a list of test files to update (#2137)
It's taking longer to update almost 500 tests which currently exist. Without the arguments, the command updates all tests, as before: ``` $ time explorer/update_checks.py Updating 466 lit test(s)... real 0m5.858s ``` With the arguments, the command updates only the specified tests: ``` $ time explorer/update_checks.py explorer/testdata/basic_syntax/fail_invalid_integer.carbon explorer/testdata/basic_syntax/fail_invalid_char.carbon Updating 2 lit test(s)... real 0m0.359s ```
1 parent 4192ee4 commit 51d6caf

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

explorer/update_checks.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
99
"""
1010

11+
import argparse
1112
from concurrent import futures
1213
import os
1314
import re
@@ -265,17 +266,14 @@ def _update_check(test: str) -> None:
265266
print(".", end="", flush=True)
266267

267268

268-
def _update_checks() -> None:
269+
def _update_checks(tests: Set[str]) -> None:
269270
"""Runs bazel to update CHECK: lines in lit tests."""
270-
# TODO: It may be helpful if a list of tests can be passed in args; would
271-
# want to use argparse for this.
272-
tests = _get_tests()
273271

274272
# Build all tests at once in order to allow parallel updates.
275273
print("Building explorer...")
276274
subprocess.check_call(["bazel", "build", "//explorer"])
277275

278-
print("Updating %d lit tests..." % len(tests))
276+
print("Updating %d lit test(s)..." % len(tests))
279277
with futures.ThreadPoolExecutor() as exec:
280278
# list() iterates to propagate exceptions.
281279
list(exec.map(_update_check, tests))
@@ -288,7 +286,15 @@ def main() -> None:
288286
# Go to the repository root so that paths will match bazel's view.
289287
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
290288

291-
_update_checks()
289+
parser = argparse.ArgumentParser()
290+
parser.add_argument("tests", nargs="*")
291+
args = parser.parse_args()
292+
if args.tests:
293+
tests = set(args.tests)
294+
else:
295+
print("HINT: run `update_checks.py f1 f2 ...` to update specific tests")
296+
tests = _get_tests()
297+
_update_checks(tests)
292298

293299

294300
if __name__ == "__main__":

0 commit comments

Comments
 (0)