Skip to content

Add tests for benchmarks and hspec-discover #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/cabal-22/.plan.nix/project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@
components = {
"library" = { depends = [ (hsPkgs.base) ]; };
exes = { "project" = { depends = [ (hsPkgs.base) (hsPkgs.project) ]; }; };
tests = {
"unit" = {
depends = [ (hsPkgs.base) (hsPkgs.project) (hsPkgs.hspec) ];
build-tools = [
(hsPkgs.buildPackages.hspec-discover or (pkgs.buildPackages.hspec-discover))
];
};
};
benchmarks = {
"project-bench" = { depends = [ (hsPkgs.base) (hsPkgs.project) ]; };
};
};
} // rec { src = (pkgs.lib).mkDefault ../.; }
14 changes: 12 additions & 2 deletions test/cabal-22/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, mkCabalProjectPkgSet }:
{ stdenv, mkCabalProjectPkgSet, util }:

with stdenv.lib;

Expand Down Expand Up @@ -45,7 +45,17 @@ in
otool -L $sofile | grep libHSghc-prim
'') + ''
touch $out

printf "checking whether benchmark runs... " >& 2
${packages.project.components.benchmarks.project-bench}/*/project-bench

printf "checking whether tests run... " >& 2
${packages.project.components.tests.unit}/*/unit
'';

meta.platforms = platforms.all;
} // { inherit (packages) project; }
passthru = {
inherit (packages) project;
shell = util.addCabalInstall packages.project.components.all;
};
}
44 changes: 44 additions & 0 deletions test/cabal-22/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,62 @@
pkgs = hackage:
{
packages = {
"tf-random".revision = (((hackage."tf-random")."0.5").revisions).default;
"ghc-prim".revision = (((hackage."ghc-prim")."0.5.2.0").revisions).default;
"stm".revision = (((hackage."stm")."2.4.5.1").revisions).default;
"unix".revision = (((hackage."unix")."2.7.2.2").revisions).default;
"rts".revision = (((hackage."rts")."1.0").revisions).default;
"clock".revision = (((hackage."clock")."0.8").revisions).default;
"clock".flags.llvm = false;
"QuickCheck".revision = (((hackage."QuickCheck")."2.13.1").revisions).default;
"QuickCheck".flags.templatehaskell = true;
"hspec-discover".revision = (((hackage."hspec-discover")."2.7.1").revisions).default;
"deepseq".revision = (((hackage."deepseq")."1.4.3.0").revisions).default;
"random".revision = (((hackage."random")."1.1").revisions).default;
"splitmix".revision = (((hackage."splitmix")."0.0.2").revisions).default;
"HUnit".revision = (((hackage."HUnit")."1.6.0.0").revisions).default;
"directory".revision = (((hackage."directory")."1.3.1.5").revisions).default;
"template-haskell".revision = (((hackage."template-haskell")."2.13.0.0").revisions).default;
"hspec-expectations".revision = (((hackage."hspec-expectations")."0.8.2").revisions).default;
"call-stack".revision = (((hackage."call-stack")."0.1.0").revisions).default;
"primitive".revision = (((hackage."primitive")."0.7.0.0").revisions).default;
"ansi-terminal".revision = (((hackage."ansi-terminal")."0.9.1").revisions).default;
"ansi-terminal".flags.example = false;
"containers".revision = (((hackage."containers")."0.5.11.0").revisions).default;
"bytestring".revision = (((hackage."bytestring")."0.10.8.2").revisions).default;
"setenv".revision = (((hackage."setenv")."0.1.1.3").revisions).default;
"base".revision = (((hackage."base")."4.11.1.0").revisions).default;
"hspec".revision = (((hackage."hspec")."2.7.1").revisions).default;
"time".revision = (((hackage."time")."1.8.0.2").revisions).default;
"transformers".revision = (((hackage."transformers")."0.5.6.2").revisions).default;
"quickcheck-io".revision = (((hackage."quickcheck-io")."0.2.0").revisions).default;
"colour".revision = (((hackage."colour")."2.3.5").revisions).default;
"filepath".revision = (((hackage."filepath")."1.4.2").revisions).default;
"hspec-core".revision = (((hackage."hspec-core")."2.7.1").revisions).default;
"pretty".revision = (((hackage."pretty")."1.1.3.6").revisions).default;
"ghc-boot-th".revision = (((hackage."ghc-boot-th")."8.4.4").revisions).default;
"array".revision = (((hackage."array")."0.5.2.0").revisions).default;
"integer-gmp".revision = (((hackage."integer-gmp")."1.0.2.0").revisions).default;
};
compiler = {
version = "8.4.4";
nix-name = "ghc844";
packages = {
"ghc-prim" = "0.5.2.0";
"stm" = "2.4.5.1";
"unix" = "2.7.2.2";
"rts" = "1.0";
"deepseq" = "1.4.3.0";
"directory" = "1.3.1.5";
"template-haskell" = "2.13.0.0";
"containers" = "0.5.11.0";
"bytestring" = "0.10.8.2";
"base" = "4.11.1.0";
"time" = "1.8.0.2";
"filepath" = "1.4.2";
"pretty" = "1.1.3.6";
"ghc-boot-th" = "8.4.4";
"array" = "0.5.2.0";
"integer-gmp" = "1.0.2.0";
};
};
Expand Down
24 changes: 19 additions & 5 deletions test/cabal-22/project.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@ maintainer: [email protected]

library
exposed-modules: Lib
-- other-modules:
-- other-extensions:
build-depends: base ^>=4.11.1.0
hs-source-dirs: lib
default-language: Haskell2010

executable project
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base ^>=4.11.1.0
, project
-- hs-source-dirs:
default-language: Haskell2010

benchmark project-bench
type: exitcode-stdio-1.0
main-is: Main.hs
build-depends: base ^>=4.11.1.0
, project
default-language: Haskell2010
ghc-options: -threaded -rtsopts -Wall -O2

test-suite unit
type: exitcode-stdio-1.0
main-is: Main.hs
build-depends: base ^>=4.11.1.0
, project
, hspec
build-tools: hspec-discover
other-modules: LibSpec
default-language: Haskell2010
hs-source-dirs: test
11 changes: 11 additions & 0 deletions test/cabal-22/project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@
components = {
"library" = { depends = [ (hsPkgs.base) ]; };
exes = { "project" = { depends = [ (hsPkgs.base) (hsPkgs.project) ]; }; };
tests = {
"unit" = {
depends = [ (hsPkgs.base) (hsPkgs.project) (hsPkgs.hspec) ];
build-tools = [
(hsPkgs.buildPackages.hspec-discover or (pkgs.buildPackages.hspec-discover))
];
};
};
benchmarks = {
"project-bench" = { depends = [ (hsPkgs.base) (hsPkgs.project) ]; };
};
};
} // rec { src = (pkgs.lib).mkDefault ./.; }
11 changes: 11 additions & 0 deletions test/cabal-22/test/LibSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module LibSpec
( spec
) where

