mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-21 22:43:01 +00:00
pkgs/test: fix silent failures when using runTests
This commit is contained in:
parent
fc6e6b8ffb
commit
2951758f51
@ -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
|
# make sure to use NON EXISTING kernel settings else they may conflict with
|
||||||
# common-config.nix
|
# common-config.nix
|
||||||
{ lib, pkgs }:
|
{ lib, pkgs }:
|
||||||
@ -37,37 +34,40 @@ let
|
|||||||
{ NIXOS_FAKE_USB_DEBUG = option yes;}
|
{ 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 `<unknown-file>' and `<unknown-file>'
|
||||||
|
testTreeform = let
|
||||||
|
res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform);
|
||||||
|
in {
|
||||||
|
expr = res.success;
|
||||||
|
expected = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
in
|
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
|
lib.optional (failures != [])
|
||||||
testMandatoryCheck = {
|
(throw "The following kernel unit tests failed: ${lib.generators.toPretty {} failures}")
|
||||||
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 `<unknown-file>' and `<unknown-file>'
|
|
||||||
testTreeform = let
|
|
||||||
res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform);
|
|
||||||
in {
|
|
||||||
expr = res.success;
|
|
||||||
expected = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,37 +1,42 @@
|
|||||||
{ pkgs, lib, stdenv, ... }:
|
{ pkgs, lib, stdenv, ... }:
|
||||||
|
|
||||||
lib.runTests {
|
let
|
||||||
# Merging two non-list definitions must still result in an error
|
failures = lib.runTests {
|
||||||
# about a conflicting definition.
|
# Merging two non-list definitions must still result in an error
|
||||||
test-unitOption-merging-non-lists-conflict =
|
# about a conflicting definition.
|
||||||
let nixos = pkgs.nixos {
|
test-unitOption-merging-non-lists-conflict =
|
||||||
system.stateVersion = lib.trivial.release;
|
let nixos = pkgs.nixos {
|
||||||
systemd.services.systemd-test-nixos = {
|
system.stateVersion = lib.trivial.release;
|
||||||
serviceConfig = lib.mkMerge [
|
systemd.services.systemd-test-nixos = {
|
||||||
{ StateDirectory = "foo"; }
|
serviceConfig = lib.mkMerge [
|
||||||
{ StateDirectory = "bar"; }
|
{ StateDirectory = "foo"; }
|
||||||
];
|
{ StateDirectory = "bar"; }
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
in {
|
||||||
in {
|
expr = (builtins.tryEval (nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory)).success;
|
||||||
expr = (builtins.tryEval (nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory)).success;
|
expected = false;
|
||||||
expected = false;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
# Merging must lift non-list definitions to a list
|
# Merging must lift non-list definitions to a list
|
||||||
# if at least one of them is a list.
|
# if at least one of them is a list.
|
||||||
test-unitOption-merging-list-non-list-append =
|
test-unitOption-merging-list-non-list-append =
|
||||||
let nixos = pkgs.nixos {
|
let nixos = pkgs.nixos {
|
||||||
system.stateVersion = lib.trivial.release;
|
system.stateVersion = lib.trivial.release;
|
||||||
systemd.services.systemd-test-nixos = {
|
systemd.services.systemd-test-nixos = {
|
||||||
serviceConfig = lib.mkMerge [
|
serviceConfig = lib.mkMerge [
|
||||||
{ StateDirectory = "foo"; }
|
{ StateDirectory = "foo"; }
|
||||||
{ StateDirectory = ["bar"]; }
|
{ StateDirectory = ["bar"]; }
|
||||||
];
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
in {
|
||||||
in {
|
expr = nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory;
|
||||||
expr = nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory;
|
expected = [ "foo" "bar" ];
|
||||||
expected = [ "foo" "bar" ];
|
};
|
||||||
};
|
};
|
||||||
}
|
in
|
||||||
|
|
||||||
|
lib.optional (failures != [])
|
||||||
|
(throw "The following systemd unit tests failed: ${lib.generators.toPretty {} failures}")
|
||||||
|
Loading…
Reference in New Issue
Block a user