diff --git a/flake-modules/dev/default.nix b/flake-modules/dev/default.nix index b5a6c2456a..617dd5cf44 100644 --- a/flake-modules/dev/default.nix +++ b/flake-modules/dev/default.nix @@ -34,6 +34,7 @@ }; statix.enable = true; stylua.enable = true; + shfmt.enable = true; taplo.enable = true; }; diff --git a/flake-modules/dev/devshell.nix b/flake-modules/dev/devshell.nix index d1ef469c9f..7eb39cafb1 100644 --- a/flake-modules/dev/devshell.nix +++ b/flake-modules/dev/devshell.nix @@ -32,11 +32,21 @@ { name = "tests"; help = "Run nixvim tests"; - command = '' - echo "=> Running nixvim tests for the '${system}' architecture..." + command = + let + launchTest = pkgs.writeShellApplication { + name = "launch-tests"; + runtimeInputs = with pkgs; [ + jq + fzf + ]; - ${nix} build .#checks.${system}.tests "$@" - ''; + text = builtins.readFile ./launch-test.sh; + }; + in + '' + NIXVIM_SYSTEM=${system} NIXVIM_NIX_COMMAND=${nix} ${lib.getExe launchTest} "$@" + ''; } { name = "test-lib"; diff --git a/flake-modules/dev/launch-test.sh b/flake-modules/dev/launch-test.sh new file mode 100755 index 0000000000..7cf194705b --- /dev/null +++ b/flake-modules/dev/launch-test.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +: "${NIXVIM_NIX_COMMAND:=nix}" +if [[ -z ${NIXVIM_SYSTEM+x} ]]; then + NIXVIM_SYSTEM=$(nix eval --raw --impure --expr "builtins.currentSystem") +fi + +help() { + cat <&2 + help + exit 1 +fi + +eval set -- "$OPTS" + +specified_tests=() +interactive=false + +mk_test_list() { + nix eval ".#checks.${NIXVIM_SYSTEM}" --apply builtins.attrNames --json | + jq -r 'map(select(startswith("test-")))[]' +} + +while true; do + case "$1" in + -h | --help) + help + exit 0 + ;; + -l | --list) + mk_test_list + exit 0 + ;; + -i | --interactive) + interactive=true + shift + ;; + --) + shift + specified_tests=("$@") + break + ;; + esac +done + +run_tests() { + # Add the prefix "checks.${system}." to each argument + if ! "${NIXVIM_NIX_COMMAND}" build --no-link --file . "${@/#/checks.${NIXVIM_SYSTEM}.}"; then + echo "Test failure" >&2 + exit 1 + fi +} + +if [[ $interactive = true && ${#specified_tests[@]} -ne 0 ]]; then + echo "Can't use --interactive with tests on the command line" >&2 + exit 1 +fi + +if [[ $interactive = true ]]; then + test_name=$(mk_test_list | fzf) || exit $? + specified_tests+=("$test_name") +fi + +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 + run_tests "${specified_tests[@]}" +fi diff --git a/flake-modules/tests.nix b/flake-modules/tests.nix index 7e6789d4d8..d2ffacf779 100644 --- a/flake-modules/tests.nix +++ b/flake-modules/tests.nix @@ -10,42 +10,42 @@ ... }: { - checks = { - tests = import ../tests { - inherit - pkgs - pkgsUnfree - helpers - makeNixvimWithModule - ; - }; - - extra-args-tests = import ../tests/extra-args.nix { - inherit pkgs; - inherit makeNixvimWithModule; - }; + checks = + { + extra-args-tests = import ../tests/extra-args.nix { + inherit pkgs; + inherit makeNixvimWithModule; + }; - extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; }; + extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; }; - extra-files = import ../tests/extra-files.nix { inherit pkgs makeNixvimWithModule; }; + extra-files = import ../tests/extra-files.nix { inherit pkgs makeNixvimWithModule; }; - enable-except-in-tests = import ../tests/enable-except-in-tests.nix { - inherit pkgs makeNixvimWithModule; - inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; - }; + enable-except-in-tests = import ../tests/enable-except-in-tests.nix { + inherit pkgs makeNixvimWithModule; + inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; + }; - no-flake = import ../tests/no-flake.nix { - inherit system; - inherit (self.lib.${system}.check) mkTestDerivationFromNvim; - nixvim = "${self}"; - }; + no-flake = import ../tests/no-flake.nix { + inherit system; + inherit (self.lib.${system}.check) mkTestDerivationFromNvim; + nixvim = "${self}"; + }; - lib-tests = import ../tests/lib-tests.nix { - inherit pkgs helpers; - inherit (pkgs) lib; - }; + lib-tests = import ../tests/lib-tests.nix { + inherit pkgs helpers; + inherit (pkgs) lib; + }; - maintainers = import ../tests/maintainers.nix { inherit pkgs; }; - }; + maintainers = import ../tests/maintainers.nix { inherit pkgs; }; + } + // (import ../tests { + inherit + pkgs + pkgsUnfree + helpers + makeNixvimWithModule + ; + }); }; } diff --git a/tests/default.nix b/tests/default.nix index c19d9a9d75..7af515923f 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -35,10 +35,12 @@ let } ]; }; - - # We attempt to build & execute all configurations - derivationList = builtins.map ( +in +# We attempt to build & execute all configurations +builtins.listToAttrs ( + builtins.map ( { name, cases }: + let # The test case can either be the actual definition, # or a child attr named `module`. @@ -46,8 +48,8 @@ let dontRunModule = case: case.tests.dontRun or false; in { - inherit name; - path = mkTestDerivationFromNixvimModule { + name = "test-${name}"; + value = mkTestDerivationFromNixvimModule { inherit name; tests = builtins.map ( { name, case }: @@ -62,6 +64,5 @@ let pkgs = pkgsUnfree; }; } - ) (testFiles ++ [ exampleFiles ]); -in -pkgs.linkFarm "nixvim-tests" derivationList + ) (testFiles ++ [ exampleFiles ]) +)