1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-24 02:39:48 +01:00

tests: allow testing assertions

By default tests are expected to produce no assertion.

This also updates the existing tests to match.
This commit is contained in:
Robert Helgesson 2021-02-07 21:52:16 +01:00
parent bdee1be7b3
commit ef4370bedc
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
22 changed files with 102 additions and 85 deletions

View file

@ -19,6 +19,22 @@ with lib;
'';
};
};
assertions = {
enable = mkOption {
type = types.bool;
default = true;
description = "Whether assertion asserts are enabled.";
};
expected = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
List of expected assertions.
'';
};
};
};
config = mkIf config.test.asserts.warnings.enable {
@ -27,6 +43,11 @@ with lib;
--
'' config.warnings;
"asserts/assertions.actual".text = concatStringsSep ''
--
'' (map (x: x.message) (filter (x: !x.assertion) config.assertions));
};
nmt.script = ''
@ -38,6 +59,15 @@ with lib;
--
'' config.test.asserts.warnings.expected)
}
assertFileContent \
home-files/asserts/assertions.actual \
${
pkgs.writeText "assertions.expected" (concatStringsSep ''
--
'' config.test.asserts.assertions.expected)
}
'';
};
}

View file

@ -6,6 +6,7 @@
accounts = {
"hm@example.com" = {
primary = true;
address = "hm@example.com";
userName = "home.manager";
realName = "H. M. Test";

View file

@ -8,7 +8,6 @@ with lib;
config = {
accounts.email.accounts = {
"hm@example.com" = {
primary = true;
notmuch.enable = true;
alot = {
contactCompletion = { };

View file

@ -1,10 +0,0 @@
output DP1
off
output DP2
pos 0x0
crtc 0
primary
mode 1920x1080
transform 0.600000,0.000000,0.000000,0.000000,0.600000,0.000000,0.000000,0.000000,1.000000
scale 2x4

View file

@ -17,10 +17,6 @@
primary = true;
position = "0x0";
mode = "1920x1080";
scale = {
x = 2;
y = 4;
};
transform = [
[ 0.6 0.0 0.0 ] # a b c
[ 0.0 0.6 0.0 ] # d e f
@ -42,7 +38,18 @@
assertFileExists $config
assertFileContent $config \
${./basic-configuration.conf}
${
pkgs.writeText "basic-configuration.conf" ''
output DP1
off
output DP2
pos 0x0
crtc 0
primary
mode 1920x1080
transform 0.600000,0.000000,0.000000,0.000000,0.600000,0.000000,0.000000,0.000000,1.000000''
}
'';
};
}

View file

@ -1 +1,4 @@
{ autorandr-basic-configuration = ./basic-configuration.nix; }
{
autorandr-basic-configuration = ./basic-configuration.nix;
autorandr-scale = ./scale.nix;
}

View file

@ -0,0 +1,32 @@
{ config, pkgs, ... }:
{
config = {
programs.autorandr = {
enable = true;
profiles = {
default = {
fingerprint.DP1 = "XXX";
config.DP1 = {
scale = {
x = 2;
y = 4;
};
};
};
};
};
nmt.script = ''
config=home-files/.config/autorandr/default/config
assertFileExists $config
assertFileContent $config \
${
pkgs.writeText "scale-expected.conf" ''
output DP1
scale 2x4''
}
'';
};
}

View file

@ -19,10 +19,8 @@ with lib;
};
nmt.script = ''
assertFileExists home-files/.getmail/getmailhm@example.com
assertFileContent home-files/.getmail/getmailhm@example.com ${
./getmail-expected.conf
}
assertFileExists home-files/.getmail/getmailrc
assertFileContent home-files/.getmail/getmailrc ${./getmail-expected.conf}
'';
};
}

View file

@ -9,6 +9,7 @@ with lib;
programs.lieer.enable = true;
accounts.email.accounts."hm@example.com" = {
flavor = "gmail.com";
lieer.enable = true;
notmuch.enable = true;
};

View file

@ -1 +0,0 @@
["The programs.mpv \"package\" option is mutually exclusive with \"scripts\" option."]

View file

@ -17,13 +17,9 @@
})
];
home.file.result.text = builtins.toJSON
(map (a: a.message) (lib.filter (a: !a.assertion) config.assertions));
nmt.script = ''
assertFileContent \
home-files/result \
${./mpv-invalid-settings-expected.json}
'';
test.asserts.assertions.expected = [
''
The programs.mpv "package" option is mutually exclusive with "scripts" option.''
];
};
}

