-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathunit.nix
More file actions
396 lines (380 loc) · 14 KB
/
Copy pathunit.nix
File metadata and controls
396 lines (380 loc) · 14 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
{ pkgs, evalPackages, lib, haskellLib, compiler-nix-name }:
let
emptyConfig = {
components = {
benchmarks = { };
exes = { };
foreignlibs = { };
library = { buildable = true; planned = true; };
sublibs = { };
tests = { };
};
package.identifier.name = "empty";
package.buildable = true;
};
componentsConfig = {
components = {
benchmarks = { bbb = { buildable = true; planned = true; }; };
exes = { eee = { buildable = true; planned = true; }; };
foreignlibs = { fff = { buildable = true; planned = true; }; };
library = { buildable = true; planned = true; };
sublibs = { };
tests = { ttt = { buildable = true; planned = true; }; };
};
package.identifier.name = "nnn";
package.buildable = true;
};
testRepoData = {
url = "https://github.com/input-output-hk/haskell.nix.git";
rev = "487eea1c249537d34c27f6143dff2b9d5586c657";
sha256 = "077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123";
};
in
lib.runTests {
# identity function for applyComponents
test-applyComponents-id = {
expr = haskellLib.applyComponents (_componentId: component: component) emptyConfig;
expected = emptyConfig.components;
};
# map a component to its component name and check these are correct
test-applyComponents-library = {
expr = haskellLib.applyComponents (componentId: _component: componentId.cname) emptyConfig;
expected = emptyConfig.components // { library = "empty"; };
};
test-applyComponents-components = {
expr = haskellLib.applyComponents (_componentId: component: component) componentsConfig;
expected = componentsConfig.components;
};
# testing that the tests work
testId = {
expr = lib.id 1;
expected = 1;
};
# `dependToLib` returns the library component of a dependency package.
testDependToLibResolvesLibrary = {
expr = haskellLib.dependToLib { identifier.name = "foo"; components.library = "the-lib"; };
expected = "the-lib";
};
# A sublib `depends` value is already the derivation (no `components`), so it
# is passed through unchanged.
testDependToLibPassesSublibThrough = {
expr = haskellLib.dependToLib "already-a-derivation";
expected = "already-a-derivation";
};
# An unplanned package (has `components`, but no planned `library`) must throw
# rather than silently vanish or give an opaque `attribute 'library' missing`
# (see #1379). `runTests` can only assert that evaluation fails; the message
# wording is checked out of band.
testDependToLibThrowsForUnplannedPackage = {
expr = (builtins.tryEval
(haskellLib.dependToLib { identifier.name = "foo"; components = { }; })).success;
expected = false;
};
testParseBlock1 = {
expr = __toJSON (haskellLib.parseSourceRepositoryPackageBlock "cabal.project" {} {} "" ''
type: git
location: https://github.com/input-output-hk/haskell.nix.git
tag: 487eea1c249537d34c27f6143dff2b9d5586c657
--sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
-- end of block
'');
expected = __toJSON {
followingText = "-- end of block\n";
indentation = "";
sourceRepo = testRepoData // { subdirs = ["."]; };
};
};
testParseBlock2 = {
expr = __toJSON (haskellLib.parseSourceRepositoryPackageBlock "cabal.project" {} {} "" ''
type: git
location: https://github.com/input-output-hk/haskell.nix.git
tag: 487eea1c249537d34c27f6143dff2b9d5586c657
--sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
subdir: dir
-- end of block
'');
expected = __toJSON {
followingText = "-- end of block\n";
indentation = "";
sourceRepo = testRepoData // { subdirs = ["dir"]; };
};
};
testParseBlock3 = {
expr = __toJSON (haskellLib.parseSourceRepositoryPackageBlock "cabal.project" {} {} "" ''
type: git
location: https://github.com/input-output-hk/haskell.nix.git
tag: 487eea1c249537d34c27f6143dff2b9d5586c657
--sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
subdir: dir1 dir2
-- end of block
'');
expected = __toJSON {
followingText = "-- end of block\n";
indentation = "";
sourceRepo = testRepoData // { subdirs = ["dir1" "dir2"]; };
};
};
testParseBlock4 = {
expr = __toJSON (haskellLib.parseSourceRepositoryPackageBlock "cabal.project" {} {} "" ''
type: git
location: https://github.com/input-output-hk/haskell.nix.git
tag: 487eea1c249537d34c27f6143dff2b9d5586c657
--sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
subdir:
dir1
dir2
-- end of block
'');
expected = __toJSON {
followingText = "-- end of block\n";
indentation = "";
sourceRepo = testRepoData // { subdirs = ["dir1" "dir2"]; };
};
};
# Verify that parseBlockLines (called inside parseSourceRepositoryPackageBlock)
# preserves string context on parsed attribute values like `location`.
# This is critical for repository blocks where the URL may contain
# interpolated store paths (e.g. `url: file:${CHaP}`).
testParseBlockLinesPreservesContext =
let
storePath = builtins.toFile "test-context" "test";
storePathStr = builtins.unsafeDiscardStringContext storePath;
# Interpolate a store path into the block to give it context.
# pkgs.lib.splitString (used inside parseSourceRepositoryPackageBlock)
# preserves this context, but builtins.match (used in parseBlockLines)
# would strip it without our fix.
blockWithContext = ''
type: git
location: file:${storePath}
tag: 487eea1c249537d34c27f6143dff2b9d5586c657
--sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
rest of file
'';
result = haskellLib.parseSourceRepositoryPackageBlock "cabal.project" {} {} "" blockWithContext;
urlContext = builtins.getContext result.sourceRepo.url;
in {
expr = urlContext ? ${storePathStr};
expected = true;
};
# Verify that parseSourceRepositoryPackages preserves string context
# from the project file through builtins.split into initialText.
testParseSourceRepoPackagesPreservesContext =
let
storePath = builtins.toFile "test-context" "test";
storePathStr = builtins.unsafeDiscardStringContext storePath;
projectFile = ''
packages: ./*.cabal
repository test-repo
url: file:${storePath}
secure: True
'';
result = haskellLib.parseSourceRepositoryPackages "cabal.project" {} {} projectFile;
initialTextContext = builtins.getContext result.initialText;
in {
expr = initialTextContext ? ${storePathStr};
expected = true;
};
testParseRepositoryBlock =
let
# The Cabal2Nix output in hackage-to-nix is imported into a lambda
# and connot be easily compared.
removeNix = x: x // {
hackage =
lib.mapAttrs (_packageName: vers:
lib.mapAttrs (_ver: data: data // {
revisions =
lib.mapAttrs (_rev: x: x // { nix = __typeOf x.nix; }) data.revisions;
}) vers
) x.hackage;
};
result = rec {
expr = __toJSON (removeNix (haskellLib.parseRepositoryBlock evalPackages "cabal.project" {} {}
evalPackages.haskell-nix.nix-tools-unchecked ''
ghcjs-overlay
url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/bfc363b9f879c360e0a0460ec0c18ec87222ec32
secure: True
root-keys:
key-threshold: 0
--sha256: sha256-tyeqsCew1ptGCrNAIrw5R2sz+oSqWbWrd/wDAPh1hMs=
-- end of block
''));
expected = __toJSON {
name = "ghcjs-overlay";
repoContents = "/nix/store/2gimg55rlc60pjiimpww10zflyf1bqh9-ghcjs-overlay";
repo = {
ghcjs-overlay = "/nix/store/2gimg55rlc60pjiimpww10zflyf1bqh9-ghcjs-overlay";
};
hackage = {
Cabal = {
"3.2.1.0" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "2b5309e942658e3b16e6938115867538e70a647d98e3dc967f2be20d6b886e61";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "2b5309e942658e3b16e6938115867538e70a647d98e3dc967f2be20d6b886e61";
};
};
sha256 = "826970f742b63d751f6fe3be7f862b7b1e419ddfafef3014c01de54f12874a4a";
};
};
basement = {
"0.0.12"= {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "600669787199915545f99754496f13f955203b94dbb31de50093362c03367bb7";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "600669787199915545f99754496f13f955203b94dbb31de50093362c03367bb7";
};
};
sha256 = "cf8f96fd92438739a516881abb7e14747118e82a12634d44acc83173fb87f535";
};
};
clock = {
"0.8.2" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "2a8441d9f531bb51bb1806e56e9e9a43e5f0214faea4f31219c15120128ca43a";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "2a8441d9f531bb51bb1806e56e9e9a43e5f0214faea4f31219c15120128ca43a";
};
};
sha256 = "57715a01df74568c638f1138b53642094de420bafd519e9f53ec7fe92876121e";
};
};
cryptonite = {
"0.29" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "231db2acdaefc978865af9b72a6e65c4ebc70238174a7ad9076d68900f3d866d";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "231db2acdaefc978865af9b72a6e65c4ebc70238174a7ad9076d68900f3d866d";
};
};
sha256 = "f104836bdaeed5243ff7e9fc0757d7255778f0af22976eef2b7789e7e1094283";
};
};
double-conversion = {
"2.0.2.0" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "698f94e66b6263a1049b56ede47aa48e224c764f345c3130265742513443595b";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "698f94e66b6263a1049b56ede47aa48e224c764f345c3130265742513443595b";
};
};
sha256 = "67c83bf4619624ef6b950578664cbcd3bc12eaed0d7a387997db5e0ba29fb140";
};
};
foundation = {
"0.0.26.1" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "9a2f63a33dc6b3c1425c4755522b8e619d04fdfcfef72e358155b965b28745a8";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "9a2f63a33dc6b3c1425c4755522b8e619d04fdfcfef72e358155b965b28745a8";
};
};
sha256 = "3c588f6bcf875762ac18b03b17a7ee3c0c60c8e2c884c0192269b0a97e89d526";
};
};
network = {
"3.1.2.1" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "ed4b1bb733613df5a2ebecd5533d08f20bacb0dc59ed207fd4b4670fe718713f";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "ed4b1bb733613df5a2ebecd5533d08f20bacb0dc59ed207fd4b4670fe718713f";
};
};
sha256 = "21869fd942cb9996ba26ba9418cdd44ac869f81caba08e5a2b2cdfe792ae4518";
};
"3.1.2.5" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "433a5e076aaa8eb3e4158abae78fb409c6bd754e9af99bc2e87583d2bcd8404a";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "433a5e076aaa8eb3e4158abae78fb409c6bd754e9af99bc2e87583d2bcd8404a";
};
};
sha256 = "ee914e9b43bfb0f415777eb0473236803b14a35d48f6172079260c92c6ceb335";
};
};
terminal-size = {
"0.3.2.1" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "7b2d8e0475a46961d07ddfb91dee618de70eff55d9ba0402ebeac1f9dcf9b18b";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "7b2d8e0475a46961d07ddfb91dee618de70eff55d9ba0402ebeac1f9dcf9b18b";
};
};
sha256 = "8e4fbfea182f3bf5769744196ca88bb2cb1c80caa617debe34336f90db27131e";
};
};
unix-compat = {
"0.5.3" = {
revisions = {
default = {
nix = "lambda";
revNum = 0;
sha256 = "9c6d68f9afb5baa6be55e8415dd401835ce0d4dfc2090f1c169fcd61c152ebac";
};
r0 = {
nix = "lambda";
revNum = 0;
sha256 = "9c6d68f9afb5baa6be55e8415dd401835ce0d4dfc2090f1c169fcd61c152ebac";
};
};
sha256 = "2fe56781422d5caf47dcbbe82c998bd33f429f8c7093483fad36cd2d31dbdceb";
};
};
};
};
};
in result;
}