Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/nixpkgs: move nixpkgs module test to dedicated drv #2740

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ in
extra-files = callTest ./extra-files.nix { };
enable-except-in-tests = callTest ./enable-except-in-tests.nix { };
failing-tests = callTest ./failing-tests.nix { };
nixpkgs-module = callTest ./nixpkgs-module.nix { };
no-flake = callTest ./no-flake.nix { };
lib-tests = callTest ./lib-tests.nix { };
maintainers = callTest ./maintainers.nix { };
Expand Down
115 changes: 115 additions & 0 deletions tests/nixpkgs-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
lib,
linkFarmFromDrvs,
nixvimConfiguration,
runCommandNoCCLocal,
self,
system,
}:
let
# Writes a runCommand style derivation based on a nixvim module's output
testModule =
{
name,
module,
drvArgs,
script,
}:
let
configuration = nixvimConfiguration.extendModules {
modules = lib.toList module;
};
finalDrvArgs = {
__structuredAttrs = true;
} // drvArgs (configuration._module.args // configuration);
in
runCommandNoCCLocal name finalDrvArgs script;

# Writes a test derivation that checks specific variables have the expected values
testExpectations =
{
name,
module,
drvArgs,
expectations,
}:
let
checks = lib.concatLines (
lib.mapAttrsToList (name: expected: ''
${lib.toShellVar "_expected" expected}
if [ "${"$" + name}" != "$_expected" ]; then
error+='- Expected ${name} to be "'"$_expected"'" but found "'"${"$" + name}"'"'
fi
'') expectations
);
in
testModule {
inherit name module drvArgs;
script = ''
error=""
${checks}
if [ -n "$error" ]; then
echo "${name} failed:"
echo "$error"
exit 1
fi
touch $out
'';
};

# Further simplifies `testExpectations` when all the expectations relate to attrs in `pkgs`
testPkgsExpectations =
{
name,
module,
expectations,
}:
testExpectations {
inherit name module expectations;
drvArgs = { pkgs, ... }: lib.mapAttrs (name: _: pkgs.${name} or null) expectations;
};
in
linkFarmFromDrvs "nixpkgs-module-tests" [

(testPkgsExpectations {
name = "overlays-are-applied";
module = {
nixpkgs.overlays = [
(final: prev: {
foobar = "foobar";
})
];
};
expectations = {
foobar = "foobar";
};
})

(testPkgsExpectations {
name = "overlays-can-be-stacked";
module = {
nixpkgs.pkgs = import self.inputs.nixpkgs {
inherit system;
overlays = [
(final: prev: {
foobar = "foobar";
conflict = "a";
})
];
};
nixpkgs.overlays = [
(final: prev: {
hello = "world";
conflict = "b";
})
];

};
expectations = {
foobar = "foobar";
hello = "world";
conflict = "b";
};
})

]
74 changes: 0 additions & 74 deletions tests/test-sources/modules/nixpkgs.nix

This file was deleted.