From bc5652b22775f4e882f07116123697d4f4702ce1 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 12 Feb 2026 22:53:42 -0600 Subject: [PATCH] tests/types: add suboptions doc test Verify we are able to extract suboptions properly with our custom lib extension. Signed-off-by: Austin Horstman --- docs/default.nix | 3 ++ tests/lib/types/default.nix | 2 + .../lib/types/either-suboptions-docs-lib.nix | 49 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/lib/types/either-suboptions-docs-lib.nix diff --git a/docs/default.nix b/docs/default.nix index f374f93b..4098bcc0 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -298,4 +298,7 @@ in in builtins.toJSON result.config.meta.maintainers ); + + # Unstable, for tests. + _internal = { inherit docsLib; }; } diff --git a/tests/lib/types/default.nix b/tests/lib/types/default.nix index f8a7e77c..c9ed3031 100644 --- a/tests/lib/types/default.nix +++ b/tests/lib/types/default.nix @@ -2,5 +2,7 @@ lib-types-dag-submodule = ./dag-submodule.nix; lib-types-dag-merge = ./dag-merge.nix; + lib-types-either-suboptions-docs-lib = ./either-suboptions-docs-lib.nix; + lib-types-gvariant-merge = ./gvariant-merge.nix; } diff --git a/tests/lib/types/either-suboptions-docs-lib.nix b/tests/lib/types/either-suboptions-docs-lib.nix new file mode 100644 index 00000000..b57cf5b5 --- /dev/null +++ b/tests/lib/types/either-suboptions-docs-lib.nix @@ -0,0 +1,49 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + inherit (lib) mkOption; + + docs = import ../../../docs { + inherit pkgs lib; + inherit (config.home.version) release isReleaseBranch; + }; + + inherit (docs._internal.docsLib) types; + + scalarOrSubmodule = types.either types.str ( + types.submodule { + options = { + foo = mkOption { type = types.str; }; + bar = mkOption { type = types.int; }; + }; + } + ); + + scalarOrSubmoduleSubOptions = scalarOrSubmodule.getSubOptions [ ]; + nullOrScalarOrSubmoduleSubOptions = (types.nullOr scalarOrSubmodule).getSubOptions [ ]; +in +{ + assertions = [ + { + assertion = scalarOrSubmoduleSubOptions ? foo; + message = "docsLib.types.either should expose submodule options when one side is scalar."; + } + { + assertion = scalarOrSubmoduleSubOptions ? bar; + message = "docsLib.types.either should expose all submodule options when one side is scalar."; + } + { + assertion = nullOrScalarOrSubmoduleSubOptions ? foo; + message = "docsLib.types.nullOr (types.either ...) should keep submodule options visible."; + } + { + assertion = nullOrScalarOrSubmoduleSubOptions ? bar; + message = "docsLib.types.nullOr (types.either ...) should keep all submodule options visible."; + } + ]; +}