mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-09-17 09:57:27 +03:00
tests: Add unit tests for library functions
This commit is contained in:
parent
20226fa294
commit
8642facf1e
@ -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
54
test/unit.nix
Normal 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;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user