From 14c7f5f8968940d1730b5e935dd1d9f3e461a2d3 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 16 May 2025 05:12:26 +0100 Subject: [PATCH] dev/tests: add `--attr` option to print full attrpath of tests Allows using the `tests` devshell command to discover the full attrpath of a test. e.g. ``` $ tests --attr modules-lsp plugins-by-name-lazygit Printing 2 tests: modules-lsp plugins-by-name-lazygit Full attr paths: - checks.x86_64-linux.test-2.entries.modules-lsp - checks.x86_64-linux.test-18.entries.plugins-by-name-lazygit ``` --- flake/dev/devshell.nix | 4 ++-- flake/dev/launch-test.sh | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/flake/dev/devshell.nix b/flake/dev/devshell.nix index 3477df31..8bbc9426 100644 --- a/flake/dev/devshell.nix +++ b/flake/dev/devshell.nix @@ -61,8 +61,8 @@ checkName: map (testName: { name = testName; - value = "${checkName}.passthru.entries.${testName}"; - }) (builtins.attrNames checks'.${checkName}.passthru.entries) + value = "${checkName}.entries.${testName}"; + }) (builtins.attrNames checks'.${checkName}.entries) ) names ); in diff --git a/flake/dev/launch-test.sh b/flake/dev/launch-test.sh index 30eceb46..0873a8e6 100755 --- a/flake/dev/launch-test.sh +++ b/flake/dev/launch-test.sh @@ -19,10 +19,11 @@ Options: -l, --list: Display the list of tests and exit -s, --system : Launch checks for "" instead of "${NIXVIM_SYSTEM}". -i, --interactive: Pick interactively the tests. Can't be supplied if tests where passed. + -a, --attr: Print full attrpath of the tests, instead of running them. EOF } -if ! OPTS=$(getopt -o "hlis:" -l "help,list,interactive,system:" -- "$@"); then +if ! OPTS=$(getopt -o "hlis:a" -l "help,list,interactive,system:,attr" -- "$@"); then echo "Invalid options" >&2 help exit 1 @@ -34,6 +35,7 @@ system=${NIXVIM_SYSTEM} specified_tests=() nix_args=() interactive=false +print_attrpath=false mk_test_list() { jq -r 'keys[]' "${NIXVIM_TESTS}" @@ -57,6 +59,10 @@ while true; do system=$2 shift 2 ;; + -a | --attr) + print_attrpath=true + shift 1 + ;; --) shift for arg in "$@"; do @@ -90,7 +96,13 @@ get_tests() { run_tests() { readarray -t test_list < <(get_tests "$@") - if ! "${NIXVIM_NIX_COMMAND}" build "${nix_args[@]}" --no-link --file . "${test_list[@]}"; then + if [[ $print_attrpath == true ]]; then + echo + echo "Full attr paths:" + for test in "${test_list[@]}"; do + echo "- $test" + done + elif ! "${NIXVIM_NIX_COMMAND}" build "${nix_args[@]}" --no-link --file . "${test_list[@]}"; then echo "Test failure" >&2 exit 1 fi @@ -110,6 +122,10 @@ if [[ ${#specified_tests[@]} -eq 0 ]]; then readarray -t complete_test_list < <(mk_test_list) run_tests "${complete_test_list[@]}" else - echo "Running ${#specified_tests[@]} tests: ${specified_tests[*]}" >&2 + verb="Running" + if [[ $print_attrpath == true ]]; then + verb="Printing" + fi + echo "$verb ${#specified_tests[@]} tests: ${specified_tests[*]}" >&2 run_tests "${specified_tests[@]}" fi