From 6ee8473173af7a0181a788e8a3d4fa164f4cc72c Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 23 Sep 2025 14:57:45 -0500 Subject: [PATCH] tests: improve debugging for failed test runs Signed-off-by: Austin Horstman --- tests/tests.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index c4cf61fe5..7847cf9f3 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -105,17 +105,54 @@ class TestRunner: for i, test in enumerate(tests_to_run, 1): print(f"\n--- Running test {i}/{count}: {test} ---") cmd = [ - "nix", "build", "-L", "--reference-lock-file", "flake.lock", + "nix", "build", "-L", "--keep-failed", "--reference-lock-file", "flake.lock", f"./tests#{test}", *nix_args ] try: # For this command, we want output to go directly to the terminal - subprocess.run(cmd, check=True, cwd=self.repo_root) + result = subprocess.run(cmd, check=True, cwd=self.repo_root, capture_output=True, text=True) print(f"{SUCCESS_EMOJI} Test passed: {test}") - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as e: failed_tests.append(test) print(f"{FAILURE_EMOJI} Test failed: {test}", file=sys.stderr) + if e.stderr: + print(e.stderr, file=sys.stderr) + + import re + if e.stderr: + build_dir_match = re.search(r"keeping build directory '([^']+)'", e.stderr) + if build_dir_match: + build_dir = build_dir_match.group(1) + try: + import glob + attr_files = glob.glob(f"{build_dir}/.attr-*") + for attr_file in attr_files: + with open(attr_file, 'r') as f: + content = f.read() + tested_match = re.search(r'TESTED="([^"]+)"', content) + if tested_match: + tested_path = tested_match.group(1) + print(f"{INFO_EMOJI} Generated test directory at: {tested_path}/", file=sys.stderr) + break + except Exception: + print(f"{INFO_EMOJI} Build directory available at: {build_dir}", file=sys.stderr) + + try: + store_cmd = [ + "nix", "build", "--no-link", "--json", "--reference-lock-file", "flake.lock", + f"./tests#{test}", *nix_args + ] + result = _run_command(store_cmd, cwd=self.repo_root, check=False) + if result.returncode == 0: + import json + build_info = json.loads(result.stdout) + if build_info: + store_path = build_info[0]["outputs"]["out"] + print(f"{INFO_EMOJI} Test directory available at: {store_path}/tested/", file=sys.stderr) + except Exception: + pass + print("\n--- Summary ---") if not failed_tests: print(f"{SUCCESS_EMOJI} All {count} tests passed!")