Unverified Commit 146b74e1 authored by Matt Sturgeon's avatar Matt Sturgeon Committed by GitHub
Browse files

vimPlugins.nvim-treesitter.tests: fix (#458803)

parents 0f3d9b1a afa668c7
Loading
Loading
Loading
Loading
+25 −19
Original line number Diff line number Diff line
@@ -112,47 +112,53 @@ in
        let
          pluginsToCheck =
            map (grammar: grammarToPlugin grammar)
              # true is here because there is `recurseForDerivations = true`
              (lib.remove true (lib.attrValues tree-sitter-grammars));
              # non-derivations are here because there is a `recurseForDerivations = true`
              (lib.filter lib.isDerivation (lib.attrValues tree-sitter-grammars));
        in
        runCommand "nvim-treesitter-test-queries-are-present-for-custom-grammars" { CI = true; } ''
          touch "$out"

          function check_grammar {
            EXPECTED_FILES="$2/parser/$1.so `ls $2/queries/$1/*.scm`"
            local grammar_name="$1"
            local grammar_path="$2"

            local grammar_queries=$(find -L "$grammar_path/queries/$grammar_name" -name '*.scm')
            local EXPECTED_FILES="$grammar_path/parser/$grammar_name.so $grammar_queries"

            echo
            echo expected files for $1:
            echo $EXPECTED_FILES
            echo ""
            echo "expected files for $grammar_name:"
            echo "$EXPECTED_FILES"

            # the derivation has only symlinks, and `find` doesn't count them as files
            # so we cannot use `-type f`
            for file in `find $2 -not -type d`; do
              echo checking $file
            # so we cannot use `-type f`, thus we use `-not -type d`
            for file in $(find -L $2 -not -type d); do
              echo "checking $file"
              # see https://stackoverflow.com/a/8063284
              if ! echo "$EXPECTED_FILES" | grep -wqF "$file"; then
                echo $file is unexpected, exiting
                echo "$file is unexpected, exiting"
                exit 1
              fi
            done
          }

          ${lib.concatLines (lib.forEach pluginsToCheck (g: "check_grammar \"${g.grammarName}\" \"${g}\""))}
          touch $out
        '';

      no-queries-for-official-grammars =
        let
          pluginsToCheck =
            # true is here because there is `recurseForDerivations = true`
            (lib.remove true (lib.attrValues vimPlugins.nvim-treesitter-parsers));
          pluginsToCheck = lib.filter lib.isDerivation (lib.attrValues vimPlugins.nvim-treesitter-parsers);
        in
        runCommand "nvim-treesitter-test-no-queries-for-official-grammars" { CI = true; } ''
          touch $out
          touch "$out"

          function check_grammar {
            echo checking $1...
            if [ -d $2/queries ]; then
              echo Queries dir exists in $1
              echo This is unexpected, see https://github.com/NixOS/nixpkgs/pull/344849#issuecomment-2381447839
            local grammar_name="$1"
            local grammar_path="$2"

            echo "checking $1..."
            if [ -d "$grammar_path/queries" ]; then
              echo "Queries directory exists in $grammar_name"
              echo "This is unexpected, see https://github.com/NixOS/nixpkgs/pull/344849#issuecomment-2381447839"
              exit 1
            fi
          }