tests: Add test for haddock generation

This commit is contained in:
Rodney Lorrimar 2019-02-12 12:45:32 +10:00
parent d1457606ed
commit 8ad8731e29
No known key found for this signature in database
GPG Key ID: 2CCD588917A9A868
7 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@ -0,0 +1,6 @@
-- | Haddock test stuff
module TestHaddock (hello) where
-- | Standard hello text.
hello :: String
hello = "Hello, world!"

View File

@ -0,0 +1,92 @@
{ pkgs
, haskell
, stdenv
}:
with stdenv.lib;
let
pkgSet = haskell.mkPkgSet {
inherit pkgs;
# generated with:
# cabal new-build
# plan-to-nix dist-newstyle/cache/plan.json > plan.nix
# cabal-to-nix test-haddock.cabal > test-haddock.nix
pkg-def = import ./plan.nix;
pkg-def-overlays = [
{ test-haddock = ./test-haddock.nix; }
];
modules = [
# overrides to fix the build
{
packages.transformers-compat.components.library.doExactConfig = true;
}
{
# Add a hook to the haddock phase
packages.test-haddock.postHaddock = ''
echo "==="
echo "This is the postHaddock hook. The files are:"
find .
echo "==="
'';
# Check that the package option works
packages.stm.doHaddock = false;
}
];
};
packages = pkgSet.config.hsPkgs;
in
stdenv.mkDerivation {
name = "builder-haddock-test";
buildCommand = let
inherit (packages.test-haddock.components) library;
noDocLibrary = packages.stm.components.library;
in ''
########################################################################
# test haddock
doc="${toString library.doc}"
docDir="${toString library.haddockDir}"
# exeDoc="$ disabled {toString packages.test-haddock.components.exes.test-haddock.doc}"
# printf "checking that executable output does not have docs ... " >& 2
# echo $exeDoc
# test "$exeDoc" = ""
printf "checking that documentation directory was built... " >& 2
echo "$doc" >& 2
test -n "$doc"
printf "checking that documentation was generated... " >& 2
grep hello "$docDir/TestHaddock.html" > /dev/null
echo yes >& 2
printf "checking for hoogle index of package... " >& 2
grep hello "$docDir/test-haddock.txt" > /dev/null
echo yes >& 2
printf "checking for absence of documentation in another package... " >& 2
if [ -d "${toString noDocLibrary.haddockDir}" ]; then
echo "it exists - FAIL" >& 2
else
echo PASS >& 2
fi
printf "checking for absence of library package store paths in docs... " >& 2
if grep -R ${library} "$docDir" > /dev/null; then
echo "Found ${library} - FAIL" >& 2
exit 1
else
echo "PASS" >& 2
fi
touch $out
'';
meta.platforms = platforms.all;
} // { inherit packages pkgSet; }

View File

@ -0,0 +1,23 @@
hackage:
{
packages = {
"ghc-prim".revision = hackage."ghc-prim"."0.5.2.0".revisions.default;
"stm".revision = hackage."stm"."2.4.5.1".revisions.default;
"rts".revision = hackage."rts"."1.0".revisions.default;
"base".revision = hackage."base"."4.11.1.0".revisions.default;
"array".revision = hackage."array"."0.5.2.0".revisions.default;
"integer-gmp".revision = hackage."integer-gmp"."1.0.2.0".revisions.default;
};
compiler = {
version = "8.4.4";
nix-name = "ghc844";
packages = {
"ghc-prim" = "0.5.2.0";
"stm" = "2.4.5.1";
"rts" = "1.0";
"base" = "4.11.1.0";
"array" = "0.5.2.0";
"integer-gmp" = "1.0.2.0";
};
};
}

View File

@ -0,0 +1,15 @@
cabal-version: 2.2
name: test-haddock
version: 0.1.0.0
license: NONE
author: Rodney Lorrimar
maintainer: rodney.lorrimar@iohk.io
library
exposed-modules: TestHaddock
other-modules: Paths_test_haddock
-- other-extensions:
build-depends: base ^>=4.11.1.0
, stm
-- hs-source-dirs:
default-language: Haskell2010

View File

@ -0,0 +1,36 @@
{ system
, compiler
, flags
, pkgs
, hsPkgs
, pkgconfPkgs
, ... }:
{
flags = {};
package = {
specVersion = "2.2";
identifier = {
name = "test-haddock";
version = "0.1.0.0";
};
license = "NONE";
copyright = "";
maintainer = "rodney.lorrimar@iohk.io";
author = "Rodney Lorrimar";
homepage = "";
url = "";
synopsis = "";
description = "";
buildType = "Simple";
};
components = {
"library" = {
depends = [
(hsPkgs.base)
(hsPkgs.stm)
];
};
};
} // rec {
src = pkgs.lib.mkDefault ./.;
}

View File

@ -21,6 +21,7 @@ in {
cabal-simple = callPackage ./cabal-simple { inherit haskell util; };
cabal-22 = callPackage ./cabal-22 { inherit haskell; };
with-packages = callPackage ./with-packages { inherit haskell util; };
builder-haddock = callPackage ./builder-haddock { inherit haskell; };
# Run unit tests with: nix-instantiate --eval --strict -A unit
# An empty list means success.