From ef4370bedc9e196aa4ca8192c6ceaf34dca589ee Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 7 Feb 2021 21:52:16 +0100 Subject: [PATCH] tests: allow testing assertions By default tests are expected to produce no assertion. This also updates the existing tests to match. --- tests/asserts.nix | 30 +++++++++++++++++ .../modules/accounts/email-test-accounts.nix | 1 + tests/modules/programs/alot/alot.nix | 1 - .../autorandr/basic-configuration.conf | 10 ------ .../autorandr/basic-configuration.nix | 17 +++++++--- tests/modules/programs/autorandr/default.nix | 5 ++- tests/modules/programs/autorandr/scale.nix | 32 +++++++++++++++++++ tests/modules/programs/getmail/getmail.nix | 6 ++-- tests/modules/programs/lieer/lieer.nix | 1 + .../mpv/mpv-invalid-settings-expected.json | 1 - .../programs/mpv/mpv-invalid-settings.nix | 12 +++---- .../programs/neomutt/neomutt-with-msmtp.nix | 1 - tests/modules/programs/neomutt/neomutt.nix | 1 - ...ert-on-both-theme-and-colors-expected.json | 1 - .../rofi/assert-on-both-theme-and-colors.nix | 11 ++----- ...ds-dynamic-bind-path-with-port-asserts.nix | 9 +----- ...ards-local-bind-path-with-port-asserts.nix | 9 +----- ...ards-local-host-path-with-port-asserts.nix | 9 +----- .../ssh/forwards-paths-with-ports-error.json | 1 - ...rds-remote-bind-path-with-port-asserts.nix | 9 +----- ...rds-remote-host-path-with-port-asserts.nix | 9 +----- .../modules/services/lieer/lieer-service.nix | 11 +++++-- 22 files changed, 102 insertions(+), 85 deletions(-) delete mode 100644 tests/modules/programs/autorandr/basic-configuration.conf create mode 100644 tests/modules/programs/autorandr/scale.nix delete mode 100644 tests/modules/programs/mpv/mpv-invalid-settings-expected.json delete mode 100644 tests/modules/programs/rofi/assert-on-both-theme-and-colors-expected.json delete mode 100644 tests/modules/programs/ssh/forwards-paths-with-ports-error.json diff --git a/tests/asserts.nix b/tests/asserts.nix index e6813b28..6d1b1002 100644 --- a/tests/asserts.nix +++ b/tests/asserts.nix @@ -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) + } ''; }; } diff --git a/tests/modules/accounts/email-test-accounts.nix b/tests/modules/accounts/email-test-accounts.nix index 9a4e0b8e..e66e5894 100644 --- a/tests/modules/accounts/email-test-accounts.nix +++ b/tests/modules/accounts/email-test-accounts.nix @@ -6,6 +6,7 @@ accounts = { "hm@example.com" = { + primary = true; address = "hm@example.com"; userName = "home.manager"; realName = "H. M. Test"; diff --git a/tests/modules/programs/alot/alot.nix b/tests/modules/programs/alot/alot.nix index 40028b7a..3f74ef21 100644 --- a/tests/modules/programs/alot/alot.nix +++ b/tests/modules/programs/alot/alot.nix @@ -8,7 +8,6 @@ with lib; config = { accounts.email.accounts = { "hm@example.com" = { - primary = true; notmuch.enable = true; alot = { contactCompletion = { }; diff --git a/tests/modules/programs/autorandr/basic-configuration.conf b/tests/modules/programs/autorandr/basic-configuration.conf deleted file mode 100644 index 681574cf..00000000 --- a/tests/modules/programs/autorandr/basic-configuration.conf +++ /dev/null @@ -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 \ No newline at end of file diff --git a/tests/modules/programs/autorandr/basic-configuration.nix b/tests/modules/programs/autorandr/basic-configuration.nix index 19051101..fad18f75 100644 --- a/tests/modules/programs/autorandr/basic-configuration.nix +++ b/tests/modules/programs/autorandr/basic-configuration.nix @@ -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'' + } ''; }; } diff --git a/tests/modules/programs/autorandr/default.nix b/tests/modules/programs/autorandr/default.nix index 5f12d409..bb7b279e 100644 --- a/tests/modules/programs/autorandr/default.nix +++ b/tests/modules/programs/autorandr/default.nix @@ -1 +1,4 @@ -{ autorandr-basic-configuration = ./basic-configuration.nix; } +{ + autorandr-basic-configuration = ./basic-configuration.nix; + autorandr-scale = ./scale.nix; +} diff --git a/tests/modules/programs/autorandr/scale.nix b/tests/modules/programs/autorandr/scale.nix new file mode 100644 index 00000000..9092e61d --- /dev/null +++ b/tests/modules/programs/autorandr/scale.nix @@ -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'' + } + ''; + }; +} diff --git a/tests/modules/programs/getmail/getmail.nix b/tests/modules/programs/getmail/getmail.nix index b0d979c4..c460a37e 100644 --- a/tests/modules/programs/getmail/getmail.nix +++ b/tests/modules/programs/getmail/getmail.nix @@ -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} ''; }; } diff --git a/tests/modules/programs/lieer/lieer.nix b/tests/modules/programs/lieer/lieer.nix index e0ade636..c5771b67 100644 --- a/tests/modules/programs/lieer/lieer.nix +++ b/tests/modules/programs/lieer/lieer.nix @@ -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; }; diff --git a/tests/modules/programs/mpv/mpv-invalid-settings-expected.json b/tests/modules/programs/mpv/mpv-invalid-settings-expected.json deleted file mode 100644 index 50d6f6f5..00000000 --- a/tests/modules/programs/mpv/mpv-invalid-settings-expected.json +++ /dev/null @@ -1 +0,0 @@ -["The programs.mpv \"package\" option is mutually exclusive with \"scripts\" option."] \ No newline at end of file diff --git a/tests/modules/programs/mpv/mpv-invalid-settings.nix b/tests/modules/programs/mpv/mpv-invalid-settings.nix index 40cd4529..f7be8c42 100644 --- a/tests/modules/programs/mpv/mpv-invalid-settings.nix +++ b/tests/modules/programs/mpv/mpv-invalid-settings.nix @@ -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.'' + ]; }; } diff --git a/tests/modules/programs/neomutt/neomutt-with-msmtp.nix b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix index 22f65599..1d5db5f9 100644 --- a/tests/modules/programs/neomutt/neomutt-with-msmtp.nix +++ b/tests/modules/programs/neomutt/neomutt-with-msmtp.nix @@ -8,7 +8,6 @@ with lib; config = { accounts.email.accounts = { "hm@example.com" = { - primary = true; msmtp.enable = true; neomutt = { enable = true; diff --git a/tests/modules/programs/neomutt/neomutt.nix b/tests/modules/programs/neomutt/neomutt.nix index c0caa44a..d4419d93 100644 --- a/tests/modules/programs/neomutt/neomutt.nix +++ b/tests/modules/programs/neomutt/neomutt.nix @@ -8,7 +8,6 @@ with lib; config = { accounts.email.accounts = { "hm@example.com" = { - primary = true; notmuch.enable = true; neomutt = { enable = true; diff --git a/tests/modules/programs/rofi/assert-on-both-theme-and-colors-expected.json b/tests/modules/programs/rofi/assert-on-both-theme-and-colors-expected.json deleted file mode 100644 index 808288f4..00000000 --- a/tests/modules/programs/rofi/assert-on-both-theme-and-colors-expected.json +++ /dev/null @@ -1 +0,0 @@ -["Cannot use the rofi options 'theme' and 'colors' simultaneously.\n"] \ No newline at end of file diff --git a/tests/modules/programs/rofi/assert-on-both-theme-and-colors.nix b/tests/modules/programs/rofi/assert-on-both-theme-and-colors.nix index f162a486..087ca472 100644 --- a/tests/modules/programs/rofi/assert-on-both-theme-and-colors.nix +++ b/tests/modules/programs/rofi/assert-on-both-theme-and-colors.nix @@ -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. + '']; }; } diff --git a/tests/modules/programs/ssh/forwards-dynamic-bind-path-with-port-asserts.nix b/tests/modules/programs/ssh/forwards-dynamic-bind-path-with-port-asserts.nix index cf2efe5a..e841b5bc 100644 --- a/tests/modules/programs/ssh/forwards-dynamic-bind-path-with-port-asserts.nix +++ b/tests/modules/programs/ssh/forwards-dynamic-bind-path-with-port-asserts.nix @@ -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." ]; }; } diff --git a/tests/modules/programs/ssh/forwards-local-bind-path-with-port-asserts.nix b/tests/modules/programs/ssh/forwards-local-bind-path-with-port-asserts.nix index f9d8e2da..e7ac454e 100644 --- a/tests/modules/programs/ssh/forwards-local-bind-path-with-port-asserts.nix +++ b/tests/modules/programs/ssh/forwards-local-bind-path-with-port-asserts.nix @@ -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." ]; }; } diff --git a/tests/modules/programs/ssh/forwards-local-host-path-with-port-asserts.nix b/tests/modules/programs/ssh/forwards-local-host-path-with-port-asserts.nix index 02a7e5b1..890459c8 100644 --- a/tests/modules/programs/ssh/forwards-local-host-path-with-port-asserts.nix +++ b/tests/modules/programs/ssh/forwards-local-host-path-with-port-asserts.nix @@ -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." ]; }; } diff --git a/tests/modules/programs/ssh/forwards-paths-with-ports-error.json b/tests/modules/programs/ssh/forwards-paths-with-ports-error.json deleted file mode 100644 index e7e3a374..00000000 --- a/tests/modules/programs/ssh/forwards-paths-with-ports-error.json +++ /dev/null @@ -1 +0,0 @@ -["Forwarded paths cannot have ports."] \ No newline at end of file diff --git a/tests/modules/programs/ssh/forwards-remote-bind-path-with-port-asserts.nix b/tests/modules/programs/ssh/forwards-remote-bind-path-with-port-asserts.nix index 61ce9ae0..ece7d795 100644 --- a/tests/modules/programs/ssh/forwards-remote-bind-path-with-port-asserts.nix +++ b/tests/modules/programs/ssh/forwards-remote-bind-path-with-port-asserts.nix @@ -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." ]; }; } diff --git a/tests/modules/programs/ssh/forwards-remote-host-path-with-port-asserts.nix b/tests/modules/programs/ssh/forwards-remote-host-path-with-port-asserts.nix index 71bdbcb7..b1228f4e 100644 --- a/tests/modules/programs/ssh/forwards-remote-host-path-with-port-asserts.nix +++ b/tests/modules/programs/ssh/forwards-remote-host-path-with-port-asserts.nix @@ -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." ]; }; } diff --git a/tests/modules/services/lieer/lieer-service.nix b/tests/modules/services/lieer/lieer-service.nix index 60e00e0c..af3074b0 100644 --- a/tests/modules/services/lieer/lieer-service.nix +++ b/tests/modules/services/lieer/lieer-service.nix @@ -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 = [