From db7c5364a58e1d9519bb4e1e0e13abb0a368376f Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 1 Jul 2025 01:51:58 +0100 Subject: [PATCH] tests: use a nested attrset for buildbot We need to optimise the buildbot attrs for nix-eval-jobs, however this doesn't make sense for `nix flake check` or `nix flake show`. Now that we aren't using the `checks` output, we don't _need_ to restrict ourselves to a flat set of test derivations anymore. This also simplifies our `tests` command, and means we no longer need to pre-compute the test attr names. --- flake/dev/devshell.nix | 16 ---------------- flake/dev/launch-test.sh | 28 +++++++++------------------- tests/default.nix | 6 +++--- 3 files changed, 12 insertions(+), 38 deletions(-) diff --git a/flake/dev/devshell.nix b/flake/dev/devshell.nix index 2babef5d..b31ee96d 100644 --- a/flake/dev/devshell.nix +++ b/flake/dev/devshell.nix @@ -59,26 +59,10 @@ 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}.entries.${testName}"; - }) (builtins.attrNames checks'.${checkName}.entries) - ) names - ); in '' export NIXVIM_SYSTEM=${system} export NIXVIM_NIX_COMMAND=${nix} - export NIXVIM_TESTS=${pkgs.writers.writeJSON "tests.json" tests} ${lib.getExe launchTest} "$@" ''; } diff --git a/flake/dev/launch-test.sh b/flake/dev/launch-test.sh index d8a1b866..f70a3450 100755 --- a/flake/dev/launch-test.sh +++ b/flake/dev/launch-test.sh @@ -40,7 +40,10 @@ group_size=20 print_attrpath=false mk_test_list() { - jq -r 'keys[]' "${NIXVIM_TESTS}" + nix eval ".#checks.$system.tests.entries" \ + --apply builtins.attrNames \ + --json | + jq -r '.[]' } while true; do @@ -83,23 +86,6 @@ 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 -} - build_group() { if ! "${NIXVIM_NIX_COMMAND}" build "${nix_args[@]}" --no-link --file . "$@"; then echo "Test failure" >&2 @@ -145,7 +131,11 @@ build_in_groups() { } run_tests() { - readarray -t test_list < <(get_tests "$@") + readarray -t test_list < <( + for test in "$@"; do + echo "checks.${system}.tests.entries.${test}" + done + ) if [[ $print_attrpath == true ]]; then echo echo "Full attr paths:" diff --git a/tests/default.nix b/tests/default.nix index 1da61795..3f40862a 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -61,12 +61,12 @@ let # Combined into a single link-farm derivation mainDrv.tests = linkFarm "tests" main; - # Grouped as a number of link-farms in the form { test-1, test-2, ... test-N } - mainGrouped = lib.pipe main [ + # Grouped as a number of link-farms in the form { tests = { group-1, group-2, ... group-N }; } + mainGrouped.tests = lib.pipe main [ (helpers.groupListBySize 10) (lib.imap1 ( i: group: rec { - name = "test-${toString i}"; + name = "group-${toString i}"; value = linkFarm name group; } ))