mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-09-11 06:55:40 +03:00
tests: Add tests for the shellFor function
This commit is contained in:
parent
bbd0133281
commit
b060ea5576
@ -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 {};
|
||||
|
||||
|
@ -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
19
test/shell-for/conduit.hs
Normal 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"
|
52
test/shell-for/default.nix
Normal file
52
test/shell-for/default.nix
Normal 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;
|
||||
};
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user