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
|
||||
# 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 `<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
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
lib.optional (failures != [])
|
||||
(throw "The following kernel unit tests failed: ${lib.generators.toPretty {} failures}")
|
||||
|
@ -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}")
|
||||
|
Loading…
Reference in New Issue
Block a user