diff options
author | Silvan Mosberger <contact@infinisil.com> | 2020-01-01 01:11:45 +0100 |
---|---|---|
committer | Silvan Mosberger <contact@infinisil.com> | 2020-01-02 09:59:35 +0100 |
commit | cc81320a46d8f822da90c84aeb413de3e9b5f4a8 (patch) | |
tree | 47cfcef66308ad7f7f134c66838cd68ba180f99a /lib/tests | |
parent | eec83d41e3e7d9ad5bc1086198d972d55bab1203 (diff) |
lib/tests: Add submoduleWith tests
Diffstat (limited to 'lib/tests')
-rwxr-xr-x | lib/tests/modules.sh | 18 | ||||
-rw-r--r-- | lib/tests/modules/declare-submoduleWith-modules.nix | 30 | ||||
-rw-r--r-- | lib/tests/modules/declare-submoduleWith-noshorthand.nix | 13 | ||||
-rw-r--r-- | lib/tests/modules/declare-submoduleWith-path.nix | 12 | ||||
-rw-r--r-- | lib/tests/modules/declare-submoduleWith-shorthand.nix | 14 | ||||
-rw-r--r-- | lib/tests/modules/declare-submoduleWith-special.nix | 17 | ||||
-rw-r--r-- | lib/tests/modules/define-submoduleWith-noshorthand.nix | 3 | ||||
-rw-r--r-- | lib/tests/modules/define-submoduleWith-shorthand.nix | 3 |
8 files changed, 110 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index cf344122cf4e..4690e380ce3c 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -164,6 +164,24 @@ checkConfigOutput "true" config.enableAlias ./alias-with-priority.nix checkConfigOutput "false" config.enable ./alias-with-priority-can-override.nix checkConfigOutput "false" config.enableAlias ./alias-with-priority-can-override.nix +# submoduleWith + +## specialArgs should work +checkConfigOutput "foo" config.submodule.foo ./declare-submoduleWith-special.nix + +## shorthandOnlyDefines config behaves as expected +checkConfigOutput "true" config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix +checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix +checkConfigError 'value is a boolean while a set was expected' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix +checkConfigOutput "true" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix + +## submoduleWith should merge all modules in one swoop +checkConfigOutput "true" config.submodule.inner ./declare-submoduleWith-modules.nix +checkConfigOutput "true" config.submodule.outer ./declare-submoduleWith-modules.nix + +## Paths should be allowed as values and work as expected +checkConfigOutput "true" config.submodule.enable ./declare-submoduleWith-path.nix + cat <<EOF ====== module tests ====== $pass Pass diff --git a/lib/tests/modules/declare-submoduleWith-modules.nix b/lib/tests/modules/declare-submoduleWith-modules.nix new file mode 100644 index 000000000000..4736ab41751b --- /dev/null +++ b/lib/tests/modules/declare-submoduleWith-modules.nix @@ -0,0 +1,30 @@ +{ lib, ... }: { + options.submodule = lib.mkOption { + type = lib.types.submoduleWith { + modules = [ + { + options.inner = lib.mkOption { + type = lib.types.bool; + default = false; + }; + } + { + outer = true; + } + ]; + }; + default = {}; + }; + + config.submodule = lib.mkMerge [ + ({ lib, ... }: { + options.outer = lib.mkOption { + type = lib.types.bool; + default = false; + }; + }) + { + inner = true; + } + ]; +} diff --git a/lib/tests/modules/declare-submoduleWith-noshorthand.nix b/lib/tests/modules/declare-submoduleWith-noshorthand.nix new file mode 100644 index 000000000000..af3b4ba470ff --- /dev/null +++ b/lib/tests/modules/declare-submoduleWith-noshorthand.nix @@ -0,0 +1,13 @@ +{ lib, ... }: let + sub.options.config = lib.mkOption { + type = lib.types.bool; + default = false; + }; +in { + options.submodule = lib.mkOption { + type = lib.types.submoduleWith { + modules = [ sub ]; + }; + default = {}; + }; +} diff --git a/lib/tests/modules/declare-submoduleWith-path.nix b/lib/tests/modules/declare-submoduleWith-path.nix new file mode 100644 index 000000000000..477647f32121 --- /dev/null +++ b/lib/tests/modules/declare-submoduleWith-path.nix @@ -0,0 +1,12 @@ +{ lib, ... }: { + options.submodule = lib.mkOption { + type = lib.types.submoduleWith { + modules = [ + ./declare-enable.nix + ]; + }; + default = {}; + }; + + config.submodule = ./define-enable.nix; +} diff --git a/lib/tests/modules/declare-submoduleWith-shorthand.nix b/lib/tests/modules/declare-submoduleWith-shorthand.nix new file mode 100644 index 000000000000..63ac16293e2b --- /dev/null +++ b/lib/tests/modules/declare-submoduleWith-shorthand.nix @@ -0,0 +1,14 @@ +{ lib, ... }: let + sub.options.config = lib.mkOption { + type = lib.types.bool; + default = false; + }; +in { + options.submodule = lib.mkOption { + type = lib.types.submoduleWith { + modules = [ sub ]; + shorthandOnlyDefinesConfig = true; + }; + default = {}; + }; +} diff --git a/lib/tests/modules/declare-submoduleWith-special.nix b/lib/tests/modules/declare-submoduleWith-special.nix new file mode 100644 index 000000000000..6b15c5bde203 --- /dev/null +++ b/lib/tests/modules/declare-submoduleWith-special.nix @@ -0,0 +1,17 @@ +{ lib, ... }: { + options.submodule = lib.mkOption { + type = lib.types.submoduleWith { + modules = [ + ({ lib, ... }: { + options.foo = lib.mkOption { + default = lib.foo; + }; + }) + ]; + specialArgs.lib = lib // { + foo = "foo"; + }; + }; + default = {}; + }; +} diff --git a/lib/tests/modules/define-submoduleWith-noshorthand.nix b/lib/tests/modules/define-submoduleWith-noshorthand.nix new file mode 100644 index 000000000000..35e1607b6f1c --- /dev/null +++ b/lib/tests/modules/define-submoduleWith-noshorthand.nix @@ -0,0 +1,3 @@ +{ + submodule.config.config = true; +} diff --git a/lib/tests/modules/define-submoduleWith-shorthand.nix b/lib/tests/modules/define-submoduleWith-shorthand.nix new file mode 100644 index 000000000000..17df248db8ef --- /dev/null +++ b/lib/tests/modules/define-submoduleWith-shorthand.nix @@ -0,0 +1,3 @@ +{ + submodule.config = true; +} |