haskell.nix/lib/check.nix
Dennis Gosnell 6c627b429b
support cabal-doctest (#427)
* Add test.

* wip

* Fix merge regression

* Combine drv, drv.source and drv.dist for doctest

* Skip cabal-doctests test when cross compiling

* Add the --no-magic flag to the .cabal file for the cabal-doctests test.

This appears to be necessary on OSX.

The --no-magic flag stops the doctest executable from expanding path
arguments, trying to locate the package db, etc.

This shouldn't be necessary with cabal-doctest, since all the
necessary options to pass to doctest are computed when running the Setup.hs
script.

See
https://github.com/input-output-hk/haskell.nix/pull/427#issuecomment-605761780.

* Fix cabal-doctest support

* Skip cabal-doctest test plan cross compiling

* More fixes for cabal-doctest

* Skip cabal-doctest tests when cross compiling

Co-authored-by: Moritz Angermann <moritz.angermann@gmail.com>
Co-authored-by: Hamish Mackenzie <Hamish.Mackenzie@iohk.io>
Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@gmail.com>
2021-03-20 14:25:30 +13:00

52 lines
1.5 KiB
Nix

{ stdenv, lib, haskellLib, srcOnly }:
drv:
let
component = drv.config;
# This derivation can be used to execute test component.
# The $out of the derivation is a file containing the resulting
# stdout output.
in stdenv.mkDerivation ({
name = (drv.name + "-check");
# Using `srcOnly` (rather than getting the `src` via a `drv.passthru`)
# should correctly apply the patches from `drv` (if any).
src = drv.source or (srcOnly drv);
passthru = {
inherit (drv) identifier config configFiles executableToolDepends cleanSrc env exeName;
};
inherit (drv) meta LANG LC_ALL buildInputs nativeBuildInputs;
inherit (component) doCheck doCrossCheck;
phases = ["unpackPhase" "buildPhase"];
# If doCheck or doCrossCheck are false we may still build this
# component and we want it to quietly succeed.
buildPhase = ''
mkdir $out
${
# Change to the source sub directory if there is one.
lib.optionalString (drv.srcSubDir or "" != "") ''
cd ${lib.removePrefix "/" drv.srcSubDir}
''
}
runHook preCheck
${toString component.testWrapper} ${drv}/bin/${drv.exeName} ${lib.concatStringsSep " " component.testFlags} | tee $out/test-stdout
# Copy over tix files, if they exist
find . -iname '${drv.exeName}.tix' -exec mkdir -p $out/share/hpc/vanilla/tix/${drv.exeName} \; -exec cp {} $out/share/hpc/vanilla/tix/${drv.exeName}/ \;
runHook postCheck
'';
} // haskellLib.optionalHooks {
inherit (component) preCheck postCheck;
}
// lib.optionalAttrs (drv ? LOCALE_ARCHIVE) { inherit (drv) LOCALE_ARCHIVE; }
)