diff options
author | Robert Hensing <robert@roberthensing.nl> | 2023-06-16 21:43:12 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2023-06-16 22:08:16 +0200 |
commit | 36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4 (patch) | |
tree | cce1f4b7a5e559b6daec93ad083c6dc27b55e54f /lib/tests | |
parent | a742767bafecf0644585309b744e24f90cdff207 (diff) | |
download | nixpkgs-36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4.tar nixpkgs-36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4.tar.gz nixpkgs-36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4.tar.bz2 nixpkgs-36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4.tar.lz nixpkgs-36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4.tar.xz nixpkgs-36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4.tar.zst nixpkgs-36ea2bbfe81ccf1118fd0ef66b13868fa3cc27e4.zip |
lib.modules: Add mergeAttrDefinitionsWithPrio
This will let us make assertions involving _module.args.pkgs, which is not an option but a value attribute, and therefore doesn't have its own highestPrio to inspect. The new function gives us that info.
Diffstat (limited to 'lib/tests')
-rwxr-xr-x | lib/tests/modules.sh | 2 | ||||
-rw-r--r-- | lib/tests/modules/test-mergeAttrDefinitionsWithPrio.nix | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 7aebba6b589..a60228198fd 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -61,6 +61,8 @@ checkConfigError() { # Shorthand meta attribute does not duplicate the config checkConfigOutput '^"one two"$' config.result ./shorthand-meta.nix +checkConfigOutput '^true$' config.result ./test-mergeAttrDefinitionsWithPrio.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/test-mergeAttrDefinitionsWithPrio.nix b/lib/tests/modules/test-mergeAttrDefinitionsWithPrio.nix new file mode 100644 index 00000000000..3233f415136 --- /dev/null +++ b/lib/tests/modules/test-mergeAttrDefinitionsWithPrio.nix @@ -0,0 +1,21 @@ +{ lib, options, ... }: + +let + defs = lib.modules.mergeAttrDefinitionsWithPrio options._module.args; + assertLazy = pos: throw "${pos.file}:${toString pos.line}:${toString pos.column}: The test must not evaluate this the assertLazy thunk, but it did. Unexpected strictness leads to unexpected errors and performance problems."; +in + +{ + options.result = lib.mkOption { }; + config._module.args = { + default = lib.mkDefault (assertLazy __curPos); + regular = null; + force = lib.mkForce (assertLazy __curPos); + unused = assertLazy __curPos; + }; + config.result = + assert defs.default.highestPrio == (lib.mkDefault (assertLazy __curPos)).priority; + assert defs.regular.highestPrio == lib.modules.defaultOverridePriority; + assert defs.force.highestPrio == (lib.mkForce (assertLazy __curPos)).priority; + true; +} |