diff --git a/pkgs/test/kernel.nix b/pkgs/test/kernel.nix index 2ccd188b1edb..e345d9fa207e 100644 --- a/pkgs/test/kernel.nix +++ b/pkgs/test/kernel.nix @@ -1,6 +1,3 @@ -# to run these tests: -# nix-instantiate --eval --strict . -A tests.kernel-config -# # make sure to use NON EXISTING kernel settings else they may conflict with # common-config.nix { lib, pkgs }: @@ -37,37 +34,40 @@ let { NIXOS_FAKE_USB_DEBUG = option yes;} ]; + failures = runTests { + testEasy = { + expr = (getConfig { NIXOS_FAKE_USB_DEBUG = yes;}).NIXOS_FAKE_USB_DEBUG; + expected = { tristate = "y"; optional = false; freeform = null; }; + }; + + # mandatory flag should win over optional + testMandatoryCheck = { + expr = (getConfig mandatoryVsOptionalConfig).NIXOS_FAKE_USB_DEBUG.optional; + expected = false; + }; + + testYesWinsOverNo = { + expr = (getConfig mkDefaultWorksConfig)."NIXOS_TEST_BOOLEAN".tristate; + expected = "y"; + }; + + testAllOptionalRemainOptional = { + expr = (getConfig allOptionalRemainOptional)."NIXOS_FAKE_USB_DEBUG".optional; + expected = true; + }; + + # check that freeform options are unique + # Should trigger + # > The option `settings.NIXOS_FAKE_MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `' and `' + testTreeform = let + res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform); + in { + expr = res.success; + expected = false; + }; + + }; in -runTests { - testEasy = { - expr = (getConfig { NIXOS_FAKE_USB_DEBUG = yes;}).NIXOS_FAKE_USB_DEBUG; - expected = { tristate = "y"; optional = false; freeform = null; }; - }; - # mandatory flag should win over optional - testMandatoryCheck = { - expr = (getConfig mandatoryVsOptionalConfig).NIXOS_FAKE_USB_DEBUG.optional; - expected = false; - }; - - testYesWinsOverNo = { - expr = (getConfig mkDefaultWorksConfig)."NIXOS_TEST_BOOLEAN".tristate; - expected = "y"; - }; - - testAllOptionalRemainOptional = { - expr = (getConfig allOptionalRemainOptional)."NIXOS_FAKE_USB_DEBUG".optional; - expected = true; - }; - - # check that freeform options are unique - # Should trigger - # > The option `settings.NIXOS_FAKE_MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `' and `' - testTreeform = let - res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform); - in { - expr = res.success; - expected = false; - }; - -} +lib.optional (failures != []) + (throw "The following kernel unit tests failed: ${lib.generators.toPretty {} failures}") diff --git a/pkgs/test/systemd/nixos/default.nix b/pkgs/test/systemd/nixos/default.nix index e45399b63516..37b42ea7ae27 100644 --- a/pkgs/test/systemd/nixos/default.nix +++ b/pkgs/test/systemd/nixos/default.nix @@ -1,37 +1,42 @@ { pkgs, lib, stdenv, ... }: -lib.runTests { - # Merging two non-list definitions must still result in an error - # about a conflicting definition. - test-unitOption-merging-non-lists-conflict = - let nixos = pkgs.nixos { - system.stateVersion = lib.trivial.release; - systemd.services.systemd-test-nixos = { - serviceConfig = lib.mkMerge [ - { StateDirectory = "foo"; } - { StateDirectory = "bar"; } - ]; +let + failures = lib.runTests { + # Merging two non-list definitions must still result in an error + # about a conflicting definition. + test-unitOption-merging-non-lists-conflict = + let nixos = pkgs.nixos { + system.stateVersion = lib.trivial.release; + systemd.services.systemd-test-nixos = { + serviceConfig = lib.mkMerge [ + { StateDirectory = "foo"; } + { StateDirectory = "bar"; } + ]; + }; }; - }; - in { - expr = (builtins.tryEval (nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory)).success; - expected = false; - }; + in { + expr = (builtins.tryEval (nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory)).success; + expected = false; + }; - # Merging must lift non-list definitions to a list - # if at least one of them is a list. - test-unitOption-merging-list-non-list-append = - let nixos = pkgs.nixos { - system.stateVersion = lib.trivial.release; - systemd.services.systemd-test-nixos = { - serviceConfig = lib.mkMerge [ - { StateDirectory = "foo"; } - { StateDirectory = ["bar"]; } - ]; + # Merging must lift non-list definitions to a list + # if at least one of them is a list. + test-unitOption-merging-list-non-list-append = + let nixos = pkgs.nixos { + system.stateVersion = lib.trivial.release; + systemd.services.systemd-test-nixos = { + serviceConfig = lib.mkMerge [ + { StateDirectory = "foo"; } + { StateDirectory = ["bar"]; } + ]; + }; }; - }; - in { - expr = nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory; - expected = [ "foo" "bar" ]; + in { + expr = nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory; + expected = [ "foo" "bar" ]; + }; }; -} +in + +lib.optional (failures != []) + (throw "The following systemd unit tests failed: ${lib.generators.toPretty {} failures}")