View file

@ -8,7 +8,6 @@ with lib;
config = {
accounts.email.accounts = {
"hm@example.com" = {
primary = true;
msmtp.enable = true;
neomutt = {
enable = true;

View file

@ -8,7 +8,6 @@ with lib;
config = {
accounts.email.accounts = {
"hm@example.com" = {
primary = true;
notmuch.enable = true;
neomutt = {
enable = true;

View file

@ -1 +0,0 @@
["Cannot use the rofi options 'theme' and 'colors' simultaneously.\n"]

View file

@ -17,16 +17,11 @@ with lib;
};
};
home.file.result.text = builtins.toJSON
(map (a: a.message) (filter (a: !a.assertion) config.assertions));
nixpkgs.overlays =
[ (self: super: { rofi = pkgs.writeScriptBin "dummy-rofi" ""; }) ];
nmt.script = ''
assertFileContent \
home-files/result \
${./assert-on-both-theme-and-colors-expected.json}
'';
test.asserts.assertions.expected = [''
Cannot use the rofi options 'theme' and 'colors' simultaneously.
''];
};
}

View file

@ -17,13 +17,6 @@ with lib;
};
};
home.file.result.text = builtins.toJSON
(map (a: a.message) (filter (a: !a.assertion) config.assertions));
nmt.script = ''
assertFileContent home-files/result ${
./forwards-paths-with-ports-error.json
}
'';
test.asserts.assertions.expected = [ "Forwarded paths cannot have ports." ];
};
}

View file

@ -21,13 +21,6 @@ with lib;
};
};
home.file.result.text = builtins.toJSON
(map (a: a.message) (filter (a: !a.assertion) config.assertions));
nmt.script = ''
assertFileContent home-files/result ${
./forwards-paths-with-ports-error.json
}
'';
test.asserts.assertions.expected = [ "Forwarded paths cannot have ports." ];
};
}

View file

@ -21,13 +21,6 @@ with lib;
};
};
home.file.result.text = builtins.toJSON
(map (a: a.message) (filter (a: !a.assertion) config.assertions));
nmt.script = ''
assertFileContent home-files/result ${
./forwards-paths-with-ports-error.json
}
'';
test.asserts.assertions.expected = [ "Forwarded paths cannot have ports." ];
};
}

View file

@ -1 +0,0 @@
["Forwarded paths cannot have ports."]

View file

@ -21,13 +21,6 @@ with lib;
};
};
home.file.result.text = builtins.toJSON
(map (a: a.message) (filter (a: !a.assertion) config.assertions));
nmt.script = ''
assertFileContent home-files/result ${
./forwards-paths-with-ports-error.json
}
'';
test.asserts.assertions.expected = [ "Forwarded paths cannot have ports." ];
};
}

View file

@ -21,13 +21,6 @@ with lib;
};
};
home.file.result.text = builtins.toJSON
(map (a: a.message) (filter (a: !a.assertion) config.assertions));
nmt.script = ''
assertFileContent home-files/result ${
./forwards-paths-with-ports-error.json
}
'';
test.asserts.assertions.expected = [ "Forwarded paths cannot have ports." ];
};
}

View file

@ -9,9 +9,14 @@ with lib;
services.lieer.enable = true;
accounts.email.accounts = {
"hm@example.com".lieer.enable = true;
"hm@example.com".lieer.sync.enable = true;
"hm@example.com".notmuch.enable = true;
"hm@example.com" = {
flavor = "gmail.com";
lieer = {
enable = true;
sync.enable = true;
};
notmuch.enable = true;
};
};
nixpkgs.overlays = [