From ac9915b1eaaa93edcb7da8af2b2f797f6c3da4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Sat, 20 May 2023 18:23:41 +0200 Subject: [PATCH] lib/tests: add mkPackageOption tests --- lib/tests/modules.sh | 5 +++++ lib/tests/modules/declare-mkPackageOption.nix | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 lib/tests/modules/declare-mkPackageOption.nix diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 45c247cbbea6..7fdc3d3d81aa 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -182,6 +182,11 @@ 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 +# Check mkPackageOption +checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix +checkConfigError 'The option .undefinedPackage. is used but not defined' config.undefinedPackage ./declare-mkPackageOption.nix +checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix + # submoduleWith ## specialArgs should work diff --git a/lib/tests/modules/declare-mkPackageOption.nix b/lib/tests/modules/declare-mkPackageOption.nix new file mode 100644 index 000000000000..640b19a7bf22 --- /dev/null +++ b/lib/tests/modules/declare-mkPackageOption.nix @@ -0,0 +1,19 @@ +{ lib, ... }: let + pkgs.hello = { + type = "derivation"; + pname = "hello"; + }; +in { + options = { + package = lib.mkPackageOption pkgs "hello" { }; + + undefinedPackage = lib.mkPackageOption pkgs "hello" { + default = null; + }; + + nullablePackage = lib.mkPackageOption pkgs "hello" { + nullable = true; + default = null; + }; + }; +}