haskell.nix/test/tests.sh
Hamish Mackenzie 6be886644f Cross comp. & callCabalProjectToNix/callStackToNix (#202)
* Cross comp. & callCabalProjectToNix/callStackToNix

This fixes an issue where the these IFD functions fail because they try
to build and run a cross compiled nix-tools on the build system.

It may also help if there are cross compilation issues with
setup-depends (they also access the buildPackages).

* Align stack-to-nix ifd with plan-to-nix ifd

This also fixes the restricted/pure eval issues with callStackToNix.

I've also made the tests run in restricted mode to catch these kinds of
issues.
2019-07-13 22:13:15 +08:00

87 lines
2.7 KiB
Bash
Executable File

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash jq nix
set -euo pipefail
NIX_BUILD_ARGS="${NIX_BUILD_ARGS:-}"
cd $(dirname $0)
printf "*** Cleaning package build directories..." >& 2
rm -rvf */cabal.project.local */.ghc.environment* */dist */dist-newstyle */.stack-work
echo >& 2
printf "*** Running the nix-build tests...\n" >& 2
nix build $NIX_BUILD_ARGS \
-I . -I .. \
--option restrict-eval true \
--option allowed-uris "https://github.com/NixOS https://github.com/input-output-hk" \
--no-link --keep-going -f default.nix
echo >& 2
printf "*** Running the unit tests... " >& 2
res=$(nix-instantiate --eval --json --strict ./default.nix -A unit.tests)
num_failed=$(jq length <<< "$res")
if [ $num_failed -eq 0 ]; then
printf "PASSED\n" >& 2
else
printf "$num_failed FAILED\n" >& 2
jq . <<< "$res"
exit 1
fi
printf "*** Checking that a nix-shell works for runghc...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A with-packages.test-shell \
--run 'runghc with-packages/Point.hs'
echo >& 2
printf "*** Checking that a nix-shell works for cabal...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A with-packages.test-shell \
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && type -p ghc && cd with-packages && cabal new-build'
echo >& 2
printf "*** Checking that a nix-shell works for cabal (doExactConfig component)...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A with-packages.test-shell-dec \
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && cabal new-build'
echo >& 2
printf "*** Checking that a nix-shell works for a multi-target project...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A cabal-simple.test-shell \
--run 'cd cabal-simple && cabal new-build'
echo >& 2
printf "*** Checking shellFor works for a cabal project, multiple packages...\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 "*** Checking shellFor works for a cabal project, single package...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A shell-for.envPkga \
--run 'cd shell-for && cabal new-build --project=single.project all'
echo >& 2
printf "*** Checking shellFor has a working hoogle index...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A shell-for.env \
--run 'hoogle ConduitT | grep Data.Conduit'
echo >& 2
printf "*** Checking the maintainer scripts...\n" >& 2
nix build $NIX_BUILD_ARGS --no-link --keep-going -f ../build.nix maintainer-scripts
echo >& 2
printf "\n*** Finished successfully\n" >& 2