From afa668c7550a7221fb02ba02ac02f367ed4eccdd Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Wed, 5 Nov 2025 13:32:19 +0100 Subject: [PATCH] vimPlugins.nvim-treesitter.tests: use best practises for bash --- .../vim/plugins/nvim-treesitter/overrides.nix | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix b/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix index fbb3619e0622..75623015e165 100644 --- a/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix +++ b/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix @@ -112,31 +112,36 @@ in let pluginsToCheck = map (grammar: grammarToPlugin grammar) - # true is here because there is `recurseForDerivations = true` + # 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; } '' - function check_grammar { - EXPECTED_FILES="$2/parser/$1.so `find -L "$2/queries/$1" -name '*.scm'`" + touch "$out" - echo - echo expected files for $1: - echo $EXPECTED_FILES + function check_grammar { + 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 $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 -L $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 = @@ -144,13 +149,16 @@ in 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 }