vimPlugins.nvim-treesitter.tests: use best practises for bash
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user