Skip to content

Commit e84e72d

Browse files
committed
Add tests for the shellFor function
1 parent e814e33 commit e84e72d

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ in {
1515
with-packages = haskell.callPackage ./with-packages { inherit util; };
1616
builder-haddock = haskell.callPackage ./builder-haddock {};
1717
stack-simple = haskell.callPackage ./stack-simple {};
18+
shell-for = haskell.callPackage ./shell-for { inherit util; };
1819

1920
# Run unit tests with: nix-instantiate --eval --strict -A unit
2021
# An empty list means success.

test/shell-for/conduit.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- https://github.com/snoyberg/conduit#readme
2+
3+
import Conduit
4+
import System.Directory (removeFile)
5+
6+
main = do
7+
-- Pure operations: summing numbers.
8+
print $ runConduitPure $ yieldMany [1..10] .| sumC
9+
10+
-- Exception safe file access: copy a file.
11+
writeFile "input.txt" "This is a test." -- create the source file
12+
runConduitRes $ sourceFileBS "input.txt" .| sinkFile "output.txt" -- actual copying
13+
readFile "output.txt" >>= putStrLn -- prove that it worked
14+
15+
-- Perform transformations.
16+
print $ runConduitPure $ yieldMany [1..10] .| mapC (+ 1) .| sinkList
17+
18+
removeFile "input.txt"
19+
removeFile "output.txt"

test/shell-for/default.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ stdenv, util, mkStackSnapshotPkgSet }:
2+
3+
with stdenv.lib;
4+
with util;
5+
6+
let
7+
pkgSet = mkStackSnapshotPkgSet {
8+
resolver = "lts-12.21";
9+
# Work around a mismatch between stackage metadata and the
10+
# libraries shipped with GHC.
11+
# https://github.com/commercialhaskell/stackage/issues/4466
12+
pkg-def-extras = [(hackage: {
13+
packages = {
14+
"transformers" = (((hackage.transformers)."0.5.6.2").revisions).default;
15+
"process" = (((hackage.process)."1.6.5.0").revisions).default;
16+
};
17+
})];
18+
};
19+
20+
env = pkgSet.config.hsPkgs.shellFor {
21+
packages = ps: with ps; [ conduit conduit-extra resourcet ];
22+
withHoogle = true;
23+
};
24+
25+
in
26+
stdenv.mkDerivation {
27+
name = "shell-for-test";
28+
29+
buildCommand = ''
30+
########################################################################
31+
# test shell-for with an example program
32+
33+
printf "checking that the shell env has the dependencies...\n" >& 2
34+
${env.ghc}/bin/runghc ${./conduit.hs}
35+
36+
touch $out
37+
'';
38+
39+
meta.platforms = platforms.all;
40+
passthru = {
41+
# Used for debugging with nix repl
42+
inherit pkgSet;
43+
44+
# Used for testing externally with nix-shell (../tests.sh).
45+
# This just adds cabal-install to the existing shell.
46+
env = addCabalInstall env;
47+
};
48+
}

test/tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,11 @@ nix-shell $NIX_BUILD_ARGS \
5454
--run 'cd cabal-simple && cabal new-build'
5555
echo >& 2
5656

57+
printf "*** Checking shellFor works with a Stackage snapshot...\n" >& 2
58+
nix-shell $NIX_BUILD_ARGS \
59+
--pure ./default.nix \
60+
-A shell-for.env \
61+
--run 'cd shell-for && runghc conduit.hs'
62+
echo >& 2
63+
5764
printf "\n*** Finished successfully\n" >& 2

0 commit comments

Comments
 (0)