mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-10-10 14:48:13 +03:00
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.
This commit is contained in:
parent
70f01c2029
commit
33e8d115f7
@ -30,6 +30,7 @@ executable cabal-simple
|
|||||||
-- other-modules:
|
-- other-modules:
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
build-depends: base >=4.11 && <4.12
|
build-depends: base >=4.11 && <4.12
|
||||||
|
, cabal-simple
|
||||||
, extra
|
, extra
|
||||||
, optparse-applicative
|
, optparse-applicative
|
||||||
-- hs-source-dirs:
|
-- hs-source-dirs:
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
"cabal-simple" = {
|
"cabal-simple" = {
|
||||||
depends = [
|
depends = [
|
||||||
(hsPkgs.base)
|
(hsPkgs.base)
|
||||||
|
(hsPkgs.cabal-simple)
|
||||||
(hsPkgs.extra)
|
(hsPkgs.extra)
|
||||||
(hsPkgs.optparse-applicative)
|
(hsPkgs.optparse-applicative)
|
||||||
];
|
];
|
||||||
|
@ -2,11 +2,16 @@
|
|||||||
{ pkgs
|
{ pkgs
|
||||||
, haskell
|
, haskell
|
||||||
, stdenv
|
, stdenv
|
||||||
|
, util
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with stdenv.lib;
|
with stdenv.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
## steps to generate local files
|
||||||
|
# 1. cabal-to-nix cabal-simple.cabal > cabal-simple.nix
|
||||||
|
# 2. cabal new-build
|
||||||
|
# 3. plan-to-nix ./dist-newstyle/cache/plan.json > plan.nix
|
||||||
pkgSet = haskell.mkPkgSet {
|
pkgSet = haskell.mkPkgSet {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
pkg-def = import ./plan.nix;
|
pkg-def = import ./plan.nix;
|
||||||
@ -49,9 +54,14 @@ in
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
meta.platforms = platforms.all;
|
meta.platforms = platforms.all;
|
||||||
} // { inherit (packages) cabal-simple; inherit pkgSet; }
|
|
||||||
|
|
||||||
## steps to generate local files
|
passthru = {
|
||||||
# 1. cabal-to-nix cabal-simple.cabal > cabal-simple.nix
|
inherit (packages) cabal-simple;
|
||||||
# 2. cabal new-build
|
inherit pkgSet;
|
||||||
# 3. plan-to-nix ./dist-newstyle/cache/plan.json > plan.nix
|
|
||||||
|
# Used for testing externally with nix-shell (../tests.sh).
|
||||||
|
# This just adds cabal-install to the existing shells.
|
||||||
|
test-shell = util.addCabalInstall packages.cabal-simple.components.all;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -15,10 +15,12 @@ let
|
|||||||
|
|
||||||
haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
|
haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
|
||||||
|
|
||||||
|
util = callPackage ./util.nix {};
|
||||||
|
|
||||||
in {
|
in {
|
||||||
cabal-simple = callPackage ./cabal-simple { inherit haskell; };
|
cabal-simple = callPackage ./cabal-simple { inherit haskell util; };
|
||||||
cabal-22 = callPackage ./cabal-22 { inherit haskell; };
|
cabal-22 = callPackage ./cabal-22 { inherit haskell; };
|
||||||
with-packages = callPackage ./with-packages { inherit haskell; };
|
with-packages = callPackage ./with-packages { inherit haskell util; };
|
||||||
|
|
||||||
# Run unit tests with: nix-instantiate --eval --strict -A unit
|
# Run unit tests with: nix-instantiate --eval --strict -A unit
|
||||||
# An empty list means success.
|
# An empty list means success.
|
||||||
|
@ -43,4 +43,11 @@ nix-shell $NIX_BUILD_ARGS \
|
|||||||
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
|
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
|
||||||
echo >& 2
|
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 && rm -rf dist-newstyle .ghc-environment* && cabal new-build'
|
||||||
|
echo >& 2
|
||||||
|
|
||||||
printf "\n*** Finished successfully\n" >& 2
|
printf "\n*** Finished successfully\n" >& 2
|
||||||
|
8
test/util.nix
Normal file
8
test/util.nix
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{ cabal-install }:
|
||||||
|
|
||||||
|
{
|
||||||
|
# Add cabal as a buildInput for a haskell derivation. Useful for nix-shell.
|
||||||
|
addCabalInstall = drv: drv.overrideAttrs (oldAttrs: {
|
||||||
|
buildInputs = (oldAttrs.buildInputs or []) ++ [ cabal-install ];
|
||||||
|
});
|
||||||
|
}
|
@ -1,9 +1,11 @@
|
|||||||
{ pkgs
|
{ pkgs
|
||||||
, haskell
|
, haskell
|
||||||
, stdenv
|
, stdenv
|
||||||
|
, util
|
||||||
}:
|
}:
|
||||||
|
|
||||||
with stdenv.lib;
|
with stdenv.lib;
|
||||||
|
with util;
|
||||||
|
|
||||||
let
|
let
|
||||||
pkgSet = haskell.mkPkgSet {
|
pkgSet = haskell.mkPkgSet {
|
||||||
@ -34,22 +36,32 @@ let
|
|||||||
|
|
||||||
packages = pkgSet.config.hsPkgs;
|
packages = pkgSet.config.hsPkgs;
|
||||||
|
|
||||||
# Add cabal as a buildInput for a haskell derivation. Useful for nix-shell.
|
package = packages.test-with-packages;
|
||||||
addCabalInstall = drv: drv.overrideAttrs (oldAttrs: {
|
inherit (package.components) library;
|
||||||
buildInputs = (oldAttrs.buildInputs or []) ++ [ pkgs.cabal-install ];
|
|
||||||
});
|
pkgId = p: "${p.identifier.name}-${p.identifier.version}";
|
||||||
|
showDepends = component: concatMapStringsSep " " pkgId component.depends;
|
||||||
|
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "with-packages-test";
|
name = "with-packages-test";
|
||||||
|
libraryDepends = showDepends pkgSet.config.packages.test-with-packages.components.library;
|
||||||
|
allDepends = showDepends pkgSet.config.packages.test-with-packages.components.all;
|
||||||
|
|
||||||
buildCommand = let
|
buildCommand = ''
|
||||||
package = packages.test-with-packages;
|
|
||||||
inherit (package.components) library;
|
|
||||||
in ''
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# test with-packages
|
# test with-packages
|
||||||
|
|
||||||
|
printf "checking merging of the 'all' component depends ... " >& 2
|
||||||
|
if [ -n "$libraryDepends" -a "$libraryDepends" = "$allDepends" ]; then
|
||||||
|
echo "PASS" >& 2
|
||||||
|
else
|
||||||
|
echo "FAIL" >& 2
|
||||||
|
echo "libraryDepends = $libraryDepends"
|
||||||
|
echo "allDepends = $allDepends"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
printf "checking that the 'all' component works... " >& 2
|
printf "checking that the 'all' component works... " >& 2
|
||||||
echo ${package.components.all} >& 2
|
echo ${package.components.all} >& 2
|
||||||
|
|
||||||
@ -62,7 +74,7 @@ in
|
|||||||
|
|
||||||
printf "checking that components.library.env has the dependencies... " >& 2
|
printf "checking that components.library.env has the dependencies... " >& 2
|
||||||
${library.env}/bin/runghc ${./Point.hs}
|
${library.env}/bin/runghc ${./Point.hs}
|
||||||
# echo >& 2
|
echo >& 2
|
||||||
|
|
||||||
touch $out
|
touch $out
|
||||||
'';
|
'';
|
||||||
|
Loading…
Reference in New Issue
Block a user