Skip to content

Commit ad1e615

Browse files
committed
lib.types: add module tests for fileset
1 parent 9c00c9a commit ad1e615

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

lib/tests/modules.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ checkConfigError 'A definition for option .* is not of type .path in the Nix sto
220220
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
221221
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
222222

223+
# types.fileset
224+
checkConfigOutput '^0$' config.filesetCardinal.ok1 ./fileset.nix
225+
checkConfigOutput '^1$' config.filesetCardinal.ok2 ./fileset.nix
226+
checkConfigOutput '^1$' config.filesetCardinal.ok3 ./fileset.nix
227+
checkConfigOutput '^1$' config.filesetCardinal.ok4 ./fileset.nix
228+
checkConfigOutput '^0$' config.filesetCardinal.ok5 ./fileset.nix
229+
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err1 ./fileset.nix
230+
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err2 ./fileset.nix
231+
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err3 ./fileset.nix
232+
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err4 ./fileset.nix
233+
223234
# Check boolean option.
224235
checkConfigOutput '^false$' config.enable ./declare-enable.nix
225236
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix

lib/tests/modules/fileset.nix

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{ config, lib, ... }:
2+
3+
let
4+
inherit (lib)
5+
mkOption
6+
mkIf
7+
types
8+
mapAttrs
9+
length
10+
;
11+
inherit (lib.fileset)
12+
empty
13+
unions
14+
toList
15+
;
16+
in
17+
18+
{
19+
options = {
20+
fileset = mkOption { type = with types; lazyAttrsOf fileset; };
21+
22+
## The following option is only here as a proxy to test `fileset` that does
23+
## not work so well with `modules.sh` because it is not JSONable. It exposes
24+
## the number of elements in the fileset.
25+
filesetCardinal = mkOption { default = mapAttrs (_: fs: length (toList fs)) config.fileset; };
26+
};
27+
28+
config = {
29+
fileset.ok1 = empty;
30+
fileset.ok2 = ./fileset;
31+
fileset.ok3 = unions [
32+
empty
33+
./fileset
34+
];
35+
# fileset.ok4: see imports below
36+
fileset.ok5 = mkIf false ./fileset;
37+
38+
fileset.err1 = 1;
39+
fileset.err2 = "foo";
40+
fileset.err3 = "./.";
41+
fileset.err4 = [ empty ];
42+
43+
};
44+
45+
imports = [
46+
{ fileset.ok4 = ./fileset; }
47+
{ fileset.ok4 = empty; }
48+
{ fileset.ok4 = ./fileset; }
49+
];
50+
}

lib/tests/modules/fileset/keepme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not remove. This file is used by the tests in `../fileset.nix`.

0 commit comments

Comments
 (0)