on 19052d8 help sign in
132 lines 4.8 kB history raw
1{ stdenv, lib, cabal-install, cabalProject', stackProject', recurseIntoAttrs, runCommand, testSrc, compiler-nix-name }:
3with lib;
5let
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;
13 # Coverage
14 packages.pkga.components.library.doCoverage = true;
15 packages.pkgb.components.library.doCoverage = true;
16 }];
17 };
19 # We can easily select a different compiler when using cabal,
20 # but for stack we would need a different resolver to be used..
21 cabalProj = (cabalProject' projectArgs // { inherit compiler-nix-name; });
22 stackProj = (stackProject' projectArgs);
24 exeExt = stdenv.hostPlatform.extensions.executable;
26in recurseIntoAttrs ({
27 # Does not work on ghcjs because it needs zlib.
28 meta.disabled = stdenv.hostPlatform.isGhcjs;
29 run = stdenv.mkDerivation {
30 name = "coverage-test";
32 buildCommand = ''
33 ########################################################################
34 # test coverage reports with an example project
36 fileExistsNonEmpty() {
37 local file=$1
38 if [ ! -f "$file" ]; then
39 echo "Missing: $file"
40 exit 1
41 fi
42 local filesize=$(command stat --format '%s' "$file")
43 if [ $filesize -eq 0 ]; then
44 echo "File must not be empty: $file"
45 exit 1
46 fi
47 }
48 findFileExistsNonEmpty() {
49 local searchDir=$1
50 local filePattern=$2
52 local file="$(find $searchDir -name $filePattern -print -quit)"
54 if [ -z $file ]; then
55 echo "Couldn't find file \"$filePattern\" in directory \"$searchDir\"."
56 exit 1
57 fi
59 local filesize=$(command stat --format '%s' "$file")
60 if [ $filesize -eq 0 ]; then
61 echo "File must not be empty: $file"
62 exit 1
63 fi
64 }
65 dirExistsEmpty() {
66 local dir=$1
67 if [ ! -d "$dir" ]; then
68 echo "Missing: $dir"
69 exit 1
70 fi
71 if [ "$(ls -A $dir)" ]; then
72 echo "Dir should be empty: $dir"
73 exit 1
74 fi
75 }
76 dirExists() {
77 local dir=$1
78 if [ ! -d "$dir" ]; then
79 echo "Missing: $dir"
80 exit 1
81 fi
82 }
84 ${concatStringsSep "\n" (map (project: ''
85 pkga_basedir="${project.hsPkgs.pkga.coverageReport}/share/hpc/vanilla"
86 findFileExistsNonEmpty "$pkga_basedir/mix/pkga-0.1.0.0/" "PkgA.mix"
87 dirExistsEmpty "$pkga_basedir/tix/pkga-0.1.0.0"
88 dirExistsEmpty "$pkga_basedir/html/pkga-0.1.0.0"
90 pkgb_basedir="${project.hsPkgs.pkgb.coverageReport}/share/hpc/vanilla"
91 testTix="$pkgb_basedir/tix/pkgb-0.1.0.0/tests${exeExt}/tests${exeExt}.tix"
92 libTix="$pkgb_basedir/tix/pkgb-0.1.0.0/pkgb-0.1.0.0.tix"
93 fileExistsNonEmpty "$testTix"
94 fileExistsNonEmpty "$libTix"
95 findFileExistsNonEmpty "$pkgb_basedir/mix/pkgb-0.1.0.0/" "ConduitExample.mix"
96 findFileExistsNonEmpty "$pkgb_basedir/mix/pkgb-0.1.0.0/" "PkgB.mix"
97 fileExistsNonEmpty "$pkgb_basedir/html/pkgb-0.1.0.0/hpc_index.html"
99 filesizeTestsTix=$(command stat --format '%s' "$testTix")
100 filesizeLibTix=$(command stat --format '%s' "$libTix")
101 if (( filesizeTestsTix <= filesizeLibTix )); then
102 echo "Filesize of \"$testTix\" ($filesizeTestsTix) should be greather than that of \"$libTix\" ($filesizeLibTix). Did you forget to exclude test modules when creating \"$libTix\"?"
103 exit 1
104 fi
106 project_basedir="${project.projectCoverageReport}/share/hpc/vanilla"
107 fileExistsNonEmpty "$project_basedir/html/index.html"
108 dirExists "$project_basedir/html/pkga-0.1.0.0"
109 dirExists "$project_basedir/html/pkgb-0.1.0.0"
110 findFileExistsNonEmpty "$project_basedir/mix/" "PkgA.mix"
111 findFileExistsNonEmpty "$project_basedir/mix/" "PkgB.mix"
112 findFileExistsNonEmpty "$project_basedir/mix/" "ConduitExample.mix"
113 dirExists "$project_basedir/tix/all"
114 fileExistsNonEmpty "$project_basedir/tix/all/all.tix"
115 dirExists "$project_basedir/tix/pkga-0.1.0.0"
116 dirExists "$project_basedir/tix/pkgb-0.1.0.0"
117 fileExistsNonEmpty "$project_basedir/tix/pkgb-0.1.0.0/pkgb-0.1.0.0.tix"
118 dirExists "$project_basedir/tix/pkgb-0.1.0.0/tests${exeExt}"
119 fileExistsNonEmpty "$project_basedir/tix/pkgb-0.1.0.0/tests${exeExt}/tests${exeExt}.tix"
120 '') (optional (compiler-nix-name == "ghc865") stackProj))}
122 touch $out
123 '';
125 meta.platforms = platforms.all;
127 passthru = {
128 # Used for debugging with nix repl
129 inherit cabalProj stackProj;
130 };
131 };
132})