on e94de40 help sign in
130 lines 4.6 kB history raw
1{ stdenv, cabal-install, cabalProject', stackProject', recurseIntoAttrs, runCommand, testSrc, compiler-nix-name }:
3with stdenv.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 run = stdenv.mkDerivation {
28 name = "coverage-test";
30 buildCommand = ''
31 ########################################################################
32 # test coverage reports with an example project
34 fileExistsNonEmpty() {
35 local file=$1
36 if [ ! -f "$file" ]; then
37 echo "Missing: $file"
38 exit 1
39 fi
40 local filesize=$(command stat --format '%s' "$file")
41 if [ $filesize -eq 0 ]; then
42 echo "File must not be empty: $file"
43 exit 1
44 fi
45 }
46 findFileExistsNonEmpty() {
47 local searchDir=$1
48 local filePattern=$2
50 local file="$(find $searchDir -name $filePattern -print -quit)"
52 if [ -z $file ]; then
53 echo "Couldn't find file \"$filePattern\" in directory \"$searchDir\"."
54 exit 1
55 fi
57 local filesize=$(command stat --format '%s' "$file")
58 if [ $filesize -eq 0 ]; then
59 echo "File must not be empty: $file"
60 exit 1
61 fi
62 }
63 dirExistsEmpty() {
64 local dir=$1
65 if [ ! -d "$dir" ]; then
66 echo "Missing: $dir"
67 exit 1
68 fi
69 if [ "$(ls -A $dir)" ]; then
70 echo "Dir should be empty: $dir"
71 exit 1
72 fi
73 }
74 dirExists() {
75 local dir=$1
76 if [ ! -d "$dir" ]; then
77 echo "Missing: $dir"
78 exit 1
79 fi
80 }
82 ${concatStringsSep "\n" (map (project: ''
83 pkga_basedir="${project.hsPkgs.pkga.coverageReport}/share/hpc/vanilla"
84 findFileExistsNonEmpty "$pkga_basedir/mix/pkga-0.1.0.0/" "PkgA.mix"
85 dirExistsEmpty "$pkga_basedir/tix/pkga-0.1.0.0"
86 dirExistsEmpty "$pkga_basedir/html/pkga-0.1.0.0"
88 pkgb_basedir="${project.hsPkgs.pkgb.coverageReport}/share/hpc/vanilla"
89 testTix="$pkgb_basedir/tix/pkgb-0.1.0.0/tests${exeExt}/tests${exeExt}.tix"
90 libTix="$pkgb_basedir/tix/pkgb-0.1.0.0/pkgb-0.1.0.0.tix"
91 fileExistsNonEmpty "$testTix"
92 fileExistsNonEmpty "$libTix"
93 findFileExistsNonEmpty "$pkgb_basedir/mix/pkgb-0.1.0.0/" "ConduitExample.mix"
94 findFileExistsNonEmpty "$pkgb_basedir/mix/pkgb-0.1.0.0/" "PkgB.mix"
95 fileExistsNonEmpty "$pkgb_basedir/html/pkgb-0.1.0.0/hpc_index.html"
97 filesizeTestsTix=$(command stat --format '%s' "$testTix")
98 filesizeLibTix=$(command stat --format '%s' "$libTix")
99 if (( filesizeTestsTix <= filesizeLibTix )); then
100 echo "Filesize of \"$testTix\" ($filesizeTestsTix) should be greather than that of \"$libTix\" ($filesizeLibTix). Did you forget to exclude test modules when creating \"$libTix\"?"
101 exit 1
102 fi
104 project_basedir="${project.projectCoverageReport}/share/hpc/vanilla"
105 fileExistsNonEmpty "$project_basedir/html/index.html"
106 dirExists "$project_basedir/html/pkga-0.1.0.0"
107 dirExists "$project_basedir/html/pkgb-0.1.0.0"
108 findFileExistsNonEmpty "$project_basedir/mix/" "PkgA.mix"
109 findFileExistsNonEmpty "$project_basedir/mix/" "PkgB.mix"
110 findFileExistsNonEmpty "$project_basedir/mix/" "ConduitExample.mix"
111 dirExists "$project_basedir/tix/all"
112 fileExistsNonEmpty "$project_basedir/tix/all/all.tix"
113 dirExists "$project_basedir/tix/pkga-0.1.0.0"
114 dirExists "$project_basedir/tix/pkgb-0.1.0.0"
115 fileExistsNonEmpty "$project_basedir/tix/pkgb-0.1.0.0/pkgb-0.1.0.0.tix"
116 dirExists "$project_basedir/tix/pkgb-0.1.0.0/tests${exeExt}"
117 fileExistsNonEmpty "$project_basedir/tix/pkgb-0.1.0.0/tests${exeExt}/tests${exeExt}.tix"
118 '') [ stackProj ])}
120 touch $out
121 '';
123 meta.platforms = platforms.all;
125 passthru = {
126 # Used for debugging with nix repl
127 inherit cabalProj stackProj;
128 };
129 };
130})