tests: Add tests for the shellFor function

This commit is contained in:
Rodney Lorrimar 2019-05-12 21:57:22 +10:00
parent bbd0133281
commit b060ea5576
No known key found for this signature in database
GPG Key ID: 2CCD588917A9A868
5 changed files with 84 additions and 0 deletions

View File

@ -17,6 +17,7 @@ in {
builder-haddock = haskell.callPackage ./builder-haddock {};
stack-simple = haskell.callPackage ./stack-simple {};
snapshots = haskell.callPackage ./snapshots {};
shell-for = haskell.callPackage ./shell-for {};
callStackToNix = haskell.callPackage ./callStackToNix {};
callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};

View File

@ -57,4 +57,9 @@ writeScript "regen-tests.sh" ''
cd stack-simple
stack-to-nix -o .
cd ..
cd shell-for
cabal_configure
plan-to-nix -o . --plan-json dist-newstyle/cache/plan.json --cabal-project cabal.project
cd ..
''

19
test/shell-for/conduit.hs Normal file
View File

@ -0,0 +1,19 @@
-- https://github.com/snoyberg/conduit#readme
import Conduit
import System.Directory (removeFile)
main = do
-- Pure operations: summing numbers.
print $ runConduitPure $ yieldMany [1..10] .| sumC
-- Exception safe file access: copy a file.
writeFile "input.txt" "This is a test." -- create the source file
runConduitRes $ sourceFileBS "input.txt" .| sinkFile "output.txt" -- actual copying
readFile "output.txt" >>= putStrLn -- prove that it worked
-- Perform transformations.
print $ runConduitPure $ yieldMany [1..10] .| mapC (+ 1) .| sinkList
removeFile "input.txt"
removeFile "output.txt"

View File

@ -0,0 +1,52 @@
{ stdenv, cabal-install, mkCabalProjectPkgSet }:
with stdenv.lib;
let
pkgSet = mkCabalProjectPkgSet {
plan-pkgs = import ./pkgs.nix;
pkg-def-extras = [{
pkga = ./.plan.nix/pkga.nix;
pkgb = ./.plan.nix/pkgb.nix;
}];
modules = [{
# Package has no exposed modules which causes
# haddock: No input file(s)
packages.bytestring-builder.doHaddock = false;
}];
};
env = pkgSet.config.hsPkgs.shellFor {
# Shell will provide the dependencies of pkga and pkgb, but not
# pkga and pkgb themselves.
packages = ps: with ps; [ pkga pkgb ];
# This adds cabal-install to the shell, which helps tests because
# they use a nix-shell --pure. Normally you would BYO cabal-install.
buildInputs = [ cabal-install ];
};
in
stdenv.mkDerivation {
name = "shell-for-test";
buildCommand = ''
########################################################################
# test shell-for with an example program
cp ${./pkgb/src}/*.hs .
printf "checking that the shell env has the dependencies...\n" >& 2
${env.ghc}/bin/runghc conduit.hs
touch $out
'';
meta.platforms = platforms.all;
passthru = {
# Used for debugging with nix repl
inherit pkgSet;
# Used for testing externally with nix-shell (../tests.sh).
inherit env;
};
}

View File

@ -54,4 +54,11 @@ nix-shell $NIX_BUILD_ARGS \
--run 'cd cabal-simple && cabal new-build'
echo >& 2
printf "*** Checking shellFor works for a cabal project...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A shell-for.env \
--run 'cd shell-for && cabal new-build all'
echo >& 2
printf "\n*** Finished successfully\n" >& 2