|
| 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 | +}) |
0 commit comments