diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2023-03-09 16:16:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-09 16:16:37 +0100 |
commit | 6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0 (patch) | |
tree | 9f3fe4f78d2f704143c76efbd8154172e3e6f54d /lib/tests | |
parent | 324ef866e213f9f697668bec431a784a48d9e66a (diff) | |
parent | 118bdf25a6c572dd2fd29d10b1ae2e4d9a95b907 (diff) | |
download | nixlib-6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0.tar nixlib-6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0.tar.gz nixlib-6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0.tar.bz2 nixlib-6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0.tar.lz nixlib-6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0.tar.xz nixlib-6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0.tar.zst nixlib-6b79fe8cdc7bc70cc289478a1da0dc07fe8da9b0.zip |
Merge pull request #211855 from hercules-ci/lib-modules-disabledModules-module-with-key
lib/modules: Allow an "anonymous" module with key in disabledModules
Diffstat (limited to 'lib/tests')
-rwxr-xr-x | lib/tests/modules.sh | 12 | ||||
-rw-r--r-- | lib/tests/modules/disable-module-bad-key.nix | 16 | ||||
-rw-r--r-- | lib/tests/modules/disable-module-with-key.nix | 34 | ||||
-rw-r--r-- | lib/tests/modules/disable-module-with-toString-key.nix | 34 | ||||
-rw-r--r-- | lib/tests/modules/merge-module-with-key.nix | 49 |
5 files changed, 145 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index cde4da643937..8081b186a2f9 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -141,6 +141,14 @@ checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix +checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-key.nix +checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-key.nix +checkConfigError 'Module ..*disable-module-bad-key.nix. contains a disabledModules item that is an attribute set, presumably a module, that does not have a .key. attribute. .*' 'config.enable' ./disable-module-bad-key.nix + +# Not sure if we want to keep supporting module keys that aren't strings, paths or v?key, but we shouldn't remove support accidentally. +checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-toString-key.nix +checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-toString-key.nix + # Check _module.args. set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@" @@ -358,6 +366,10 @@ checkConfigOutput '^"The option `a\.b. defined in `.*/doRename-warnings\.nix. ha config.result \ ./doRename-warnings.nix +# Anonymous modules get deduplicated by key +checkConfigOutput '^"pear"$' config.once.raw ./merge-module-with-key.nix +checkConfigOutput '^"pear\\npear"$' config.twice.raw ./merge-module-with-key.nix + cat <<EOF ====== module tests ====== $pass Pass diff --git a/lib/tests/modules/disable-module-bad-key.nix b/lib/tests/modules/disable-module-bad-key.nix new file mode 100644 index 000000000000..f50d06f2f03c --- /dev/null +++ b/lib/tests/modules/disable-module-bad-key.nix @@ -0,0 +1,16 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; + + moduleWithKey = { config, ... }: { + config = { + enable = true; + }; + }; +in +{ + imports = [ + ./declare-enable.nix + ]; + disabledModules = [ { } ]; +} diff --git a/lib/tests/modules/disable-module-with-key.nix b/lib/tests/modules/disable-module-with-key.nix new file mode 100644 index 000000000000..ea2a60aa832d --- /dev/null +++ b/lib/tests/modules/disable-module-with-key.nix @@ -0,0 +1,34 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; + + moduleWithKey = { + key = "disable-module-with-key.nix#moduleWithKey"; + config = { + enable = true; + }; + }; +in +{ + options = { + positive = mkOption { + type = types.submodule { + imports = [ + ./declare-enable.nix + moduleWithKey + ]; + }; + default = {}; + }; + negative = mkOption { + type = types.submodule { + imports = [ + ./declare-enable.nix + moduleWithKey + ]; + disabledModules = [ moduleWithKey ]; + }; + default = {}; + }; + }; +} diff --git a/lib/tests/modules/disable-module-with-toString-key.nix b/lib/tests/modules/disable-module-with-toString-key.nix new file mode 100644 index 000000000000..3f8c81904ce6 --- /dev/null +++ b/lib/tests/modules/disable-module-with-toString-key.nix @@ -0,0 +1,34 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; + + moduleWithKey = { + key = 123; + config = { + enable = true; + }; + }; +in +{ + options = { + positive = mkOption { + type = types.submodule { + imports = [ + ./declare-enable.nix + moduleWithKey + ]; + }; + default = {}; + }; + negative = mkOption { + type = types.submodule { + imports = [ + ./declare-enable.nix + moduleWithKey + ]; + disabledModules = [ 123 ]; + }; + default = {}; + }; + }; +} diff --git a/lib/tests/modules/merge-module-with-key.nix b/lib/tests/modules/merge-module-with-key.nix new file mode 100644 index 000000000000..21f00e6ef976 --- /dev/null +++ b/lib/tests/modules/merge-module-with-key.nix @@ -0,0 +1,49 @@ +{ lib, ... }: +let + inherit (lib) mkOption types; + + moduleWithoutKey = { + config = { + raw = "pear"; + }; + }; + + moduleWithKey = { + key = __curPos.file + "#moduleWithKey"; + config = { + raw = "pear"; + }; + }; + + decl = { + options = { + raw = mkOption { + type = types.lines; + }; + }; + }; +in +{ + options = { + once = mkOption { + type = types.submodule { + imports = [ + decl + moduleWithKey + moduleWithKey + ]; + }; + default = {}; + }; + twice = mkOption { + type = types.submodule { + imports = [ + decl + moduleWithoutKey + moduleWithoutKey + ]; + }; + default = {}; + }; + }; +} |