on fa2fa13 help sign in
haskell.nix/test/tests.sh
138 lines 4.8 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
42# This has to use ghc865 for now
43nix-shell $NIX_BUILD_ARGS \
44 --pure ./default.nix \
45 --argstr compiler-nix-name ghc865 \
46 -A with-packages.test-shell \
47 --run 'runghc with-packages/Point.hs'
48echo >& 2
50printf "*** Checking that a nix-shell works for cabal...\n" >& 2
51# This has to use ghc865 for now
52nix-shell $NIX_BUILD_ARGS \
53 --pure ./default.nix \
54 --argstr compiler-nix-name ghc865 \
55 -A with-packages.test-shell \
56 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && type -p ghc && cd with-packages && cabal new-build'
57echo >& 2
59printf "*** Checking that a nix-shell works for cabal (doExactConfig component)...\n" >& 2
60# This has to use ghc865 for now
61nix-shell $NIX_BUILD_ARGS \
62 --pure ./default.nix \
63 --argstr compiler-nix-name ghc865 \
64 -A with-packages.test-shell-dec \
65 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && cabal new-build'
66echo >& 2
68printf "*** Checking that a nix-shell works for a project with test-suite build-tools and benchmarks...\n" >& 2
69printf "!!! This is expected to fail until https://github.com/input-output-hk/haskell.nix/issues/231 is resolved! \n" >& 2
70nix-shell $NIX_BUILD_ARGS \
71 --pure ./default.nix \
72 --argstr compiler-nix-name $GHC \
73 -A cabal-22.shell \
74 --run 'cd cabal-22 && cabal new-build all --enable-tests --enable-benchmarks' \
75 || true
76echo >& 2
78printf "*** Checking that a nix-shell works for a multi-target project...\n" >& 2
79nix-shell $NIX_BUILD_ARGS \
80 --pure ./default.nix \
81 --argstr compiler-nix-name $GHC \
82 -A cabal-simple.test-shell \
83 --run 'cd cabal-simple && cabal new-build'
84echo >& 2
86printf "*** Checking shellFor works for a cabal project, multiple packages...\n" >& 2
87nix-shell $NIX_BUILD_ARGS \
88 --pure ./default.nix \
89 --argstr compiler-nix-name $GHC \
90 -A shell-for.env \
91 --run 'cd shell-for && cabal new-build all'
92echo >& 2
94printf "*** Checking shellFor works for a cabal project, single package...\n" >& 2
95nix-shell $NIX_BUILD_ARGS \
96 --pure ./default.nix \
97 --argstr compiler-nix-name $GHC \
98 -A shell-for.envPkga \
99 --run 'cd shell-for && cabal new-build --project=single.project all'
100echo >& 2
102printf "*** Checking shellFor has a working hoogle index...\n" >& 2
103nix-shell $NIX_BUILD_ARGS \
104 --pure ./default.nix \
105 --argstr compiler-nix-name $GHC \
106 -A shell-for.env \
107 --run 'hoogle ConduitT | grep Data.Conduit'
108echo >& 2
110printf "*** Checking shellFor does not depend on given packages...\n" >& 2
111drva=$(nix-instantiate ./default.nix --argstr compiler-nix-name $GHC -A shell-for.env)
112echo "-- hello" >> shell-for/pkga/PkgA.hs
113drvb=$(nix-instantiate ./default.nix --argstr compiler-nix-name $GHC -A shell-for.env)
114sed -i -e '/-- hello/d' shell-for/pkga/PkgA.hs
115if [ "$drva" != "$drvb" ]; then
116 printf "FAIL\nShell derivations\n$drva\n$drvb\n are not identical.\n" >& 2
117 exit 1
118else
119 printf "PASS\n" >& 2
120fi
122printf "*** Checking the maintainer scripts...\n" >& 2
123nix build $NIX_BUILD_ARGS --no-link --keep-going -f ../build.nix --argstr compiler-nix-name $GHC maintainer-scripts
124echo >& 2
126printf "*** Checking that plan construction works with extra Hackages...\n" >& 2
127nix build $NIX_BUILD_ARGS --no-link \
128 -f ./default.nix --argstr compiler-nix-name $GHC \
129 extra-hackage.run.project.plan-nix
130echo >& 2
132printf "*** Checking that package with extra Hackages can be build...\n" >& 2
133nix build $NIX_BUILD_ARGS --no-link \
134 -f ./default.nix --argstr compiler-nix-name $GHC \
135 extra-hackage.run.project.hsPkgs.external-package-user.components.exes.external-package-user
136echo >& 2
138printf "\n*** Finished successfully\n" >& 2