Skip to content

Commit

Permalink
test/run-tests.py: Add an argument for running only failed tests.
Browse files Browse the repository at this point in the history
Implements the typical 're-run the failed tests' most test runners
have for convenience.

Signed-off-by: stijn <[email protected]>
  • Loading branch information
stinos committed Dec 14, 2023
1 parent 05d3b22 commit 2291555
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def open(self, path, mode):
__import__('__injected_test')
"""

# Strings used in creating test basename, in the order they get applied.
test_basename_strings = [(":", "&"), ("..", "#"), ("./", "%"), ("/", "$")]

def rm_f(fname):
if os.path.exists(fname):
Expand Down Expand Up @@ -675,7 +677,9 @@ def run_one_test(test_file):
if verdict == "exclude":
return

test_basename = test_file.replace("..", "_").replace("./", "").replace("/", "_")
test_basename = test_file
for replacement in test_basename_strings:
test_basename = test_basename.replace(replacement[0], replacement[1])
test_name = os.path.splitext(os.path.basename(test_file))[0]
is_native = (
test_name.startswith("native_")
Expand Down Expand Up @@ -910,6 +914,11 @@ def main():
action="store_true",
help="delete the .exp and .out files from failed tests and exit",
)
cmd_parser.add_argument(
"--run-failed",
action="store_true",
help="re-run only the currently failed tests",
)
args = cmd_parser.parse_args()

if args.print_failures:
Expand Down Expand Up @@ -974,7 +983,15 @@ def main():
else:
raise ValueError("target must be one of %s" % ", ".join(LOCAL_TARGETS + EXTERNAL_TARGETS))

if len(args.files) == 0:
if args.run_failed:
tests = [
os.path.splitext(file.replace(args.result_dir + os.sep, ""))[0]
for file in glob(os.path.join(args.result_dir, "*.exp"))
]
for i in range(len(tests)):
for replacement in reversed(test_basename_strings):
tests[i] = tests[i].replace(replacement[1], replacement[0])
elif len(args.files) == 0:
if args.test_dirs is None:
test_dirs = (
"basics",
Expand Down

0 comments on commit 2291555

Please sign in to comment.