tests: Add unit tests for library functions

This commit is contained in:
Rodney Lorrimar 2019-01-30 15:26:54 +10:00
parent 20226fa294
commit 8642facf1e
No known key found for this signature in database
GPG Key ID: 2CCD588917A9A868
2 changed files with 60 additions and 0 deletions

View File

@ -13,9 +13,15 @@ let
# The new Haskell infra applied to nix representation of Hackage
haskell = import ../. hackage;
haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
in {
cabal-simple = callPackage ./cabal-simple { inherit haskell; };
cabal-22 = callPackage ./cabal-22 { inherit haskell; };
# Run unit tests with: nix-instantiate --eval --strict -A unit
# An empty list means success.
unit = callPackage ./unit.nix { inherit haskellLib; };
}
## possible test cases

54
test/unit.nix Normal file
View File

@ -0,0 +1,54 @@
{ lib, haskellLib }:
let
emptyConfig = {
components = {
benchmarks = { };
exes = { };
foreignlibs = { };
library = "library";
sublibs = { };
tests = { };
all = "all";
};
package.identifier.name = "empty";
};
componentsConfig = {
components = {
benchmarks = { bbb = "bbb"; };
exes = { eee = "eee"; };
foreignlibs = { fff = "fff"; };
library = "library";
sublibs = { };
tests = { ttt = "ttt"; };
all = "all";
};
package.identifier.name = "nnn";
};
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"; all = "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;
};
}