on iko/ghcjs-patch-master help sign in
tests: Add more tests for "all" component merging

- Make the cabal-simple executable depend on the library component -- a better exercise for the merged all component build. - Test building cabal-simple with "cabal new-build" in nix-shell. - Check the contents of components.all.depends for the with-packages test.

commit33e8d115f75b7c288a42c1d3efbfc77744aa63cd authorRodney Lorrimar <rodney.lorrimar@iohk.io> dateMon 4 Feb 2019, 13:49 (8 years ago) parent70f01c2
7 files changed+57−16
test/cabal-simple/cabal-simple.cabal+1 test/cabal-simple/cabal-simple.nix+1 test/cabal-simple/default.nix+15−5 test/default.nix+4−2 test/tests.sh+7 test/util.nix+8 test/with-packages/default.nix+21−9
test/cabal-simple/cabal-simple.cabal+1
@@ -30,6 +30,7 @@ executable cabal-simple
3030 -- other-modules:
3131 -- other-extensions:
3232 build-depends: base >=4.11 && <4.12
33+ , cabal-simple
3334 , extra
3435 , optparse-applicative
3536 -- hs-source-dirs:
test/cabal-simple/cabal-simple.nix+1
@@ -36,6 +36,7 @@
3636 "cabal-simple" = {
3737 depends = [
3838 (hsPkgs.base)
39+ (hsPkgs.cabal-simple)
3940 (hsPkgs.extra)
4041 (hsPkgs.optparse-applicative)
4142 ];
test/cabal-simple/default.nix+15−5
@@ -2,11 +2,16 @@
22{ pkgs
33, haskell
44, stdenv
5+, util
56}:
67
78with stdenv.lib;
89
910let
11+ ## steps to generate local files
12+ # 1. cabal-to-nix cabal-simple.cabal > cabal-simple.nix
13+ # 2. cabal new-build
14+ # 3. plan-to-nix ./dist-newstyle/cache/plan.json > plan.nix
1015 pkgSet = haskell.mkPkgSet {
1116 inherit pkgs;
1217 pkg-def = import ./plan.nix;
@@ -49,9 +54,14 @@ in
4954 '';
5055
5156 meta.platforms = platforms.all;
52−} // { inherit (packages) cabal-simple; inherit pkgSet; }
5357
54−## steps to generate local files
55−# 1. cabal-to-nix cabal-simple.cabal > cabal-simple.nix
56−# 2. cabal new-build
57−# 3. plan-to-nix ./dist-newstyle/cache/plan.json > plan.nix
58+ passthru = {
59+ inherit (packages) cabal-simple;
60+ inherit pkgSet;
61+
62+ # Used for testing externally with nix-shell (../tests.sh).
63+ # This just adds cabal-install to the existing shells.
64+ test-shell = util.addCabalInstall packages.cabal-simple.components.all;
65+
66+ };
67+}
test/default.nix+4−2
@@ -15,10 +15,12 @@ let
1515
1616 haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
1717
18+ util = callPackage ./util.nix {};
19+
1820in {
19− cabal-simple = callPackage ./cabal-simple { inherit haskell; };
21+ cabal-simple = callPackage ./cabal-simple { inherit haskell util; };
2022 cabal-22 = callPackage ./cabal-22 { inherit haskell; };
21− with-packages = callPackage ./with-packages { inherit haskell; };
23+ with-packages = callPackage ./with-packages { inherit haskell util; };
2224
2325 # Run unit tests with: nix-instantiate --eval --strict -A unit
2426 # An empty list means success.
test/tests.sh+7
@@ -43,4 +43,11 @@ nix-shell $NIX_BUILD_ARGS \
4343 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
4444echo >& 2
4545
46+printf "*** Checking that a nix-shell works for a multi-target project...\n" >& 2
47+nix-shell $NIX_BUILD_ARGS \
48+ --pure ./default.nix \
49+ -A cabal-simple.test-shell \
50+ --run 'cd cabal-simple && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
51+echo >& 2
52+
4653printf "\n*** Finished successfully\n" >& 2
test/util.nixnew file+8
@@ -0,0 +1,8 @@
1+{ cabal-install }:
2+
3+{
4+ # Add cabal as a buildInput for a haskell derivation. Useful for nix-shell.
5+ addCabalInstall = drv: drv.overrideAttrs (oldAttrs: {
6+ buildInputs = (oldAttrs.buildInputs or []) ++ [ cabal-install ];
7+ });
8+}
test/with-packages/default.nix+21−9
@@ -1,9 +1,11 @@
11{ pkgs
22, haskell
33, stdenv
4+, util
45}:
56
67with stdenv.lib;
8+with util;
79
810let
911 pkgSet = haskell.mkPkgSet {
@@ -34,22 +36,32 @@ let
3436
3537 packages = pkgSet.config.hsPkgs;
3638
37− # Add cabal as a buildInput for a haskell derivation. Useful for nix-shell.
38− addCabalInstall = drv: drv.overrideAttrs (oldAttrs: {
39− buildInputs = (oldAttrs.buildInputs or []) ++ [ pkgs.cabal-install ];
40− });
39+ package = packages.test-with-packages;
40+ inherit (package.components) library;
41+
42+ pkgId = p: "${p.identifier.name}-${p.identifier.version}";
43+ showDepends = component: concatMapStringsSep " " pkgId component.depends;
4144
4245in
4346 stdenv.mkDerivation {
4447 name = "with-packages-test";
48+ libraryDepends = showDepends pkgSet.config.packages.test-with-packages.components.library;
49+ allDepends = showDepends pkgSet.config.packages.test-with-packages.components.all;
4550
46− buildCommand = let
47− package = packages.test-with-packages;
48− inherit (package.components) library;
49− in ''
51+ buildCommand = ''
5052 ########################################################################
5153 # test with-packages
5254
55+ printf "checking merging of the 'all' component depends ... " >& 2
56+ if [ -n "$libraryDepends" -a "$libraryDepends" = "$allDepends" ]; then
57+ echo "PASS" >& 2
58+ else
59+ echo "FAIL" >& 2
60+ echo "libraryDepends = $libraryDepends"
61+ echo "allDepends = $allDepends"
62+ exit 1
63+ fi
64+
5365 printf "checking that the 'all' component works... " >& 2
5466 echo ${package.components.all} >& 2
5567
@@ -62,7 +74,7 @@ in
6274
6375 printf "checking that components.library.env has the dependencies... " >& 2
6476 ${library.env}/bin/runghc ${./Point.hs}
65− # echo >& 2
77+ echo >& 2
6678
6779 touch $out
6880 '';