on e94de40 help sign in
haskell.nix/test/tests.sh
135 lines 4.7 kB history raw
1#! /usr/bin/env nix-shell
2#! nix-shell -i bash -p bash jq nix gnused
4set -euo pipefail
6NIX_BUILD_ARGS="${NIX_BUILD_ARGS:-}"
8cd $(dirname $0)
10if [ "$#" != "1" ]; then
11 echo "Please pass a compiler-nix-name to use. For example: ./test/test.sh ghc884"
12 exit 1
13fi
15GHC=$1
17printf "*** Cleaning package build directories..." >& 2
18rm -rvf */cabal.project.local */.ghc.environment* */dist */dist-newstyle */.stack-work
19echo >& 2
21printf "*** Running the nix-build tests...\n" >& 2
22nix build $NIX_BUILD_ARGS \
23 -I . -I .. \
24 --option restrict-eval true \
25 --option allowed-uris "https://github.com/NixOS https://github.com/input-output-hk" \
26 --no-link --keep-going -f default.nix \
27 --argstr compiler-nix-name $GHC
28echo >& 2
30printf "*** Running the unit tests... " >& 2
31res=$(nix-instantiate --eval --json --strict ./default.nix --argstr compiler-nix-name $GHC -A unit.tests)
32num_failed=$(jq length <<< "$res")
33if [ $num_failed -eq 0 ]; then
34 printf "PASSED\n" >& 2
35else
36 printf "$num_failed FAILED\n" >& 2
37 jq . <<< "$res"
38 exit 1
39fi
41printf "*** Checking that a nix-shell works for runghc...\n" >& 2
42nix-shell $NIX_BUILD_ARGS \
43 --pure ./default.nix \
44 --argstr compiler-nix-name $GHC \
45 -A with-packages.test-shell \
46 --run 'runghc with-packages/Point.hs'
47echo >& 2
49printf "*** Checking that a nix-shell works for cabal...\n" >& 2
50nix-shell $NIX_BUILD_ARGS \
51 --pure ./default.nix \
52 --argstr compiler-nix-name $GHC \
53 -A with-packages.test-shell \
54 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && type -p ghc && cd with-packages && cabal new-build'
55echo >& 2
57printf "*** Checking that a nix-shell works for cabal (doExactConfig component)...\n" >& 2
58nix-shell $NIX_BUILD_ARGS \
59 --pure ./default.nix \
60 --argstr compiler-nix-name $GHC \
61 -A with-packages.test-shell-dec \
62 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && cabal new-build'
63echo >& 2
65printf "*** Checking that a nix-shell works for a project with test-suite build-tools and benchmarks...\n" >& 2
66printf "!!! This is expected to fail until https://github.com/input-output-hk/haskell.nix/issues/231 is resolved! \n" >& 2
67nix-shell $NIX_BUILD_ARGS \
68 --pure ./default.nix \
69 --argstr compiler-nix-name $GHC \
70 -A cabal-22.shell \
71 --run 'cd cabal-22 && cabal new-build all --enable-tests --enable-benchmarks' \
72 || true
73echo >& 2
75printf "*** Checking that a nix-shell works for a multi-target project...\n" >& 2
76nix-shell $NIX_BUILD_ARGS \
77 --pure ./default.nix \
78 --argstr compiler-nix-name $GHC \
79 -A cabal-simple.test-shell \
80 --run 'cd cabal-simple && cabal new-build'
81echo >& 2
83printf "*** Checking shellFor works for a cabal project, multiple packages...\n" >& 2
84nix-shell $NIX_BUILD_ARGS \
85 --pure ./default.nix \
86 --argstr compiler-nix-name $GHC \
87 -A shell-for.env \
88 --run 'cd shell-for && cabal new-build all'
89echo >& 2
91printf "*** Checking shellFor works for a cabal project, single package...\n" >& 2
92nix-shell $NIX_BUILD_ARGS \
93 --pure ./default.nix \
94 --argstr compiler-nix-name $GHC \
95 -A shell-for.envPkga \
96 --run 'cd shell-for && cabal new-build --project=single.project all'
97echo >& 2
99printf "*** Checking shellFor has a working hoogle index...\n" >& 2
100nix-shell $NIX_BUILD_ARGS \
101 --pure ./default.nix \
102 --argstr compiler-nix-name $GHC \
103 -A shell-for.env \
104 --run 'hoogle ConduitT | grep Data.Conduit'
105echo >& 2
107printf "*** Checking shellFor does not depend on given packages...\n" >& 2
108drva=$(nix-instantiate ./default.nix --argstr compiler-nix-name $GHC -A shell-for.env)
109echo "-- hello" >> shell-for/pkga/PkgA.hs
110drvb=$(nix-instantiate ./default.nix --argstr compiler-nix-name $GHC -A shell-for.env)
111sed -i -e '/-- hello/d' shell-for/pkga/PkgA.hs
112if [ "$drva" != "$drvb" ]; then
113 printf "FAIL\nShell derivations\n$drva\n$drvb\n are not identical.\n" >& 2
114 exit 1
115else
116 printf "PASS\n" >& 2
117fi
119printf "*** Checking the maintainer scripts...\n" >& 2
120nix build $NIX_BUILD_ARGS --no-link --keep-going -f ../build.nix --argstr compiler-nix-name $GHC maintainer-scripts
121echo >& 2
123printf "*** Checking that plan construction works with extra Hackages...\n" >& 2
124nix build $NIX_BUILD_ARGS --no-link \
125 -f ./default.nix --argstr compiler-nix-name $GHC \
126 extra-hackage.run.project.plan-nix
127echo >& 2
129printf "*** Checking that package with extra Hackages can be build...\n" >& 2
130nix build $NIX_BUILD_ARGS --no-link \
131 -f ./default.nix --argstr compiler-nix-name $GHC \
132 extra-hackage.run.project.hsPkgs.external-package-user.components.exes.external-package-user
133echo >& 2
135printf "\n*** Finished successfully\n" >& 2