lib.types: add module tests for fileset

This commit is contained in:
Niols
2025-08-29 13:07:55 +02:00
parent 9c00c9af71
commit ad1e615f48
3 changed files with 62 additions and 0 deletions
+11
View File
@@ -220,6 +220,17 @@ checkConfigError 'A definition for option .* is not of type .path in the Nix sto
checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/.links"' config.pathInStore.bad4 ./types.nix
checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: "/foo/bar"' config.pathInStore.bad5 ./types.nix
# types.fileset
checkConfigOutput '^0$' config.filesetCardinal.ok1 ./fileset.nix
checkConfigOutput '^1$' config.filesetCardinal.ok2 ./fileset.nix
checkConfigOutput '^1$' config.filesetCardinal.ok3 ./fileset.nix
checkConfigOutput '^1$' config.filesetCardinal.ok4 ./fileset.nix
checkConfigOutput '^0$' config.filesetCardinal.ok5 ./fileset.nix
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err1 ./fileset.nix
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err2 ./fileset.nix
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err3 ./fileset.nix
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err4 ./fileset.nix
# Check boolean option.
checkConfigOutput '^false$' config.enable ./declare-enable.nix
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
+50
View File
@@ -0,0 +1,50 @@
{ config, lib, ... }:
let
inherit (lib)
mkOption
mkIf
types
mapAttrs
length
;
inherit (lib.fileset)
empty
unions
toList
;
in
{
options = {
fileset = mkOption { type = with types; lazyAttrsOf fileset; };
## The following option is only here as a proxy to test `fileset` that does
## not work so well with `modules.sh` because it is not JSONable. It exposes
## the number of elements in the fileset.
filesetCardinal = mkOption { default = mapAttrs (_: fs: length (toList fs)) config.fileset; };
};
config = {
fileset.ok1 = empty;
fileset.ok2 = ./fileset;
fileset.ok3 = unions [
empty
./fileset
];
# fileset.ok4: see imports below
fileset.ok5 = mkIf false ./fileset;
fileset.err1 = 1;
fileset.err2 = "foo";
fileset.err3 = "./.";
fileset.err4 = [ empty ];
};
imports = [
{ fileset.ok4 = ./fileset; }
{ fileset.ok4 = empty; }
{ fileset.ok4 = ./fileset; }
];
}
+1
View File
@@ -0,0 +1 @@
Do not remove. This file is used by the tests in `../fileset.nix`.