import Test.Hspec
import Lib

spec :: Spec
spec = describe "Lib message" $
it "should greet appropriately" $
message `shouldContain` "Hello"
1 change: 1 addition & 0 deletions test/cabal-22/test/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
2 changes: 1 addition & 1 deletion test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ in pkgs.recurseIntoAttrs {
cabal-simple = haskell.callPackage ./cabal-simple { inherit util; };
cabal-simple-prof = haskell.callPackage ./cabal-simple-prof { inherit util; };
cabal-sublib = haskell.callPackage ./cabal-sublib { inherit util; };
cabal-22 = haskell.callPackage ./cabal-22 {};
cabal-22 = haskell.callPackage ./cabal-22 { inherit util; };
with-packages = haskell.callPackage ./with-packages { inherit util; };
builder-haddock = haskell.callPackage ./builder-haddock {};
stack-simple = haskell.callPackage ./stack-simple {};
Expand Down
2 changes: 1 addition & 1 deletion test/shell-for/pkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,4 @@
{
packages = { pkga = ./.plan.nix/pkga.nix; pkgb = ./.plan.nix/pkgb.nix; };
};
}
}
9 changes: 9 additions & 0 deletions test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ nix-shell $NIX_BUILD_ARGS \
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && cabal new-build'
echo >& 2

printf "*** Checking that a nix-shell works for a project with test-suite build-tools and benchmarks...\n" >& 2
printf "!!! This is expected to fail until https://github.com/input-output-hk/haskell.nix/issues/231 is resolved! \n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
-A cabal-22.shell \
--run 'cd cabal-22 && cabal new-build all --enable-tests --enable-benchmarks' \
|| true
echo >& 2

printf "*** Checking that a nix-shell works for a multi-target project...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
Expand Down