clan/checks: move into lib function; add tests
This commit is contained in:
@@ -56,15 +56,8 @@ in
|
||||
}
|
||||
];
|
||||
};
|
||||
apply =
|
||||
config:
|
||||
lib.deepSeq (lib.mapAttrs (
|
||||
id: check:
|
||||
if check.ignore || check.assertion then
|
||||
null
|
||||
else
|
||||
throw "clan.checks.${id} failed with message\n${check.message}"
|
||||
) config.checks) config;
|
||||
# Important: !This logic needs to be kept in sync with lib.clan function!
|
||||
apply = config: clan-core.lib.checkConfig config.checks config;
|
||||
};
|
||||
|
||||
# Mapped flake toplevel outputs
|
||||
|
||||
19
lib/clan/checkConfig.nix
Normal file
19
lib/clan/checkConfig.nix
Normal file
@@ -0,0 +1,19 @@
|
||||
{ lib, ... }:
|
||||
/**
|
||||
Function to assert clan configuration checks.
|
||||
|
||||
Arguments:
|
||||
|
||||
- 'checks' attribute of clan configuration
|
||||
- Any: the returned configuration (can be anything, is just passed through)
|
||||
*/
|
||||
checks:
|
||||
lib.deepSeq (
|
||||
lib.mapAttrs (
|
||||
id: check:
|
||||
if check.ignore || check.assertion then
|
||||
null
|
||||
else
|
||||
throw "clan.checks.${id} failed with message\n${check.message}"
|
||||
) checks
|
||||
)
|
||||
@@ -33,7 +33,7 @@
|
||||
let
|
||||
nixpkgs = self.inputs.nixpkgs or clan-core.inputs.nixpkgs;
|
||||
nix-darwin = self.inputs.nix-darwin or clan-core.inputs.nix-darwin;
|
||||
in
|
||||
configuration = (
|
||||
lib.evalModules {
|
||||
class = "clan";
|
||||
specialArgs = {
|
||||
@@ -50,3 +50,6 @@ lib.evalModules {
|
||||
m
|
||||
];
|
||||
}
|
||||
);
|
||||
in
|
||||
clan-core.clanLib.checkConfig configuration.config.checks configuration
|
||||
|
||||
@@ -16,6 +16,8 @@ lib.fix (
|
||||
*/
|
||||
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
||||
|
||||
checkConfig = clanLib.callLib ./clan/checkConfig.nix { };
|
||||
|
||||
evalService = clanLib.callLib ./evalService.nix { };
|
||||
# ------------------------------------
|
||||
# ClanLib functions
|
||||
|
||||
@@ -212,6 +212,36 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
test_clan_check_simple_fail =
|
||||
let
|
||||
eval = clan {
|
||||
checks.constFail = {
|
||||
assertion = false;
|
||||
message = "This is a constant failure";
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
result = eval;
|
||||
expr = eval.config;
|
||||
expectedError.type = "ThrownError";
|
||||
expectedError.msg = "This is a constant failure";
|
||||
};
|
||||
test_clan_check_simple_pass =
|
||||
let
|
||||
eval = clan {
|
||||
checks.constFail = {
|
||||
assertion = true;
|
||||
message = "This is a constant success";
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
result = eval;
|
||||
expr = lib.seq eval.config 42;
|
||||
expected = 42;
|
||||
};
|
||||
|
||||
test_get_var_machine =
|
||||
let
|
||||
varsLib = import ./vars.nix { };
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
/**
|
||||
Root 'clan' Module
|
||||
|
||||
Defines lib.clan and flake-parts.clan options
|
||||
and all common logic for the 'clan' module.
|
||||
|
||||
- has Class _class = "clan"
|
||||
|
||||
- _module.args.clan-core: reference to clan-core flake
|
||||
- _module.args.clanLib: reference to lib.clan function
|
||||
*/
|
||||
{ clan-core }:
|
||||
{
|
||||
_class = "clan";
|
||||
|
||||
Reference in New Issue
Block a user