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