on iko/ghcjs-patch-master help sign in
tests: Add more tests for "all" component merging
33e8d11Rodney Lorrimar
test/cabal-simple/cabal-simple.cabal+1
@@ -30,6 +30,7 @@ executable cabal-simple
30 -- other-modules:
30 -- other-modules:
31 -- other-extensions:
31 -- other-extensions:
32 build-depends: base >=4.11 && <4.12
32 build-depends: base >=4.11 && <4.12
33+ , cabal-simple
33 , extra
34 , extra
34 , optparse-applicative
35 , optparse-applicative
35 -- hs-source-dirs:
36 -- hs-source-dirs:
test/cabal-simple/cabal-simple.nix+1
@@ -36,6 +36,7 @@
36 "cabal-simple" = {
36 "cabal-simple" = {
37 depends = [
37 depends = [
38 (hsPkgs.base)
38 (hsPkgs.base)
39+ (hsPkgs.cabal-simple)
39 (hsPkgs.extra)
40 (hsPkgs.extra)
40 (hsPkgs.optparse-applicative)
41 (hsPkgs.optparse-applicative)
41 ];
42 ];
test/cabal-simple/default.nix+15−5
@@ -2,11 +2,16 @@
2{ pkgs
2{ pkgs
3, haskell
3, haskell
4, stdenv
4, stdenv
5+, util
5}:
6}:
6
7
7with stdenv.lib;
8with stdenv.lib;
8
9
9let
10let
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
10 pkgSet = haskell.mkPkgSet {
15 pkgSet = haskell.mkPkgSet {
11 inherit pkgs;
16 inherit pkgs;
12 pkg-def = import ./plan.nix;
17 pkg-def = import ./plan.nix;
@@ -49,9 +54,14 @@ in
49 '';
54 '';
50
55
51 meta.platforms = platforms.all;
56 meta.platforms = platforms.all;
52−} // { inherit (packages) cabal-simple; inherit pkgSet; }
53
57
54−## steps to generate local files
58+ passthru = {
55−# 1. cabal-to-nix cabal-simple.cabal > cabal-simple.nix
59+ inherit (packages) cabal-simple;
56−# 2. cabal new-build
60+ inherit pkgSet;
57−# 3. plan-to-nix ./dist-newstyle/cache/plan.json > plan.nix
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
15
15
16 haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
16 haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
17
17
18+ util = callPackage ./util.nix {};
19+
18in {
20in {
19− cabal-simple = callPackage ./cabal-simple { inherit haskell; };
21+ cabal-simple = callPackage ./cabal-simple { inherit haskell util; };
20 cabal-22 = callPackage ./cabal-22 { inherit haskell; };
22 cabal-22 = callPackage ./cabal-22 { inherit haskell; };
21− with-packages = callPackage ./with-packages { inherit haskell; };
23+ with-packages = callPackage ./with-packages { inherit haskell util; };
22
24
23 # Run unit tests with: nix-instantiate --eval --strict -A unit
25 # Run unit tests with: nix-instantiate --eval --strict -A unit
24 # An empty list means success.
26 # An empty list means success.
test/tests.sh+7
@@ -43,4 +43,11 @@ nix-shell $NIX_BUILD_ARGS \
43 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
43 --run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
44echo >& 2
44echo >& 2
45
45
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+
46printf "\n*** Finished successfully\n" >& 2
53printf "\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 @@
1{ pkgs
1{ pkgs
2, haskell
2, haskell
3, stdenv
3, stdenv
4+, util
4}:
5}:
5
6
6with stdenv.lib;
7with stdenv.lib;
8+with util;
7
9
8let
10let
9 pkgSet = haskell.mkPkgSet {
11 pkgSet = haskell.mkPkgSet {
@@ -34,22 +36,32 @@ let
34
36
35 packages = pkgSet.config.hsPkgs;
37 packages = pkgSet.config.hsPkgs;
36
38
37− # Add cabal as a buildInput for a haskell derivation. Useful for nix-shell.
39+ package = packages.test-with-packages;
38− addCabalInstall = drv: drv.overrideAttrs (oldAttrs: {
40+ inherit (package.components) library;
39− buildInputs = (oldAttrs.buildInputs or []) ++ [ pkgs.cabal-install ];
41+
40− });
42+ pkgId = p: "${p.identifier.name}-${p.identifier.version}";
43+ showDepends = component: concatMapStringsSep " " pkgId component.depends;
41
44
42in
45in
43 stdenv.mkDerivation {
46 stdenv.mkDerivation {
44 name = "with-packages-test";
47 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;
45
50
46− buildCommand = let
51+ buildCommand = ''
47− package = packages.test-with-packages;
48− inherit (package.components) library;
49− in ''
50 ########################################################################
52 ########################################################################
51 # test with-packages
53 # test with-packages
52
54
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+
53 printf "checking that the 'all' component works... " >& 2
65 printf "checking that the 'all' component works... " >& 2
54 echo ${package.components.all} >& 2
66 echo ${package.components.all} >& 2
55
67
@@ -62,7 +74,7 @@ in
62
74
63 printf "checking that components.library.env has the dependencies... " >& 2
75 printf "checking that components.library.env has the dependencies... " >& 2
64 ${library.env}/bin/runghc ${./Point.hs}
76 ${library.env}/bin/runghc ${./Point.hs}
65− # echo >& 2
77+ echo >& 2
66
78
67 touch $out
79 touch $out
68 '';
80 '';