From 5f00024e752106fa8189b27883604609caf11bcd Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 2 Jan 2022 10:22:50 +0100 Subject: [PATCH] tests: make `enableBig` an option This makes it possible to identify the test as big in the test file itself. It also seems like a more natural way to control the test running. --- tests/big-test.nix | 13 ++ tests/default.nix | 12 +- tests/modules/misc/debug/default.nix | 41 +++--- tests/modules/programs/emacs/extra-config.nix | 2 +- .../firefox/deprecated-native-messenger.nix | 62 +++++---- .../programs/firefox/profile-settings.nix | 121 +++++++++--------- .../programs/firefox/state-version-19_09.nix | 44 +++---- 7 files changed, 151 insertions(+), 144 deletions(-) create mode 100644 tests/big-test.nix diff --git a/tests/big-test.nix b/tests/big-test.nix new file mode 100644 index 00000000..421eaebb --- /dev/null +++ b/tests/big-test.nix @@ -0,0 +1,13 @@ +{ lib, ... }: + +{ + options.test.enableBig = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to enable big tests. These are tests that require + more resources than typical tests. For example, tests that depend on large + packages or tests that take long to run. + ''; + }; +} diff --git a/tests/default.nix b/tests/default.nix index e2964179..686cc36a 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -26,7 +26,9 @@ let # unnecessary rebuilds of the tests. manual.manpages.enable = false; - imports = [ ./asserts.nix ./stubs.nix ]; + imports = [ ./asserts.nix ./big-test.nix ./stubs.nix ]; + + test.enableBig = enableBig; } ]; @@ -55,6 +57,7 @@ import nmt { ./modules/programs/browserpass ./modules/programs/dircolors ./modules/programs/direnv + ./modules/programs/emacs ./modules/programs/feh ./modules/programs/fish ./modules/programs/gh @@ -101,6 +104,7 @@ import nmt { ] ++ lib.optionals isLinux [ ./modules/config/i18n ./modules/i18n/input-method + ./modules/misc/debug ./modules/misc/gtk ./modules/misc/numlock ./modules/misc/pam @@ -109,6 +113,7 @@ import nmt { ./modules/misc/xsession ./modules/programs/abook ./modules/programs/autorandr + ./modules/programs/firefox ./modules/programs/foot ./modules/programs/getmail ./modules/programs/gnome-terminal @@ -152,10 +157,5 @@ import nmt { ./modules/services/xsettingsd ./modules/systemd ./modules/targets-linux - ] ++ lib.optionals enableBig [ - ./modules/programs/emacs - ] ++ lib.optionals (enableBig && isLinux) [ - ./modules/misc/debug - ./modules/programs/firefox ]); } diff --git a/tests/modules/misc/debug/default.nix b/tests/modules/misc/debug/default.nix index b42462d0..19ff4e2b 100644 --- a/tests/modules/misc/debug/default.nix +++ b/tests/modules/misc/debug/default.nix @@ -1,25 +1,26 @@ { - debug = { pkgs, config, lib, ... }: { - home.enableDebugInfo = true; - home.packages = with pkgs; [ curl gdb ]; + debug = { pkgs, config, lib, ... }: + lib.mkIf config.test.enableBig { + home.enableDebugInfo = true; + home.packages = with pkgs; [ curl gdb ]; - nmt.script = '' - [ -L $TESTED/home-path/lib/debug/curl ] \ - || fail "Debug-symbols for pkgs.curl should exist in \`/home-path/lib/debug'!" + nmt.script = '' + [ -L $TESTED/home-path/lib/debug/curl ] \ + || fail "Debug-symbols for pkgs.curl should exist in \`/home-path/lib/debug'!" - #source $TESTED/home-path/etc/profile.d/hm-session-vars.sh - #[[ "$NIX_DEBUG_INFO_DIRS" =~ /lib/debug$ ]] \ - #|| fail "Invalid NIX_DEBUG_INFO_DIRS!" - assertFileExists home-path/etc/profile.d/hm-session-vars.sh - assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ - 'NIX_DEBUG_INFO_DIRS=.*/lib/debug' + #source $TESTED/home-path/etc/profile.d/hm-session-vars.sh + #[[ "$NIX_DEBUG_INFO_DIRS" =~ /lib/debug$ ]] \ + #|| fail "Invalid NIX_DEBUG_INFO_DIRS!" + assertFileExists home-path/etc/profile.d/hm-session-vars.sh + assertFileRegex home-path/etc/profile.d/hm-session-vars.sh \ + 'NIX_DEBUG_INFO_DIRS=.*/lib/debug' - # We need to override NIX_DEBUG_INFO_DIRS here as $HOME evalutes to the home - # of the user who executes this testcase :/ - { echo quit | PATH="$TESTED/home-path/bin''${PATH:+:}$PATH" NIX_DEBUG_INFO_DIRS=$TESTED/home-path/lib/debug \ - gdb curl 2>&1 | \ - grep 'Reading symbols from ${builtins.storeDir}/'; \ - } || fail "Failed to read debug symbols from curl in gdb" - ''; - }; + # We need to override NIX_DEBUG_INFO_DIRS here as $HOME evalutes to the home + # of the user who executes this testcase :/ + { echo quit | PATH="$TESTED/home-path/bin''${PATH:+:}$PATH" NIX_DEBUG_INFO_DIRS=$TESTED/home-path/lib/debug \ + gdb curl 2>&1 | \ + grep 'Reading symbols from ${builtins.storeDir}/'; \ + } || fail "Failed to read debug symbols from curl in gdb" + ''; + }; } diff --git a/tests/modules/programs/emacs/extra-config.nix b/tests/modules/programs/emacs/extra-config.nix index 67778c35..de8a5ee1 100644 --- a/tests/modules/programs/emacs/extra-config.nix +++ b/tests/modules/programs/emacs/extra-config.nix @@ -10,7 +10,7 @@ let emacsBin = "${config.programs.emacs.finalPackage}/bin/emacs"; -in { +in lib.mkIf config.test.enableBig { programs.emacs = { enable = true; package = pkgs.emacs-nox; diff --git a/tests/modules/programs/firefox/deprecated-native-messenger.nix b/tests/modules/programs/firefox/deprecated-native-messenger.nix index 9c624388..796389f1 100644 --- a/tests/modules/programs/firefox/deprecated-native-messenger.nix +++ b/tests/modules/programs/firefox/deprecated-native-messenger.nix @@ -2,37 +2,35 @@ with lib; -{ - config = { - programs.firefox = { - enable = true; - enableGnomeExtensions = true; - }; - - nixpkgs.overlays = [ - (self: super: { - firefox-unwrapped = pkgs.runCommandLocal "firefox-0" { - meta.description = "I pretend to be Firefox"; - passthru.gtk3 = null; - } '' - mkdir -p "$out"/{bin,lib} - touch "$out/bin/firefox" - chmod 755 "$out/bin/firefox" - ''; - - chrome-gnome-shell = - pkgs.runCommandLocal "dummy-chrome-gnome-shell" { } '' - mkdir -p $out/lib/mozilla/native-messaging-hosts - touch $out/lib/mozilla/native-messaging-hosts/dummy - ''; - }) - ]; - - test.asserts.warnings.expected = ['' - Using 'programs.firefox.enableGnomeExtensions' has been deprecated and - will be removed in the future. Please change to overriding the package - configuration using 'programs.firefox.package' instead. You can refer to - its example for how to do this. - '']; +lib.mkIf config.test.enableBig { + programs.firefox = { + enable = true; + enableGnomeExtensions = true; }; + + nixpkgs.overlays = [ + (self: super: { + firefox-unwrapped = pkgs.runCommandLocal "firefox-0" { + meta.description = "I pretend to be Firefox"; + passthru.gtk3 = null; + } '' + mkdir -p "$out"/{bin,lib} + touch "$out/bin/firefox" + chmod 755 "$out/bin/firefox" + ''; + + chrome-gnome-shell = + pkgs.runCommandLocal "dummy-chrome-gnome-shell" { } '' + mkdir -p $out/lib/mozilla/native-messaging-hosts + touch $out/lib/mozilla/native-messaging-hosts/dummy + ''; + }) + ]; + + test.asserts.warnings.expected = ['' + Using 'programs.firefox.enableGnomeExtensions' has been deprecated and + will be removed in the future. Please change to overriding the package + configuration using 'programs.firefox.package' instead. You can refer to + its example for how to do this. + '']; } diff --git a/tests/modules/programs/firefox/profile-settings.nix b/tests/modules/programs/firefox/profile-settings.nix index 10d5855a..c74be20d 100644 --- a/tests/modules/programs/firefox/profile-settings.nix +++ b/tests/modules/programs/firefox/profile-settings.nix @@ -2,70 +2,67 @@ with lib; -{ - config = { - programs.firefox = { - enable = true; - profiles.basic.isDefault = true; +lib.mkIf config.test.enableBig { + programs.firefox = { + enable = true; + profiles.basic.isDefault = true; - profiles.test = { - id = 1; - settings = { "general.smoothScroll" = false; }; - }; - - profiles.bookmarks = { - id = 2; - settings = { "general.smoothScroll" = false; }; - bookmarks = { - wikipedia = { - keyword = "wiki"; - url = - "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go"; - }; - "kernel.org" = { url = "https://www.kernel.org"; }; - }; - }; + profiles.test = { + id = 1; + settings = { "general.smoothScroll" = false; }; }; - nixpkgs.overlays = [ - (self: super: { - firefox-unwrapped = pkgs.runCommand "firefox-0" { - meta.description = "I pretend to be Firefox"; - preferLocalBuild = true; - passthru.gtk3 = null; - } '' - mkdir -p "$out"/{bin,lib} - touch "$out/bin/firefox" - chmod 755 "$out/bin/firefox" - ''; - }) - ]; - - nmt.script = '' - assertFileRegex \ - home-path/bin/firefox \ - MOZ_APP_LAUNCHER - - assertDirectoryExists home-files/.mozilla/firefox/basic - - assertFileContent \ - home-files/.mozilla/firefox/test/user.js \ - ${./profile-settings-expected-user.js} - - bookmarksUserJs=$(normalizeStorePaths \ - home-files/.mozilla/firefox/bookmarks/user.js) - - assertFileContent \ - $bookmarksUserJs \ - ${./profile-settings-expected-bookmarks-user.js} - - bookmarksFile="$(sed -n \ - '/browser.bookmarks.file/ {s|^.*\(/nix/store[^"]*\).*|\1|;p}' \ - $TESTED/home-files/.mozilla/firefox/bookmarks/user.js)" - - assertFileContent \ - $bookmarksFile \ - ${./profile-settings-expected-bookmarks.html} - ''; + profiles.bookmarks = { + id = 2; + settings = { "general.smoothScroll" = false; }; + bookmarks = { + wikipedia = { + keyword = "wiki"; + url = "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go"; + }; + "kernel.org" = { url = "https://www.kernel.org"; }; + }; + }; }; + + nixpkgs.overlays = [ + (self: super: { + firefox-unwrapped = pkgs.runCommand "firefox-0" { + meta.description = "I pretend to be Firefox"; + preferLocalBuild = true; + passthru.gtk3 = null; + } '' + mkdir -p "$out"/{bin,lib} + touch "$out/bin/firefox" + chmod 755 "$out/bin/firefox" + ''; + }) + ]; + + nmt.script = '' + assertFileRegex \ + home-path/bin/firefox \ + MOZ_APP_LAUNCHER + + assertDirectoryExists home-files/.mozilla/firefox/basic + + assertFileContent \ + home-files/.mozilla/firefox/test/user.js \ + ${./profile-settings-expected-user.js} + + bookmarksUserJs=$(normalizeStorePaths \ + home-files/.mozilla/firefox/bookmarks/user.js) + + assertFileContent \ + $bookmarksUserJs \ + ${./profile-settings-expected-bookmarks-user.js} + + bookmarksFile="$(sed -n \ + '/browser.bookmarks.file/ {s|^.*\(/nix/store[^"]*\).*|\1|;p}' \ + $TESTED/home-files/.mozilla/firefox/bookmarks/user.js)" + + assertFileContent \ + $bookmarksFile \ + ${./profile-settings-expected-bookmarks.html} + ''; } diff --git a/tests/modules/programs/firefox/state-version-19_09.nix b/tests/modules/programs/firefox/state-version-19_09.nix index 3eb6084f..bf0b95f0 100644 --- a/tests/modules/programs/firefox/state-version-19_09.nix +++ b/tests/modules/programs/firefox/state-version-19_09.nix @@ -2,30 +2,28 @@ with lib; -{ - config = { - home.stateVersion = "19.09"; +lib.mkIf config.test.enableBig { + home.stateVersion = "19.09"; - programs.firefox.enable = true; + programs.firefox.enable = true; - nixpkgs.overlays = [ - (self: super: { - firefox-unwrapped = pkgs.runCommand "firefox-0" { - meta.description = "I pretend to be Firefox"; - preferLocalBuild = true; - passthru.gtk3 = null; - } '' - mkdir -p "$out"/{bin,lib} - touch "$out/bin/firefox" - chmod 755 "$out/bin/firefox" - ''; - }) - ]; + nixpkgs.overlays = [ + (self: super: { + firefox-unwrapped = pkgs.runCommand "firefox-0" { + meta.description = "I pretend to be Firefox"; + preferLocalBuild = true; + passthru.gtk3 = null; + } '' + mkdir -p "$out"/{bin,lib} + touch "$out/bin/firefox" + chmod 755 "$out/bin/firefox" + ''; + }) + ]; - nmt.script = '' - assertFileRegex \ - home-path/bin/firefox \ - MOZ_APP_LAUNCHER - ''; - }; + nmt.script = '' + assertFileRegex \ + home-path/bin/firefox \ + MOZ_APP_LAUNCHER + ''; }