flake-modules/devshell: update tests command with link-farm support

Since we're using link-farms, we need to access the underlying tests as
`passthru.entries.*`.
This commit is contained in:
Matt Sturgeon 2024-08-19 03:55:56 +01:00
parent 69c2fa866e
commit 312db6b6e2
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 40 additions and 5 deletions

View file

@ -7,6 +7,7 @@
lib,
pkgs,
config,
self',
system,
...
}:
@ -44,9 +45,27 @@
text = builtins.readFile ./launch-test.sh;
};
tests =
let
checks' = self'.checks;
names = builtins.filter (n: builtins.match "test-.*" n != null) (builtins.attrNames checks');
in
builtins.listToAttrs (
builtins.concatMap (
checkName:
map (testName: {
name = testName;
value = "${checkName}.passthru.entries.${testName}";
}) (builtins.attrNames checks'.${checkName}.passthru.entries)
) names
);
in
''
NIXVIM_SYSTEM=${system} NIXVIM_NIX_COMMAND=${nix} ${lib.getExe launchTest} "$@"
export NIXVIM_SYSTEM=${system}
export NIXVIM_NIX_COMMAND=${nix}
export NIXVIM_TESTS=${pkgs.writers.writeJSON "tests.json" tests}
${lib.getExe launchTest} "$@"
'';
}
{

View file

@ -36,8 +36,7 @@ nix_args=()
interactive=false
mk_test_list() {
nix eval ".#checks.${system}" --apply builtins.attrNames --json |
jq -r 'map(select(startswith("test-")))[]'
jq -r 'keys[]' "${NIXVIM_TESTS}"
}
while true; do
@ -72,9 +71,26 @@ while true; do
esac
done
get_tests() {
# Convert bash array to jq query
# e.g. (foo bar baz) => ."foo",."bar",."baz"
readarray -t queries < <(
for test in "$@"; do
echo '."'"$test"'"'
done
)
query=$(
IFS=,
echo "${queries[*]}"
)
for test in $(jq -r "${query}" "${NIXVIM_TESTS}"); do
echo "checks.${system}.${test}"
done
}
run_tests() {
# Add the prefix "checks.${system}." to each argument
if ! "${NIXVIM_NIX_COMMAND}" build "${nix_args[@]}" --no-link --file . "${@/#/checks.${system}.}"; then
readarray -t test_list < <(get_tests "$@")
if ! "${NIXVIM_NIX_COMMAND}" build "${nix_args[@]}" --no-link --file . "${test_list[@]}"; then
echo "Test failure" >&2
exit 1
fi