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
Implement the typical 're-run the failed tests' most test runners
have for convenience.  Works by constructing the original test name
back from the .exp files, so does require the current directory to
be the same unless full test paths were used.

Signed-off-by: stijn <[email protected]>
  • Loading branch information
stinos committed Dec 14, 2023
1 parent 05d3b22 commit c82f5e1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ 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 +678,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 +915,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 +984,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 c82f5e1

Please sign in to comment.