Skip to content

Commit b060ea5

Browse files
committed
tests: Add tests for the shellFor function
1 parent bbd0133 commit b060ea5

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ in {
1717
builder-haddock = haskell.callPackage ./builder-haddock {};
1818
stack-simple = haskell.callPackage ./stack-simple {};
1919
snapshots = haskell.callPackage ./snapshots {};
20+
shell-for = haskell.callPackage ./shell-for {};
2021
callStackToNix = haskell.callPackage ./callStackToNix {};
2122
callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
2223

test/regen.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,9 @@ writeScript "regen-tests.sh" ''
5757
cd stack-simple
5858
stack-to-nix -o .
5959
cd ..
60+
61+
cd shell-for
62+
cabal_configure
63+
plan-to-nix -o . --plan-json dist-newstyle/cache/plan.json --cabal-project cabal.project
64+
cd ..
6065
''

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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{ stdenv, cabal-install, mkCabalProjectPkgSet }:
2+
3+
with stdenv.lib;
4+
5+
let
6+
pkgSet = mkCabalProjectPkgSet {
7+
plan-pkgs = import ./pkgs.nix;
8+
pkg-def-extras = [{
9+
pkga = ./.plan.nix/pkga.nix;
10+
pkgb = ./.plan.nix/pkgb.nix;
11+
}];
12+
modules = [{
13+
# Package has no exposed modules which causes
14+
# haddock: No input file(s)
15+
packages.bytestring-builder.doHaddock = false;
16+
}];
17+
};
18+
19+
env = pkgSet.config.hsPkgs.shellFor {
20+
# Shell will provide the dependencies of pkga and pkgb, but not
21+
# pkga and pkgb themselves.
22+
packages = ps: with ps; [ pkga pkgb ];
23+
# This adds cabal-install to the shell, which helps tests because
24+
# they use a nix-shell --pure. Normally you would BYO cabal-install.
25+
buildInputs = [ cabal-install ];
26+
};
27+
28+
in
29+
stdenv.mkDerivation {
30+
name = "shell-for-test";
31+
32+
buildCommand = ''
33+
########################################################################
34+
# test shell-for with an example program
35+
36+
cp ${./pkgb/src}/*.hs .
37+
38+
printf "checking that the shell env has the dependencies...\n" >& 2
39+
${env.ghc}/bin/runghc conduit.hs
40+
41+
touch $out
42+
'';
43+
44+
meta.platforms = platforms.all;
45+
passthru = {
46+
# Used for debugging with nix repl
47+
inherit pkgSet;
48+
49+
# Used for testing externally with nix-shell (../tests.sh).
50+
inherit env;
51+
};
52+
}

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 for a cabal project...\n" >& 2
58+
nix-shell $NIX_BUILD_ARGS \
59+
--pure ./default.nix \
60+
-A shell-for.env \
61+
--run 'cd shell-for && cabal new-build all'
62+
echo >& 2
63+
5764
printf "\n*** Finished successfully\n" >& 2

0 commit comments

Comments
 (0)