Skip to content

Commit 8642fac

Browse files
committed
tests: Add unit tests for library functions
1 parent 20226fa commit 8642fac

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

test/default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ let
1313
# The new Haskell infra applied to nix representation of Hackage
1414
haskell = import ../. hackage;
1515

16+
haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
17+
1618
in {
1719
cabal-simple = callPackage ./cabal-simple { inherit haskell; };
1820
cabal-22 = callPackage ./cabal-22 { inherit haskell; };
21+
22+
# Run unit tests with: nix-instantiate --eval --strict -A unit
23+
# An empty list means success.
24+
unit = callPackage ./unit.nix { inherit haskellLib; };
1925
}
2026

2127
## possible test cases

test/unit.nix

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{ lib, haskellLib }:
2+
3+
let
4+
emptyConfig = {
5+
components = {
6+
benchmarks = { };
7+
exes = { };
8+
foreignlibs = { };
9+
library = "library";
10+
sublibs = { };
11+
tests = { };
12+
all = "all";
13+
};
14+
package.identifier.name = "empty";
15+
};
16+
17+
componentsConfig = {
18+
components = {
19+
benchmarks = { bbb = "bbb"; };
20+
exes = { eee = "eee"; };
21+
foreignlibs = { fff = "fff"; };
22+
library = "library";
23+
sublibs = { };
24+
tests = { ttt = "ttt"; };
25+
all = "all";
26+
};
27+
package.identifier.name = "nnn";
28+
};
29+
30+
in
31+
lib.runTests {
32+
# identity function for applyComponents
33+
test-applyComponents-id = {
34+
expr = haskellLib.applyComponents (componentId: component: component) emptyConfig;
35+
expected = emptyConfig.components;
36+
};
37+
38+
# map a component to its component name and check these are correct
39+
test-applyComponents-library = {
40+
expr = haskellLib.applyComponents (componentId: component: componentId.cname) emptyConfig;
41+
expected = emptyConfig.components // { library = "empty"; all = "empty"; };
42+
};
43+
44+
test-applyComponents-components = {
45+
expr = haskellLib.applyComponents (componentId: component: component) componentsConfig;
46+
expected = componentsConfig.components;
47+
};
48+
49+
# testing that the tests work
50+
testId = {
51+
expr = lib.id 1;
52+
expected = 1;
53+
};
54+
}

0 commit comments

Comments
 (0)