on 19052d8 help sign in
haskell.nix/test/unit.nix
120 lines 3.8 kB history raw
1{ pkgs, lib, haskellLib }:
3let
4 emptyConfig = {
5 components = {
6 benchmarks = { };
7 exes = { };
8 foreignlibs = { };
9 library = { buildable = true; planned = true; };
10 sublibs = { };
11 tests = { };
12 };
13 package.identifier.name = "empty";
14 package.buildable = true;
15 };
17 componentsConfig = {
18 components = {
19 benchmarks = { bbb = { buildable = true; planned = true; }; };
20 exes = { eee = { buildable = true; planned = true; }; };
21 foreignlibs = { fff = { buildable = true; planned = true; }; };
22 library = { buildable = true; planned = true; };
23 sublibs = { };
24 tests = { ttt = { buildable = true; planned = true; }; };
25 };
26 package.identifier.name = "nnn";
27 package.buildable = true;
28 };
30 testRepoData = {
31 url = "https://github.com/input-output-hk/haskell.nix.git";
32 ref = "487eea1c249537d34c27f6143dff2b9d5586c657";
33 sha256 = "077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123";
34 };
35in
36lib.runTests {
37 # identity function for applyComponents
38 test-applyComponents-id = {
39 expr = haskellLib.applyComponents (componentId: component: component) emptyConfig;
40 expected = emptyConfig.components;
41 };
43 # map a component to its component name and check these are correct
44 test-applyComponents-library = {
45 expr = haskellLib.applyComponents (componentId: component: componentId.cname) emptyConfig;
46 expected = emptyConfig.components // { library = "empty"; };
47 };
49 test-applyComponents-components = {
50 expr = haskellLib.applyComponents (componentId: component: component) componentsConfig;
51 expected = componentsConfig.components;
52 };
54 # testing that the tests work
55 testId = {
56 expr = lib.id 1;
57 expected = 1;
58 };
60 testParseBlock1 = {
61 expr = __toJSON (haskellLib.parseBlock "cabal.project" (_: null) ''
62 type: git
63 location: https://github.com/input-output-hk/haskell.nix.git
64 tag: 487eea1c249537d34c27f6143dff2b9d5586c657
65 --sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
66 -- end of block
67 '');
68 expected = __toJSON {
69 otherText = "-- end of block\n";
70 sourceRepo = testRepoData // { subdirs = ["."]; };
71 };
72 };
74 testParseBlock2 = {
75 expr = __toJSON (haskellLib.parseBlock "cabal.project" (_: null) ''
76 type: git
77 location: https://github.com/input-output-hk/haskell.nix.git
78 tag: 487eea1c249537d34c27f6143dff2b9d5586c657
79 --sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
80 subdir: dir
81 -- end of block
82 '');
83 expected = __toJSON {
84 otherText = "-- end of block\n";
85 sourceRepo = testRepoData // { subdirs = ["dir"]; };
86 };
87 };
89 testParseBlock3 = {
90 expr = __toJSON (haskellLib.parseBlock "cabal.project" (_: null) ''
91 type: git
92 location: https://github.com/input-output-hk/haskell.nix.git
93 tag: 487eea1c249537d34c27f6143dff2b9d5586c657
94 --sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
95 subdir: dir1 dir2
96 -- end of block
97 '');
98 expected = __toJSON {
99 otherText = "-- end of block\n";
100 sourceRepo = testRepoData // { subdirs = ["dir1" "dir2"]; };
101 };
102 };
104 testParseBlock4 = {
105 expr = __toJSON (haskellLib.parseBlock "cabal.project" (_: null) ''
106 type: git
107 location: https://github.com/input-output-hk/haskell.nix.git
108 tag: 487eea1c249537d34c27f6143dff2b9d5586c657
109 --sha256: 077j5j3j86qy1wnabjlrg4dmqy1fv037dyq3xb8ch4ickpxxs123
110 subdir:
111 dir1
112 dir2
113 -- end of block
114 '');
115 expected = __toJSON {
116 otherText = "-- end of block\n";
117 sourceRepo = testRepoData // { subdirs = ["dir1" "dir2"]; };
118 };
119 };