<commit_before># NixOS tests for gnome-desktop-testing-runner using software
# See https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests

{ system ? builtins.currentSystem,
  config ? {},
  pkgs ? import ../../.. { inherit system config; }
}:

with import ../../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

let

  callInstalledTest = pkgs.newScope { inherit makeInstalledTest; };

  makeInstalledTest =
    { # Package to test. Needs to have an installedTests output
      tested

      # Config to inject into machine
    , testConfig ? {}

      # Test script snippet to inject before gnome-desktop-testing-runner begins.
      # This is useful for extra setup the environment may need before the runner begins.
    , preTestScript ? ""

      # Does test need X11?
    , withX11 ? false

      # Extra flags to pass to gnome-desktop-testing-runner.
    , testRunnerFlags ? ""
    }:
    makeTest rec {
      name = tested.name;

      meta = {
        maintainers = tested.meta.maintainers;
      };

      machine = { ... }: {
        imports = [
          testConfig
        ] ++ optional withX11 ../common/x11.nix;

        environment.systemPackages = with pkgs; [ gnome-desktop-testing ];

      };

      testScript =
        optionalString withX11 ''
          machine.wait_for_x()
        '' +
        optionalString (preTestScript != "") ''
          ${preTestScript}
        '' +
        ''
          machine.succeed(
              "gnome-desktop-testing-runner ${testRunnerFlags} -d '${tested.installedTests}/share'"
          )
        '';
    };

in

{
  colord = callInstalledTest ./colord.nix {};
  flatpak = callInstalledTest ./flatpak.nix {};
  flatpak-builder = callInstalledTest ./flatpak-builder.nix {};
  fwupd = callInstalledTest ./fwupd.nix {};
  gcab = callInstalledTest ./gcab.nix {};
  gdk-pixbuf = callInstalledTest ./gdk-pixbuf.nix {};
  gjs = callInstalledTest ./gjs.nix {};
  glib-networking = callInstalledTest ./glib-networking.nix {};
  gnome-photos = callInstalledTest ./gnome-photos.nix {};
  graphene = callInstalledTest ./graphene.nix {};
  libgdata = callInstalledTest ./libgdata.nix {};
  libxmlb = callInstalledTest ./libxmlb.nix {};
  ostree = callInstalledTest ./ostree.nix {};
  xdg-desktop-portal = callInstalledTest ./xdg-desktop-portal.nix {};
}
<commit_msg>nixosTests.installed-tests: allow passing extra makeTest args<commit_after># NixOS tests for gnome-desktop-testing-runner using software
# See https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests

{ system ? builtins.currentSystem,
  config ? {},
  pkgs ? import ../../.. { inherit system config; }
}:

with import ../../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

let

  callInstalledTest = pkgs.newScope { inherit makeInstalledTest; };

  makeInstalledTest =
    { # Package to test. Needs to have an installedTests output
      tested

      # Config to inject into machine
    , testConfig ? {}

      # Test script snippet to inject before gnome-desktop-testing-runner begins.
      # This is useful for extra setup the environment may need before the runner begins.
    , preTestScript ? ""

      # Does test need X11?
    , withX11 ? false

      # Extra flags to pass to gnome-desktop-testing-runner.
    , testRunnerFlags ? ""

      # Extra attributes to pass to makeTest.
      # They will be recursively merged into the attrset created by this function.
    , ...
    }@args:
    makeTest
      (recursiveUpdate
        rec {
          name = tested.name;

          meta = {
            maintainers = tested.meta.maintainers;
          };

          machine = { ... }: {
            imports = [
              testConfig
            ] ++ optional withX11 ../common/x11.nix;

            environment.systemPackages = with pkgs; [ gnome-desktop-testing ];

          };

          testScript =
            optionalString withX11 ''
              machine.wait_for_x()
            '' +
            optionalString (preTestScript != "") ''
              ${preTestScript}
            '' +
            ''
              machine.succeed(
                  "gnome-desktop-testing-runner ${testRunnerFlags} -d '${tested.installedTests}/share'"
              )
            '';
        }

        (removeAttrs args [
          "tested"
          "testConfig"
          "preTestScript"
          "withX11"
          "testRunnerFlags"
        ])
      );

in

{
  colord = callInstalledTest ./colord.nix {};
  flatpak = callInstalledTest ./flatpak.nix {};
  flatpak-builder = callInstalledTest ./flatpak-builder.nix {};
  fwupd = callInstalledTest ./fwupd.nix {};
  gcab = callInstalledTest ./gcab.nix {};
  gdk-pixbuf = callInstalledTest ./gdk-pixbuf.nix {};
  gjs = callInstalledTest ./gjs.nix {};
  glib-networking = callInstalledTest ./glib-networking.nix {};
  gnome-photos = callInstalledTest ./gnome-photos.nix {};
  graphene = callInstalledTest ./graphene.nix {};
  libgdata = callInstalledTest ./libgdata.nix {};
  libxmlb = callInstalledTest ./libxmlb.nix {};
  ostree = callInstalledTest ./ostree.nix {};
  xdg-desktop-portal = callInstalledTest ./xdg-desktop-portal.nix {};
}

{'fraction_non_alphanumeric': 0.12043512043512043, 'fraction_numerical': 0.004273504273504274, 'mean_word_length': 2.2629911280101394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7473009', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1507, 'n_words': 342}