lol

lib/tests: Add tests for attrsOf and lazyAttrsOf

authored by

Silvan Mosberger and committed by
Silvan Mosberger
ab10e874 b48717d1

+35
+9
lib/tests/modules.sh
··· 186 186 # Check that imports can depend on derivations 187 187 checkConfigOutput "true" config.enable ./import-from-store.nix 188 188 189 + # Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only 190 + # attrsOf should work with conditional definitions 191 + # In addition, lazyAttrsOf should honor an options emptyValue 192 + checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix 193 + checkConfigOutput "true" config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix 194 + checkConfigOutput "true" config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix 195 + checkConfigOutput "false" config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix 196 + checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix 197 + 189 198 cat <<EOF 190 199 ====== module tests ====== 191 200 $pass Pass
+7
lib/tests/modules/attrsOf-conditional-check.nix
··· 1 + { lib, config, ... }: { 2 + options.conditionalWorks = lib.mkOption { 3 + default = ! config.value ? foo; 4 + }; 5 + 6 + config.value.foo = lib.mkIf false "should not be defined"; 7 + }
+7
lib/tests/modules/attrsOf-lazy-check.nix
··· 1 + { lib, config, ... }: { 2 + options.isLazy = lib.mkOption { 3 + default = ! config.value ? foo; 4 + }; 5 + 6 + config.value.bar = throw "is not lazy"; 7 + }
+6
lib/tests/modules/declare-attrsOf.nix
··· 1 + { lib, ... }: { 2 + options.value = lib.mkOption { 3 + type = lib.types.attrsOf lib.types.str; 4 + default = {}; 5 + }; 6 + }
+6
lib/tests/modules/declare-lazyAttrsOf.nix
··· 1 + { lib, ... }: { 2 + options.value = lib.mkOption { 3 + type = lib.types.lazyAttrsOf (lib.types.str // { emptyValue.value = "empty"; }); 4 + default = {}; 5 + }; 6 + }