on 19052d8 help sign in
haskell.nix/test/default.nix
235 lines 10 kB history raw
1{ haskellNix ? import ../default.nix { }
2, pkgs ? import nixpkgs nixpkgsArgs
3, nixpkgs ? haskellNix.sources.nixpkgs-unstable
4, nixpkgsArgs ? haskellNix.nixpkgsArgs
5, ifdLevel ? 1000
6, compiler-nix-name
7, checkMaterialization ? false
8}:
10with pkgs;
12let
13 inherit (import ../ci-lib.nix { inherit pkgs; }) dimension platformFilterGeneric filterAttrsOnlyRecursive;
14 isDisabled = d: d.meta.disabled or false;
16 # Set recurseForDerivations for both children and grand-children values in
17 # the input association list, but only if the key is "ifdInputs".
18 #
19 # withIfdInputs :: AttrSet -> AttrSet
20 #
21 # The values in the input attribute set must be attribute sets themselves.
22 #
23 # >>> withIfdInputs { ifdInputs = { plan-nix = { a = true; b = "hello"; }; }; cat = 2; }
24 # { ifdInputs = {
25 # plan-nix = {
26 # a = true;
27 # b = "hello";
28 # recurseForDerivations = true;
29 # };
30 # recurseForDerivations = true;
31 # };
32 # cat = 2;
33 # }
34 #
35 # >>> withIfdInputs { dog = "hello"; }
36 # { dog = "hello"; }
37 #
38 # >>> withIfdInputs { }
39 # { }
40 withIfdInputs =
41 builtins.mapAttrs
42 (name: val:
43 if name == "ifdInputs"
44 then
45 pkgs.recurseIntoAttrs
46 (builtins.mapAttrs (_: v: pkgs.haskell-nix.withInputs v) val)
47 else val
48 );
50 util = import ./util.nix { cabal-install = pkgs.evalPackages.haskell-nix.cabal-install.${compiler-nix-name}; };
52 # Map the values in an association list over the withIfdInputs function.
53 #
54 # addIfdInputsToVal :: AttrSet -> AttrSet
55 #
56 # The values in the input association list must be attribute sets themselves.
57 addIfdInputsToVal = builtins.mapAttrs (_: val: withIfdInputs val);
59 # Keep only the attribute with the key "ifdInputs" and "meta".
60 # Meta is needed for `meta.disabled` to work at this level.
61 #
62 # filterAttrsIfdInputs :: AttrSet -> AttrSet
63 #
64 # >>> filterAttrsIfdInputs { ifdInputs = 1; foobar = 2 }
65 # { ifdInputs = 1 }
66 #
67 # >>> filterAttrsIfdInputs { foobar = "hello" }
68 # { }
69 filterAttrsIfdInputs = pkgs.lib.filterAttrs (n: _: n == "ifdInputs" || n == "meta");
71 # Remove all keys and values in a attribute set where the key
72 # doesn't equal "ifdInputs". Set the "recurseForDerivations"
73 # key in the resulting value.
74 #
75 # filterNonIfdInputsSetRecurse :: AttrSet -> AttrSet
76 #
77 # >>> filterNonIfdInputsSetRecurse { ifdInputs = 1; foobar = 2 }
78 # { ifdInputs = 1; recurseForDerivations = true }
79 #
80 # >>> filterNonIfdInputsSetRecurse { foobar = "hello" }
81 # { recurseForDerivations = true; }
82 filterNonIfdInputsSetRecurse = attrs:
83 pkgs.recurseIntoAttrs (filterAttrsIfdInputs attrs);
85 # Filter all out all the keys/values for child values of this attribute set
86 # where the key is not equal to "ifdInputs".
87 #
88 # filterNonIfdInputsValues :: AttrSet -> AttrSet
89 #
90 # The values in the input AttrSet must be attribute sets themselves.
91 #
92 # >>> filterNonIfdInputsValues { foo = { ifdInputs = 1; cat = 2; }; bar = { dog = "hello"; }; }
93 # { foo = {
94 # ifdInputs = 1;
95 # recurseForDerivations = true;
96 # };
97 # bar = {
98 # recurseForDerivations = true;
99 # };
100 # }
101 #
102 # >>> filterNonIfdInputsValues { }
103 # { }
104 filterNonIfdInputsValues = attrs:
105 builtins.mapAttrs (_: d: filterNonIfdInputsSetRecurse d) attrs;
107 # Call filterNonIfdInputsValues on the input attribute set, but only
108 # if ifdLevel is less than 3. Otherwise, just return the attribute set.
109 #
110 # filterNonIfdInputsValuesLTLevel3 :: AttrSet -> AttrSet
111 #
112 # >>> filterNonIfdInputsValuesLTLevel3 2 { cabal-doctests = { ifdInputs = {...}; run = ""; }; cabal-simple = { run = ""; }; }
113 # { cabal-doctests = {
114 # ifdInputs = {...};
115 # recurseForDerivations = true;
116 # };
117 # cabal-simple = {
118 # recurseForDerivations = true;
119 # };
120 # }
121 #
122 # >>> filterNonIfdInputsValuesLTLevel3 1000 { cabal-doctests = { ifdInputs = {...}; run = "..."; }; cabal-simple = { run = "..."; }; }
123 # { cabal-doctests = {
124 # ifdInputs = {...};
125 # run = "...";
126 # recurseForDerivations = true;
127 # };
128 # cabal-simple = {
129 # run = "...";
130 # recurseForDerivations = true;
131 # };
132 # }
133 #
134 # >>> filterNonIfdInputsValuesLTLevel3 0 { }
135 # { }
136 filterNonIfdInputsValuesLTLevel3 = ifdLevel: attrs:
137 if ifdLevel < 3
138 then filterNonIfdInputsValues attrs
139 else attrs;
141 testSrcRoot = haskell-nix.haskellLib.cleanGit { src = ../.; subDir = "test"; };
142 testSrc = subDir: haskell-nix.haskellLib.cleanSourceWith { src = testSrcRoot; inherit subDir; };
143 # Use the following reproduce issues that may arise on hydra as a
144 # result of building a snapshot not a git repo.
145 # testSrcRoot = pkgs.copyPathToStore ./.;
146 # testSrc = subDir: testSrcRoot + "/${subDir}";
147 testSrcRootWithGitDir = haskell-nix.haskellLib.cleanGit { src = ../.; subDir = "test"; includeSiblings = true; keepGitDir = true; };
148 testSrcWithGitDir = subDir: haskell-nix.haskellLib.cleanSourceWith { src = testSrcRootWithGitDir; inherit subDir; includeSiblings = true; };
149 callTest = x: args: haskell-nix.callPackage x (args // { inherit testSrc; });
151 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
152 # An empty list means success.
153 unitTests =
154 let
155 tests = haskell-nix.callPackage ./unit.nix {};
156 testsFailedEcho = lib.concatMapStringsSep "\n" (t: "echo ${t.name} failed") tests;
157 testsFinalLine = if builtins.length tests == 0 then "\ntouch $out" else "\nexit 1";
158 testsScript = testsFailedEcho + testsFinalLine;
159 in
160 runCommand "unit-tests" { passthru = { inherit tests; }; } testsScript;
162 # All tests.
163 allTests = {
164 cabal-simple = callTest ./cabal-simple { inherit util compiler-nix-name; };
165 cabal-simple-debug = callTest ./cabal-simple-debug { inherit util compiler-nix-name; };
166 cabal-simple-prof = callTest ./cabal-simple-prof { inherit util compiler-nix-name; };
167 cabal-sublib = callTest ./cabal-sublib { inherit util compiler-nix-name; };
168 with-packages = callTest ./with-packages { inherit util compiler-nix-name; };
169 builder-haddock = callTest ./builder-haddock {};
170 stack-simple = callTest ./stack-simple { inherit compiler-nix-name; };
171 stack-local-resolver = callTest ./stack-local-resolver { inherit compiler-nix-name; };
172 stack-local-resolver-subdir = callTest ./stack-local-resolver-subdir { inherit compiler-nix-name; };
173 stack-remote-resolver = callTest ./stack-remote-resolver { inherit compiler-nix-name; };
174 shell-for-setup-deps = callTest ./shell-for-setup-deps { inherit compiler-nix-name; };
175 setup-deps = import ./setup-deps { inherit pkgs compiler-nix-name; };
176 callStackToNix = callTest ./call-stack-to-nix { inherit compiler-nix-name; };
177 callCabalProjectToNix = callTest ./call-cabal-project-to-nix { inherit compiler-nix-name; };
178 cabal-source-repo = callTest ./cabal-source-repo { inherit compiler-nix-name; };
179 cabal-source-repo-comments = callTest ./cabal-source-repo-comments { inherit compiler-nix-name; };
180 buildable = callTest ./buildable { inherit compiler-nix-name; };
181 project-flags-cabal = callTest ./project-flags/cabal.nix { inherit compiler-nix-name; };
182 project-flags-stack = callTest ./project-flags/stack.nix { inherit compiler-nix-name; };
183 ghc-options-cabal = callTest ./ghc-options/cabal.nix { inherit compiler-nix-name; };
184 ghc-options-stack = callTest ./ghc-options/stack.nix { inherit compiler-nix-name; };
185 exe-only = callTest ./exe-only { inherit util compiler-nix-name; };
186 stack-source-repo = callTest ./stack-source-repo { inherit compiler-nix-name; };
187 cabal-doctests = callTest ./cabal-doctests { inherit util compiler-nix-name; };
188 extra-hackage = callTest ./extra-hackage { inherit compiler-nix-name; };
189 hls-cabal = callTest ./haskell-language-server/cabal.nix { inherit compiler-nix-name; };
190 hls-stack = callTest ./haskell-language-server/stack.nix { inherit compiler-nix-name; };
191 cabal-hpack = callTest ./cabal-hpack { inherit util compiler-nix-name; };
192 index-state = callTest ./index-state { inherit compiler-nix-name; };
193 lookup-sha256 = callTest ./lookup-sha256 { inherit compiler-nix-name; };
194 # fully-static = callTest ./fully-static { inherit (pkgs) buildPackages; };
195 shell-for = callTest ./shell-for { inherit compiler-nix-name; };
196 cabal-22 = callTest ./cabal-22 { inherit util compiler-nix-name; };
197 coverage = callTest ./coverage { inherit compiler-nix-name; };
198 coverage-golden = callTest ./coverage-golden { inherit compiler-nix-name;};
199 coverage-no-libs = callTest ./coverage-no-libs { inherit compiler-nix-name; };
200 snapshots = callTest ./snapshots { inherit compiler-nix-name; };
201 sublib-docs = callTest ./sublib-docs { inherit util compiler-nix-name; };
202 githash = haskell-nix.callPackage ./githash { inherit compiler-nix-name; testSrc = testSrcWithGitDir; };
204 unit = unitTests;
205 };
207 # This is the same as allTests, but filter out all the key/vaules from the
208 # tests other than the "ifdInputs" key if the input ifdLevel is less than 3.
209 allTestsRemoveIfdLTLevel3 = ifdLevel:
210 filterNonIfdInputsValuesLTLevel3 ifdLevel allTests;
212 # This is the same as allTestsRemoveIfdLTLevel3, but make sure
213 # recurseForDerivations is set on all child values under the
214 # ifdInputs key.
215 allTestsWithIfdInputs = ifdLevel:
216 addIfdInputsToVal (allTestsRemoveIfdLTLevel3 ifdLevel);
218 # This is the same as allTestsWithIfdInputs, but returns an empty attribute set
219 # if the input ifdLevel is 0 or 1.
220 #
221 # Here is the result based on the input ifdLevel:
222 #
223 # - input ifdLevel is 0 or 1: {}
224 # - input ifdLevel is 2: filter out everything from the children of allTests
225 # except for the ifdInputs attribute
226 # - input ifdLevel is 3 or greater: return allTests
227 optionalIfdTests = ifdLevel:
228 pkgs.lib.optionalAttrs (ifdLevel > 1) (allTestsWithIfdInputs ifdLevel);
229in filterAttrsOnlyRecursive (_: v: !(isDisabled v))
230 (pkgs.recurseIntoAttrs (optionalIfdTests ifdLevel))
232## more possible test cases
233# 1. fully static linking
234# 2. cabal 2.4 stuff
235# 3. cross-compiling