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

introducing: per-module checks #309

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions pkgs/moduleit/module-definition.nix
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ in
};

};

checks = mkOption {
type = types.attrsOf types.package;
default = { };
description = "module tests";
};
};

config = {
Expand Down
8 changes: 8 additions & 0 deletions pkgs/modules/interpreters/nodejs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ with pkgs.lib; {
};

config = mkIf cfg.enable {
checks.nodejs = pkgs.writeShellScript "nodejs-check" ''
output=$(${nodejs-wrapped}/bin/node --version)
if [ "$output" != "v${nodejs-wrapped.version}" ]; then
echo "Node.js version mismatch: expected v${nodejs-wrapped.version}, got $output"
exit 1
fi
Comment on lines +40 to +44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test could've caught a bug in a previous release of v1!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this will be very important when we enforce version pinning. Do not want to accidentally upgrade the version by upgrading a Nix channel.

'';

replit = {
packages = [
nodejs-wrapped
Expand Down
19 changes: 18 additions & 1 deletion pkgs/v2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ let
in
pkgs.writeText "registry.json" (builtins.toJSON getRegistryResponse);

check = module:
pkgs.writeShellScript "modules-checks"
(pipe ([ module ] ++ allModules) [
myEvalModules
(getAttrFromPath [ "config" "checks" ])
(mapAttrsToList (suite-name: check: ''
printf 'Running test ${suite-name}...'
output=$(sh ${check})
case $? in
0) echo 'OK' ;;
*) echo 'FAILED'
echo $output
;;
esac
''))
concatLines
]);
in
{
examples = {
Expand All @@ -275,5 +292,5 @@ in
nodejs = buildModule ./examples/nodejs.nix;
};

inherit buildDotReplit registry;
inherit buildDotReplit check registry;
}
Loading