on iko/ghcjs-patch-master help sign in
tests: Add tests for the shellFor function
commita2a28b5a7a061fed29ad25688d991275d0911d18 authorRodney Lorrimar <rodney.lorrimar@iohk.io> dateSun 12 May 2019, 21:57 (7 years ago) parent90cdb97
5 files changed+84−1
test/default.nix+1−1 test/regen.nix+5 test/shell-for/conduit.hs+19 test/shell-for/default.nix+52 test/tests.sh+7
test/default.nix+1−1
@@ -16,8 +16,8 @@ in {
1616 with-packages = haskell.callPackage ./with-packages { inherit util; };
1717 builder-haddock = haskell.callPackage ./builder-haddock {};
1818 stack-simple = haskell.callPackage ./stack-simple {};
19+ shell-for = haskell.callPackage ./shell-for {};
1920 callStackToNix = haskell.callPackage ./callStackToNix {};
20−
2121 callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {};
2222
2323 # Run unit tests with: nix-instantiate --eval --strict -A unit
test/regen.nix+5
@@ -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.hsnew file+19
@@ -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.nixnew file+52
@@ -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+7
@@ -54,4 +54,11 @@ nix-shell $NIX_BUILD_ARGS \
5454 --run 'cd cabal-simple && cabal new-build'
5555echo >& 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+
5764printf "\n*** Finished successfully\n" >& 2