1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00

tests: improve debugging for failed test runs

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-09-23 14:57:45 -05:00
parent e9114f96ef
commit 6ee8473173

View file

@ -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!")