diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index fbbccd8172f6..b388f7d8aefe 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -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 diff --git a/lib/tests/modules/fileset.nix b/lib/tests/modules/fileset.nix new file mode 100644 index 000000000000..40b1a8ef601f --- /dev/null +++ b/lib/tests/modules/fileset.nix @@ -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; } + ]; +} diff --git a/lib/tests/modules/fileset/keepme b/lib/tests/modules/fileset/keepme new file mode 100644 index 000000000000..27b2fabd2c27 --- /dev/null +++ b/lib/tests/modules/fileset/keepme @@ -0,0 +1 @@ +Do not remove. This file is used by the tests in `../fileset.nix`.