mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-15 17:50:53 +00:00
tests: add support for asserting warnings
This adds a "test.asserts" module that currently just provides a convenient way to assert on the content of warnings. By default all tests will assert that no warnings are given.
This commit is contained in:
parent
4dedfcfd95
commit
9d53afb709
7 changed files with 64 additions and 1 deletions
43
tests/asserts.nix
Normal file
43
tests/asserts.nix
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
options.test.asserts = {
|
||||||
|
warnings = {
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Whether warning asserts are enabled.";
|
||||||
|
};
|
||||||
|
|
||||||
|
expected = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
List of expected warnings.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf config.test.asserts.warnings.enable {
|
||||||
|
home.file = {
|
||||||
|
"asserts/warnings.actual".text = concatStringsSep ''
|
||||||
|
|
||||||
|
--
|
||||||
|
'' config.warnings;
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileContent \
|
||||||
|
home-files/asserts/warnings.actual \
|
||||||
|
${
|
||||||
|
pkgs.writeText "warnings.expected" (concatStringsSep ''
|
||||||
|
|
||||||
|
--
|
||||||
|
'' config.test.asserts.warnings.expected)
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -25,6 +25,8 @@ let
|
||||||
# Avoid including documentation since this will cause
|
# Avoid including documentation since this will cause
|
||||||
# unnecessary rebuilds of the tests.
|
# unnecessary rebuilds of the tests.
|
||||||
manual.manpages.enable = false;
|
manual.manpages.enable = false;
|
||||||
|
|
||||||
|
imports = [ ./asserts.nix ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,12 @@ with lib;
|
||||||
userName = "John Doe";
|
userName = "John Doe";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test.asserts.warnings.expected = [''
|
||||||
|
Using programs.git.extraConfig as a string option is
|
||||||
|
deprecated and will be removed in the future. Please
|
||||||
|
change to using it as an attribute set instead.
|
||||||
|
''];
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertFileExists home-files/.config/git/config
|
assertFileExists home-files/.config/git/config
|
||||||
assertFileContent home-files/.config/git/config \
|
assertFileContent home-files/.config/git/config \
|
||||||
|
|
|
@ -8,7 +8,10 @@ with lib;
|
||||||
config = {
|
config = {
|
||||||
programs.lieer.enable = true;
|
programs.lieer.enable = true;
|
||||||
|
|
||||||
accounts.email.accounts = { "hm@example.com".lieer.enable = true; };
|
accounts.email.accounts."hm@example.com" = {
|
||||||
|
lieer.enable = true;
|
||||||
|
notmuch.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
(self: super: { gmailieer = pkgs.writeScriptBin "dummy-gmailieer" ""; })
|
(self: super: { gmailieer = pkgs.writeScriptBin "dummy-gmailieer" ""; })
|
||||||
|
|
|
@ -66,6 +66,10 @@ in {
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Remove when https://github.com/nix-community/home-manager/issues/1686 is
|
||||||
|
# fixed.
|
||||||
|
test.asserts.warnings.enable = false;
|
||||||
|
|
||||||
nmt.description = ''
|
nmt.description = ''
|
||||||
Test for the broken configuration
|
Test for the broken configuration
|
||||||
https://github.com/nix-community/home-manager/pull/1329#issuecomment-653253069
|
https://github.com/nix-community/home-manager/pull/1329#issuecomment-653253069
|
||||||
|
|
|
@ -50,6 +50,10 @@ in {
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Remove when https://github.com/nix-community/home-manager/issues/1686 is
|
||||||
|
# fixed.
|
||||||
|
test.asserts.warnings.enable = false;
|
||||||
|
|
||||||
nmt.script = ''
|
nmt.script = ''
|
||||||
assertPathNotExists home-files/.config/waybar/style.css
|
assertPathNotExists home-files/.config/waybar/style.css
|
||||||
assertFileContent \
|
assertFileContent \
|
||||||
|
|
|
@ -11,6 +11,7 @@ with lib;
|
||||||
accounts.email.accounts = {
|
accounts.email.accounts = {
|
||||||
"hm@example.com".lieer.enable = true;
|
"hm@example.com".lieer.enable = true;
|
||||||
"hm@example.com".lieer.sync.enable = true;
|
"hm@example.com".lieer.sync.enable = true;
|
||||||
|
"hm@example.com".notmuch.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
|
|
Loading…
Reference in a new issue