diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 9eb887a7b695..92525b8caa40 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -3210,6 +3210,95 @@ runTests { ]; }; + testDocOptionVisiblity = { + expr = + let + submodule = + { lib, ... }: + { + freeformType = lib.types.attrsOf ( + lib.types.submodule { + options.bar = lib.mkOption { }; + } + ); + options.foo = lib.mkOption { }; + }; + + module = + { lib, ... }: + { + options = { + shallow = lib.mkOption { + type = lib.types.submodule submodule; + visible = "shallow"; + }; + "true" = lib.mkOption { + type = lib.types.submodule submodule; + visible = true; + }; + "false" = lib.mkOption { + type = lib.types.submodule submodule; + visible = false; + }; + "internal" = lib.mkOption { + type = lib.types.submodule submodule; + internal = true; + }; + }; + }; + + options = + (evalModules { + modules = [ module ]; + }).options; + in + pipe options [ + optionAttrSetToDocList + (filter (opt: !(builtins.elem "_module" opt.loc))) + (map ( + opt: + nameValuePair opt.name { + inherit (opt) visible internal; + } + )) + listToAttrs + ]; + expected = { + shallow = { + visible = true; + internal = false; + }; + "true" = { + visible = true; + internal = false; + }; + "true.foo" = { + visible = true; + internal = false; + }; + "true..bar" = { + visible = true; + internal = false; + }; + "false" = { + visible = false; + internal = false; + }; + "internal" = { + visible = true; + internal = true; + }; + "internal.foo" = { + visible = true; + internal = false; + }; + "internal..bar" = { + visible = true; + internal = false; + }; + }; + }; + testAttrsWithName = { expr = let