summaryrefslogtreecommitdiff
path: root/pkgs/test/make-hardcode-gsettings-patch/default.nix
blob: 2bf63f56aa46b8211eb049aabbc463b49c081969 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  runCommandLocal,
  lib,
  git,
  clang-tools,
  makeHardcodeGsettingsPatch,
}:

let
  mkTest =
    {
      name,
      expected,
      src,
      patches ? [ ],
      args,
    }:

    let
      patch = makeHardcodeGsettingsPatch (
        args
        // {
          inherit src patches;
        }
      );
    in
    runCommandLocal "makeHardcodeGsettingsPatch-tests-${name}"

      {
        nativeBuildInputs = [
          git
          clang-tools
        ];
      }

      ''
        cp -r --no-preserve=all "${src}" src
        cp -r --no-preserve=all "${expected}" src-expected

        pushd src
        for patch in ${lib.escapeShellArgs (map (p: "${p}") patches)}; do
            patch < "$patch"
        done
        patch < "${patch}"
        popd

        find src -name '*.c' -print0 | while read -d $'\0' sourceFile; do
          sourceFile=''${sourceFile#src/}
          clang-format -style='{BasedOnStyle: InheritParentConfig, ColumnLimit: 240}' -i "src/$sourceFile" "src-expected/$sourceFile"
          git diff --no-index "src/$sourceFile" "src-expected/$sourceFile" | cat
        done
        touch "$out"
      '';
in
{
  basic = mkTest {
    name = "basic";
    src = ./fixtures/example-project;
    args = {
      schemaIdToVariableMapping = {
        "org.gnome.evolution-data-server.addressbook" = "EDS";
        "org.gnome.evolution.calendar" = "EVO";
        "org.gnome.seahorse.nautilus.window" = "SEANAUT";
      };
    };
    expected = ./fixtures/example-project-patched;
  };

  patches = mkTest {
    name = "patches";
    src = ./fixtures/example-project-wrapped-settings-constructor;
    patches = [
      # Avoid using wrapper function, which the generator cannot handle.
      ./fixtures/example-project-wrapped-settings-constructor-resolve.patch
    ];
    args = {
      schemaIdToVariableMapping = {
        "org.gnome.evolution-data-server.addressbook" = "EDS";
      };
    };
    expected = ./fixtures/example-project-wrapped-settings-constructor-patched;
  };

  existsFn = mkTest {
    name = "exists-fn";
    src = ./fixtures/example-project;
    args = {
      schemaIdToVariableMapping = {
        "org.gnome.evolution-data-server.addressbook" = "EDS";
        "org.gnome.evolution.calendar" = "EVO";
        "org.gnome.seahorse.nautilus.window" = "SEANAUT";
      };
      schemaExistsFunction = "e_ews_common_utils_gsettings_schema_exists";
    };
    expected = ./fixtures/example-project-patched-with-exists-fn;
  };

}