From 1ca210648a6ca9b957efde5da957f3de6b1f0c45 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sat, 3 Feb 2024 19:39:45 +0100 Subject: [PATCH] tests: reduce closure sizes --- .../i18n/input-method/fcitx5-stubs.nix | 15 ++++ tests/modules/programs/beets/mpdstats.nix | 6 +- .../programs/mpv/mpv-example-settings.nix | 84 +++++++++---------- .../programs/mpv/mpv-invalid-settings.nix | 29 +++---- tests/modules/programs/mpv/mpv-stubs.nix | 28 +++++++ 5 files changed, 98 insertions(+), 64 deletions(-) create mode 100644 tests/modules/programs/mpv/mpv-stubs.nix diff --git a/tests/modules/i18n/input-method/fcitx5-stubs.nix b/tests/modules/i18n/input-method/fcitx5-stubs.nix index 7710aa3c5..2a9811256 100644 --- a/tests/modules/i18n/input-method/fcitx5-stubs.nix +++ b/tests/modules/i18n/input-method/fcitx5-stubs.nix @@ -18,6 +18,21 @@ fcitx5-qt = { outPath = null; }; fcitx5-gtk = { outPath = null; }; fcitx5-chinese-addons = { outPath = null; }; + + gtk2 = { + buildScript = '' + mkdir -p $out/bin + echo '#/usr/bin/env bash' > $out/bin/gtk-query-immodules-2.0 + chmod +x $out/bin/* + ''; + }; + gtk3 = { + buildScript = '' + mkdir -p $out/bin + echo '#/usr/bin/env bash' > $out/bin/gtk-query-immodules-3.0 + chmod +x $out/bin/* + ''; + }; }; nixpkgs.overlays = [ diff --git a/tests/modules/programs/beets/mpdstats.nix b/tests/modules/programs/beets/mpdstats.nix index 781eaa84a..d825f85bd 100644 --- a/tests/modules/programs/beets/mpdstats.nix +++ b/tests/modules/programs/beets/mpdstats.nix @@ -11,10 +11,14 @@ programs.beets = { enable = true; - package = config.lib.test.mkStubPackage { outPath = "@beets@"; }; mpdIntegration.enableStats = true; }; + test.stubs = { + beets = { }; + mpd = { }; + }; + nmt.script = '' assertFileExists home-files/.config/beets/config.yaml assertFileContent \ diff --git a/tests/modules/programs/mpv/mpv-example-settings.nix b/tests/modules/programs/mpv/mpv-example-settings.nix index 58467de0b..9974aff6b 100644 --- a/tests/modules/programs/mpv/mpv-example-settings.nix +++ b/tests/modules/programs/mpv/mpv-example-settings.nix @@ -1,55 +1,51 @@ { config, lib, pkgs, ... }: { - config = { - programs.mpv = { - enable = true; - package = pkgs.mpvDummy; + imports = [ ./mpv-stubs.nix ]; - bindings = { - WHEEL_UP = "seek 10"; - WHEEL_DOWN = "seek -10"; - "Alt+0" = "set window-scale 0.5"; - }; + programs.mpv = { + enable = true; - config = { - force-window = true; - ytdl-format = "bestvideo+bestaudio"; - cache-default = 4000000; - }; - - scriptOpts = { - osc = { - scalewindowed = 2.0; - vidscale = false; - visibility = "always"; - }; - }; - - profiles = { - fast = { vo = "vdpau"; }; - "protocol.dvd" = { - profile-desc = "profile for dvd:// streams"; - alang = "en"; - }; - }; - - defaultProfiles = [ "gpu-hq" ]; + bindings = { + WHEEL_UP = "seek 10"; + WHEEL_DOWN = "seek -10"; + "Alt+0" = "set window-scale 0.5"; }; - test.stubs.mpvDummy = { }; + config = { + force-window = true; + ytdl-format = "bestvideo+bestaudio"; + cache-default = 4000000; + }; - nmt.script = '' - assertFileContent \ - home-files/.config/mpv/mpv.conf \ - ${./mpv-example-settings-expected-config} - assertFileContent \ - home-files/.config/mpv/input.conf \ - ${./mpv-example-settings-expected-bindings} - assertFileContent \ - home-files/.config/mpv/script-opts/osc.conf \ - ${./mpv-example-settings-expected-osc-opts} - ''; + scriptOpts = { + osc = { + scalewindowed = 2.0; + vidscale = false; + visibility = "always"; + }; + }; + + profiles = { + fast = { vo = "vdpau"; }; + "protocol.dvd" = { + profile-desc = "profile for dvd:// streams"; + alang = "en"; + }; + }; + + defaultProfiles = [ "gpu-hq" ]; }; + nmt.script = '' + assertFileContent \ + home-files/.config/mpv/mpv.conf \ + ${./mpv-example-settings-expected-config} + assertFileContent \ + home-files/.config/mpv/input.conf \ + ${./mpv-example-settings-expected-bindings} + assertFileContent \ + home-files/.config/mpv/script-opts/osc.conf \ + ${./mpv-example-settings-expected-osc-opts} + ''; } diff --git a/tests/modules/programs/mpv/mpv-invalid-settings.nix b/tests/modules/programs/mpv/mpv-invalid-settings.nix index 701c823fb..896e34fa7 100644 --- a/tests/modules/programs/mpv/mpv-invalid-settings.nix +++ b/tests/modules/programs/mpv/mpv-invalid-settings.nix @@ -1,25 +1,16 @@ { config, lib, pkgs, ... }: { - config = { - programs.mpv = { - enable = true; - package = pkgs.mpvDummy; - scripts = [ pkgs.mpvScript ]; - }; + imports = [ ./mpv-stubs.nix ]; - nixpkgs.overlays = [ - (self: super: { - mpvScript = - pkgs.runCommandLocal "mpvScript" { scriptName = "something"; } - "mkdir $out"; - }) - ]; - test.stubs.mpvDummy = { }; - - test.asserts.assertions.expected = [ - '' - The programs.mpv "package" option is mutually exclusive with "scripts" option.'' - ]; + programs.mpv = { + enable = true; + package = pkgs.emptyDirectory; + scripts = [ pkgs.mpvScript ]; }; + + test.asserts.assertions.expected = [ + '' + The programs.mpv "package" option is mutually exclusive with "scripts" option.'' + ]; } diff --git a/tests/modules/programs/mpv/mpv-stubs.nix b/tests/modules/programs/mpv/mpv-stubs.nix new file mode 100644 index 000000000..5d558ab3e --- /dev/null +++ b/tests/modules/programs/mpv/mpv-stubs.nix @@ -0,0 +1,28 @@ +{ pkgs, ... }: + +{ + nixpkgs.overlays = [ + (self: super: { + mpvScript = pkgs.runCommandLocal "mpvScript" { scriptName = "something"; } + "mkdir $out"; + + mpv-unwrapped = super.mpv-unwrapped.overrideAttrs { + builder = pkgs.writeShellScript "dummy" '' + PATH=${pkgs.coreutils}/bin + mkdir -p $dev $man $out/bin $out/Applications/mpv.app/Contents/MacOS + touch $out/bin/{mpv,umpv} \ + $out/Applications/mpv.app/Contents/MacOS/{mpv,mpv-bundle} + chmod +x $out/bin/{mpv,umpv} \ + $out/Applications/mpv.app/Contents/MacOS/{mpv,mpv-bundle} + ''; + }; + + lua = pkgs.emptyDirectory.overrideAttrs { + luaversion = "0"; + withPackages = ps: pkgs.emptyDirectory; + }; + }) + ]; + + test.stubs = { yt-dlp = { }; }; +}