mirror of
https://github.com/nix-community/home-manager.git
synced 2026-01-11 01:19:32 +08:00
tests: output store path even for success
Useful when trying to double check the contents of a test directory even when the tests are passing. ie: stub a test and see the stuff you want to assert/validate. Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
@@ -92,6 +92,23 @@ class TestRunner:
|
||||
# Can happen if fzf is not found or the user cancels (non-zero exit)
|
||||
return []
|
||||
|
||||
def _get_store_path(self, test: str, nix_args: list[str]) -> str | None:
|
||||
"""Retrieve the store path of a test."""
|
||||
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:
|
||||
return build_info[0]["outputs"]["out"]
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def run_tests(self, tests_to_run: list[str], nix_args: list[str]) -> bool:
|
||||
"""Run the selected tests and report the outcome."""
|
||||
if not tests_to_run:
|
||||
@@ -112,6 +129,11 @@ class TestRunner:
|
||||
# For this command, we want output to go directly to the terminal
|
||||
result = subprocess.run(cmd, check=True, cwd=self.repo_root, capture_output=True, text=True)
|
||||
print(f"{SUCCESS_EMOJI} Test passed: {test}")
|
||||
|
||||
store_path = self._get_store_path(test, nix_args)
|
||||
if store_path:
|
||||
print(f"{INFO_EMOJI} Test directory available at: {store_path}/tested/", file=sys.stderr)
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
failed_tests.append(test)
|
||||
print(f"{FAILURE_EMOJI} Test failed: {test}", file=sys.stderr)
|
||||
@@ -138,20 +160,9 @@ class TestRunner:
|
||||
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
|
||||
store_path = self._get_store_path(test, nix_args)
|
||||
if store_path:
|
||||
print(f"{INFO_EMOJI} Test directory available at: {store_path}/tested/", file=sys.stderr)
|
||||
|
||||
print("\n--- Summary ---")
|
||||
if not failed_tests:
|
||||
|
||||
Reference in New Issue
Block a user