From 9f4c9ea7e4389b95611558ab4b4ac3c62b8cdbcb Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 9 Sep 2024 15:53:17 +0100 Subject: [PATCH] tests/generated: check packages are found in `pkgs` Fixes #2197 --- tests/generated.nix | 77 ++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/tests/generated.nix b/tests/generated.nix index 28a89ff4..51fe11eb 100644 --- a/tests/generated.nix +++ b/tests/generated.nix @@ -14,6 +14,9 @@ let { # The plugin's name name, + # A list of package paths declared in declarationFile + # A path can be either a single string, or a list; as expected by `mkPackageOption` + packages, # A list of names declared in declarationFile declared, # A list of names generated by generate-files @@ -22,50 +25,60 @@ let declarationFile, }: let + missingFromPkgs = builtins.concatMap ( + loc: lib.optional (!lib.hasAttrByPath loc pkgs) (lib.concatStringsSep "." loc) + ) (builtins.map lib.toList packages); undeclared = lib.filter (name: !(lib.elem name declared)) generated; uselesslyDeclared = lib.filter (name: !(lib.elem name generated)) declared; in - describeErrors "${name}: The following are not declared in ${declarationFile}:" undeclared + describeErrors "${name}: The following are not found in `pkgs`, but are declared in ${declarationFile}:" missingFromPkgs + ++ describeErrors "${name}: The following are not declared in ${declarationFile}:" undeclared ++ describeErrors "${name}: The following are not listed upstream, but are declared in ${declarationFile}:" uselesslyDeclared; # The error message provided to the derivation. # The test fails if this is non-empty. errors = lib.concatStringsSep "\n" ( - checkDeclarations { - name = "none-ls"; - declarationFile = "plugins/none-ls/packages.nix"; + checkDeclarations ( + let + inherit (import ../plugins/none-ls/packages.nix lib) noPackage packaged; + in + { + name = "none-ls"; + declarationFile = "plugins/none-ls/packages.nix"; - declared = - let - inherit (import ../plugins/none-ls/packages.nix lib) noPackage packaged; - in - noPackage ++ lib.attrsets.attrNames packaged; + packages = builtins.filter (pkg: pkg != null) (builtins.attrValues packaged); - generated = lib.pipe ../generated/none-ls.nix [ - import - lib.attrsets.attrValues - lib.lists.concatLists - lib.lists.unique - ]; - } - ++ checkDeclarations { - name = "efmls"; - declarationFile = "efmls-configs-pkgs.nix"; + declared = noPackage ++ lib.attrsets.attrNames packaged; - declared = - let - inherit (import ../plugins/lsp/language-servers/efmls-configs-pkgs.nix lib) packaged unpackaged; - in - unpackaged ++ lib.attrsets.attrNames packaged; + generated = lib.pipe ../generated/none-ls.nix [ + import + lib.attrsets.attrValues + lib.lists.concatLists + lib.lists.unique + ]; + } + ) + ++ checkDeclarations ( + let + inherit (import ../plugins/lsp/language-servers/efmls-configs-pkgs.nix lib) packaged unpackaged; + in + { + name = "efmls"; + declarationFile = "efmls-configs-pkgs.nix"; - generated = lib.pipe ../generated/efmls-configs.nix [ - import - lib.attrsets.attrValues - (lib.map ({ linter, formatter }: linter.possible ++ formatter.possible)) - lib.lists.concatLists - lib.lists.unique - ]; - } + packages = builtins.attrValues packaged; + + declared = unpackaged ++ lib.attrsets.attrNames packaged; + + generated = lib.pipe ../generated/efmls-configs.nix [ + import + lib.attrsets.attrValues + (lib.map ({ linter, formatter }: linter.possible ++ formatter.possible)) + lib.lists.concatLists + lib.lists.unique + ]; + } + ) ); in runCommand "generated-sources-test" { inherit errors; } ''