Skip to content

Commit 01d061c

Browse files
committed
First pass at tests
1 parent a4ccd53 commit 01d061c

File tree

18 files changed

+139
-88
lines changed

18 files changed

+139
-88
lines changed

overlays/haskell.nix

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,13 @@ final: prev: {
537537
++ (args.modules or [])
538538
++ final.lib.optional (args ? ghc) { ghc.package = args.ghc; };
539539
};
540-
in addProjectAndPackageAttrs {
541-
inherit (pkg-set.config) hsPkgs;
542-
inherit pkg-set;
543-
stack-nix = callProjectResults.projectNix;
540+
project = addProjectAndPackageAttrs {
541+
inherit (pkg-set.config) hsPkgs;
542+
inherit pkg-set;
543+
stack-nix = callProjectResults.projectNix;
544+
};
545+
in project // {
546+
projectCoverageReport = haskellLib.projectCoverageReport (haskellLib.selectProjectPackages project.hsPkgs);
544547
};
545548

546549
stackProject = args: let p = stackProject' args;

test/cabal-coverage/default.nix

Lines changed: 0 additions & 83 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

test/coverage/default.nix

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{ stdenv, cabal-install, cabalProject', stackProject', recurseIntoAttrs, runCommand, testSrc }:
2+
3+
with stdenv.lib;
4+
5+
let
6+
projectArgs = {
7+
src = testSrc "coverage";
8+
modules = [{
9+
# Package has no exposed modules which causes
10+
# haddock: No input file(s)
11+
packages.bytestring-builder.doHaddock = false;
12+
13+
packages.pkga.components.library.doCoverage = true;
14+
packages.pkgb.components.library.doCoverage = true;
15+
}];
16+
};
17+
18+
cabalProject = cabalProject' projectArgs;
19+
stackProject = stackProject' projectArgs;
20+
21+
in recurseIntoAttrs ({
22+
run = stdenv.mkDerivation {
23+
name = "coverage-test";
24+
25+
buildCommand = ''
26+
########################################################################
27+
# test coverage reports with an example project
28+
29+
fileExistsNonEmpty() {
30+
local file=$1
31+
if [ ! -f "$file" ]; then
32+
echo "Missing: $file"
33+
exit 1
34+
fi
35+
local filesize=$(command stat --format '%s' "$file")
36+
if [ $filesize -eq 0 ]; then
37+
echo "File must not be empty: $file"
38+
exit 1
39+
fi
40+
}
41+
findFileExistsNonEmpty() {
42+
local searchDir=$1
43+
local filePattern=$2
44+
45+
local file="$(find $searchDir -name $filePattern -print -quit)"
46+
47+
if [ -z $file ]; then
48+
echo "Couldn't find file \"$filePattern\" in directory \"$searchDir\"."
49+
exit 1
50+
fi
51+
52+
local filesize=$(command stat --format '%s' "$file")
53+
if [ $filesize -eq 0 ]; then
54+
echo "File must not be empty: $file"
55+
exit 1
56+
fi
57+
}
58+
dirExistsEmpty() {
59+
local dir=$1
60+
if [ ! -d "$dir" ]; then
61+
echo "Missing: $dir"
62+
exit 1
63+
fi
64+
if [ "$(ls -A $dir)" ]; then
65+
echo "Dir should be empty: $dir"
66+
exit 1
67+
fi
68+
}
69+
dirExists() {
70+
local dir=$1
71+
if [ ! -d "$dir" ]; then
72+
echo "Missing: $dir"
73+
exit 1
74+
fi
75+
}
76+
77+
${concatStringsSep "\n" (map (project: ''
78+
pkga_basedir="${project.hsPkgs.pkga.coverageReport}/share/hpc/"
79+
findFileExistsNonEmpty "$pkga_basedir/mix/pkga-0.1.0.0/" "PkgA.mix"
80+
dirExistsEmpty "$pkga_basedir/tix/pkga-0.1.0.0"
81+
dirExistsEmpty "$pkga_basedir/html/pkga-0.1.0.0"
82+
83+
pkgb_basedir="${project.hsPkgs.pkgb.coverageReport}/share/hpc/"
84+
testTix="$pkgb_basedir/tix/tests/tests.tix"
85+
libTix="$pkgb_basedir/tix/pkgb-0.1.0.0/pkgb-0.1.0.0.tix"
86+
fileExistsNonEmpty "$testTix"
87+
fileExistsNonEmpty "$libTix"
88+
findFileExistsNonEmpty "$pkgb_basedir/mix/pkgb-0.1.0.0/" "ConduitExample.mix"
89+
findFileExistsNonEmpty "$pkgb_basedir/mix/pkgb-0.1.0.0/" "PkgB.mix"
90+
fileExistsNonEmpty "$pkgb_basedir/mix/tests/Main.mix"
91+
fileExistsNonEmpty "$pkgb_basedir/html/pkgb-0.1.0.0/hpc_index.html"
92+
fileExistsNonEmpty "$pkgb_basedir/html/tests/hpc_index.html"
93+
94+
filesizeTestsTix=$(command stat --format '%s' "$testTix")
95+
filesizeLibTix=$(command stat --format '%s' "$libTix")
96+
if (( filesizeTestsTix <= filesizeLibTix )); then
97+
echo "Filesize of \"$testTix\" ($filesizeTestsTix) should be greather than that of \"$libTix\" ($filesizeLibTix). Did you forget to exclude test modules when creating \"$libTix\"?"
98+
exit 1
99+
fi
100+
101+
project_basedir="${project.projectCoverageReport}/share/hpc/"
102+
fileExistsNonEmpty "$project_basedir/html/index.html"
103+
fileExistsNonEmpty "$project_basedir/tix/all/all.tix"
104+
dirExists "$project_basedir/html/pkga-0.1.0.0"
105+
dirExists "$project_basedir/html/pkgb-0.1.0.0"
106+
dirExists "$project_basedir/html/tests"
107+
dirExists "$project_basedir/mix/pkga-0.1.0.0"
108+
dirExists "$project_basedir/mix/pkgb-0.1.0.0"
109+
dirExists "$project_basedir/mix/tests"
110+
dirExists "$project_basedir/tix/all"
111+
dirExists "$project_basedir/tix/pkga-0.1.0.0"
112+
dirExists "$project_basedir/tix/pkgb-0.1.0.0"
113+
dirExists "$project_basedir/tix/tests"
114+
'') [ cabalProject stackProject ])}
115+
116+
touch $out
117+
'';
118+
119+
meta.platforms = platforms.all;
120+
121+
passthru = {
122+
# Used for debugging with nix repl
123+
inherit cabalProject stackProject;
124+
};
125+
};
126+
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/coverage/stack.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resolver: lts-14.13
2+
3+
packages:
4+
- pkga/
5+
- pkgb/

test/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ let
178178
compiler-nix-name = callTest ./compiler-nix-name {};
179179
hls-cabal = callTest ./haskell-language-server/cabal.nix {};
180180
hls-stack = callTest ./haskell-language-server/stack.nix {};
181-
cabal-coverage = callTest ./cabal-coverage {};
181+
coverage = callTest ./coverage {};
182182

183183
unit = unitTests;
184184
} // lib.optionalAttrs (!stdenv.hostPlatform.isGhcjs && pkgs.haskell-nix.defaultCompilerNixName != "ghc8101" ) {

0 commit comments

Comments
 (0)