@@ -0,0 +1,50 @@
1+{ stdenv, fetchFromGitHub, recurseIntoAttrs, runCommand, testSrc, compiler-nix-name, buildPackages, sources }:
2+
3+with stdenv.lib;
4+
5+let
6+ # Using buildPackages.buildPackages here because buildPackages.git
7+ # is built with a cross compiler version of gdb (needed by python).
8+ # So buildPackages.buildPackages.git is more likely to be in the cache.
9+ inherit (buildPackages.buildPackages) jq git;
10+
11+ hpc-coveralls-exes = (buildPackages.haskell-nix.project' {
12+ compiler-nix-name = "ghc865"; # TODO use `inherit compiler-nix-name;` once it is working with 8.8 and 8.10
13+ src = sources.hpc-coveralls;
14+ }).hsPkgs.hpc-coveralls.components.exes;
15+
16+ exampleProjectSrc = sources.cardano-shell;
17+
18+ exampleProject = import "${exampleProjectSrc}" { config = { haskellNix = { coverage = true; }; }; };
19+ exampleCoverageReport = exampleProject.cardanoShellHaskellPackages.projectCoverageReport;
20+
21+in recurseIntoAttrs ({
22+ run = stdenv.mkDerivation {
23+ name = "coverage-golden-test";
24+
25+ nativeBuildInputs = [ git jq hpc-coveralls-exes.hpc-coveralls hpc-coveralls-exes.run-cabal-test ];
26+ buildCommand = ''
27+ ########################################################################
28+ # Test that the coverage reports haven't materially changed
29+
30+ TRAVIS=1 TRAVIS_JOB_ID=1 hpc-coveralls all \
31+ --package-dir ${exampleProjectSrc}/cardano-shell/ \
32+ --package-dir ${exampleProjectSrc}/cardano-launcher \
33+ --hpc-dir ${exampleCoverageReport}/share/hpc/vanilla \
34+ --coverage-mode StrictlyFullLines \
35+ --dont-send
36+
37+ # Format JSON for better diffing error messages and remove
38+ # references to Nix path, our golden coverage file contains no
39+ # Nix paths
40+ cat ./travis-ci-1.json | jq -S | sed "s;${exampleProjectSrc}/;;g" > ./actual.json
41+
42+ # Fail if doesn't match golden, i.e. our coverage has changed
43+ diff ${./golden.json} ./actual.json
44+
45+ touch $out
46+ '';
47+
48+ meta.platforms = platforms.all;
49+ };
50+})