@@ -0,0 +1,101 @@
1+{ stdenv, cabal-install, cabalProject', stackProject', recurseIntoAttrs, runCommand, testSrc, compiler-nix-name }:
2+
3+with stdenv.lib;
4+
5+let
6+ projectArgs = {
7+ src = testSrc "coverage-no-libs";
8+ modules = [{
9+ # Package has no exposed modules which causes
10+ # haddock: No input file(s)
11+ packages.bytestring-builder.doHaddock = false;
12+ }];
13+ };
14+
15+ # We can easily select a different compiler when using cabal,
16+ # but for stack we would need a different resolver to be used..
17+ cabalProj = (cabalProject' projectArgs // { inherit compiler-nix-name; });
18+ stackProj = (stackProject' projectArgs);
19+
20+ exeExt = stdenv.hostPlatform.extensions.executable;
21+
22+in recurseIntoAttrs ({
23+ run = stdenv.mkDerivation {
24+ name = "coverage-test";
25+
26+ buildCommand = ''
27+ ########################################################################
28+ # test coverage reports with an example project
29+
30+ fileExistsNonEmpty() {
31+ local file=$1
32+ if [ ! -f "$file" ]; then
33+ echo "Missing: $file"
34+ exit 1
35+ fi
36+ local filesize=$(command stat --format '%s' "$file")
37+ if [ $filesize -eq 0 ]; then
38+ echo "File must not be empty: $file"
39+ exit 1
40+ fi
41+ }
42+ findFileExistsNonEmpty() {
43+ local searchDir=$1
44+ local filePattern=$2
45+
46+ local file="$(find $searchDir -name $filePattern -print -quit)"
47+
48+ if [ -z $file ]; then
49+ echo "Couldn't find file \"$filePattern\" in directory \"$searchDir\"."
50+ exit 1
51+ fi
52+
53+ local filesize=$(command stat --format '%s' "$file")
54+ if [ $filesize -eq 0 ]; then
55+ echo "File must not be empty: $file"
56+ exit 1
57+ fi
58+ }
59+ dirExistsEmpty() {
60+ local dir=$1
61+ if [ ! -d "$dir" ]; then
62+ echo "Missing: $dir"
63+ exit 1
64+ fi
65+ if [ "$(ls -A $dir)" ]; then
66+ echo "Dir should be empty: $dir"
67+ exit 1
68+ fi
69+ }
70+ dirExists() {
71+ local dir=$1
72+ if [ ! -d "$dir" ]; then
73+ echo "Missing: $dir"
74+ exit 1
75+ fi
76+ }
77+
78+ ${concatStringsSep "\n" (map (project: ''
79+ pkga_basedir="${project.hsPkgs.pkga.coverageReport}/share/hpc/vanilla"
80+ dirExistsEmpty "$pkga_basedir/html/pkga-0.1.0.0"
81+ dirExistsEmpty "$pkga_basedir/mix/pkga-0.1.0.0"
82+ dirExistsEmpty "$pkga_basedir/tix/pkga-0.1.0.0"
83+
84+ project_basedir="${project.projectCoverageReport}/share/hpc/vanilla"
85+ dirExistsEmpty "$pkga_basedir/html/pkga-0.1.0.0"
86+ dirExistsEmpty "$pkga_basedir/mix/pkga-0.1.0.0"
87+ dirExistsEmpty "$pkga_basedir/tix/pkga-0.1.0.0"
88+ dirExistsEmpty "$project_basedir/tix/all"
89+ '') [ stackProj ])}
90+
91+ touch $out
92+ '';
93+
94+ meta.platforms = platforms.all;
95+
96+ passthru = {
97+ # Used for debugging with nix repl
98+ inherit cabalProj stackProj;
99+ };
100+ };
101+})