mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
tests: improve debugging for failed test runs
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
e9114f96ef
commit
6ee8473173
1 changed files with 40 additions and 3 deletions
|
|
@ -105,17 +105,54 @@ class TestRunner:
|
||||||
for i, test in enumerate(tests_to_run, 1):
|
for i, test in enumerate(tests_to_run, 1):
|
||||||
print(f"\n--- Running test {i}/{count}: {test} ---")
|
print(f"\n--- Running test {i}/{count}: {test} ---")
|
||||||
cmd = [
|
cmd = [
|
||||||
"nix", "build", "-L", "--reference-lock-file", "flake.lock",
|
"nix", "build", "-L", "--keep-failed", "--reference-lock-file", "flake.lock",
|
||||||
f"./tests#{test}", *nix_args
|
f"./tests#{test}", *nix_args
|
||||||
]
|
]
|
||||||
try:
|
try:
|
||||||
# For this command, we want output to go directly to the terminal
|
# 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}")
|
print(f"{SUCCESS_EMOJI} Test passed: {test}")
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as e:
|
||||||
failed_tests.append(test)
|
failed_tests.append(test)
|
||||||
print(f"{FAILURE_EMOJI} Test failed: {test}", file=sys.stderr)
|
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 ---")
|
print("\n--- Summary ---")
|
||||||
if not failed_tests:
|
if not failed_tests:
|
||||||
print(f"{SUCCESS_EMOJI} All {count} tests passed!")
|
print(f"{SUCCESS_EMOJI} All {count} tests passed!")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue