Add some test cases for the component builder

This commit is contained in:
Rodney Lorrimar 2018-12-20 11:59:49 +10:00 committed by Moritz Angermann
parent 9a5101e46f
commit a384c9a8a5
15 changed files with 327 additions and 0 deletions

6
test/README.md Normal file
View File

@ -0,0 +1,6 @@
### Haskell infrastructure test cases
To execute the test cases, build from this directory:
nix-build --no-out-link default.nix

6
test/cabal-22/Main.hs Normal file
View File

@ -0,0 +1,6 @@
module Main where
import Lib (message)
main :: IO ()
main = putStrLn message

2
test/cabal-22/Setup.hs Normal file
View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

50
test/cabal-22/default.nix Normal file
View File

@ -0,0 +1,50 @@
{ pkgs
, haskell
, stdenv
}:
with stdenv.lib;
let
pkgSet = haskell.mkNewPkgSet {
inherit pkgs;
pkg-def = import ./plan.nix;
pkg-def-overlays = [
{ project = ./project.nix; }
];
modules = [ ];
};
packages = pkgSet.config.hsPkgs;
in
stdenv.mkDerivation {
name = "cabal-22-test";
buildCommand = ''
exe="${packages.project.components.exes.project}/bin/project"
size=$(command stat --format '%s' "$exe")
printf "size of executable $exe is $size. \n" >& 2
# fixme: run on target platform when cross-compiled
printf "checking whether executable runs... " >& 2
"$exe"
# fixme: linux-specific
printf "checking that executable is dynamically linked to system libraries... " >& 2
ldd "$exe" | grep libpthread
# fixme: posix-specific
printf "checking that dynamic library is produced... " >& 2
sofile=$(find "${packages.project.components.library}" | grep -e '\.so$')
echo "$sofile"
printf "checking that dynamic library is dynamically linked to base... " >& 2
ldd "$sofile" | grep libHSbase
touch $out
'';
meta.platforms = platforms.all;
} // { inherit (packages) project; }

4
test/cabal-22/lib/Lib.hs Normal file
View File

@ -0,0 +1,4 @@
module Lib (message) where
message :: String
message = "Hello, Haskell!"

19
test/cabal-22/plan.nix Normal file
View File

@ -0,0 +1,19 @@
hackage:
{
packages = {
"ghc-prim".revision = hackage."ghc-prim"."0.5.2.0".revisions.default;
"rts".revision = hackage."rts"."1.0".revisions.default;
"base".revision = hackage."base"."4.11.1.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";
"rts" = "1.0";
"base" = "4.11.1.0";
"integer-gmp" = "1.0.2.0";
};
};
}

View File

@ -0,0 +1,31 @@
cabal-version: 2.2
-- Initial package description 'project.cabal' generated by 'cabal init'.
-- For further documentation, see http://haskell.org/cabal/users-guide/
name: project
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
license: NONE
author: Rodney Lorrimar
maintainer: rodney.lorrimar@iohk.io
-- copyright:
-- category:
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

41
test/cabal-22/project.nix Normal file
View File

@ -0,0 +1,41 @@
{ system
, compiler
, flags
, pkgs
, hsPkgs
, pkgconfPkgs
, ... }:
{
flags = {};
package = {
specVersion = "2.2";
identifier = {
name = "project";
version = "0.1.0.0";
};
license = "NONE";
copyright = "";
maintainer = "rodney.lorrimar@iohk.io";
author = "Rodney Lorrimar";
homepage = "";
url = "";
synopsis = "";
description = "";
buildType = "Simple";
};
components = {
"library" = {
depends = [ (hsPkgs.base) ];
};
exes = {
"project" = {
depends = [
(hsPkgs.base)
(hsPkgs.project)
];
};
};
};
} // rec {
src = pkgs.lib.mkDefault ./.;
}

View File

@ -0,0 +1,4 @@
module Main where
main :: IO ()
main = putStrLn "Hello, Haskell!"

View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@ -0,0 +1,31 @@
cabal-version: >=1.10
-- Initial package description 'cabal-simple.cabal' generated by 'cabal
-- init'. For further documentation, see
-- http://haskell.org/cabal/users-guide/
name: cabal-simple
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
license: PublicDomain
author: Rodney Lorrimar
maintainer: rodney.lorrimar@iohk.io
-- category:
build-type: Simple
library
-- exposed-modules:
-- other-modules:
-- other-extensions:
build-depends: base >=4.11 && <4.12
-- hs-source-dirs:
default-language: Haskell2010
executable cabal-simple
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.11 && <4.12
-- hs-source-dirs:
default-language: Haskell2010

View File

@ -0,0 +1,38 @@
{ system
, compiler
, flags
, pkgs
, hsPkgs
, pkgconfPkgs
, ... }:
{
flags = {};
package = {
specVersion = "1.10";
identifier = {
name = "cabal-simple";
version = "0.1.0.0";
};
license = "LicenseRef-PublicDomain";
copyright = "";
maintainer = "rodney.lorrimar@iohk.io";
author = "Rodney Lorrimar";
homepage = "";
url = "";
synopsis = "";
description = "";
buildType = "Simple";
};
components = {
"library" = {
depends = [ (hsPkgs.base) ];
};
exes = {
"cabal-simple" = {
depends = [ (hsPkgs.base) ];
};
};
};
} // rec {
src = pkgs.lib.mkDefault ./.;
}

View File

@ -0,0 +1,49 @@
# Test a package set
{ pkgs
, haskell
, stdenv
}:
with stdenv.lib;
let
pkgSet = haskell.mkNewPkgSet {
inherit pkgs;
pkg-def = import ./plan.nix;
pkg-def-overlays = [
{ cabal-simple = ./cabal-simple.nix;
}
];
modules = [ ];
};
packages = pkgSet.config.hsPkgs;
in
stdenv.mkDerivation {
name = "cabal-simple-test";
buildCommand = ''
exe="${packages.cabal-simple.components.exes.cabal-simple}/bin/cabal-simple"
size=$(command stat --format '%s' "$exe")
printf "size of executable $exe is $size. \n" >& 2
# fixme: run on target platform when cross-compiled
printf "checking whether executable runs... " >& 2
$exe
# fixme: linux-specific
printf "checking that executable is dynamically linked to system libraries... " >& 2
ldd $exe | grep libpthread
touch $out
'';
meta.platforms = platforms.all;
} // { inherit (packages) cabal-simple; }
## 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

View File

@ -0,0 +1,19 @@
hackage:
{
packages = {
"ghc-prim".revision = hackage."ghc-prim"."0.5.2.0".revisions.default;
"rts".revision = hackage."rts"."1.0".revisions.default;
"base".revision = hackage."base"."4.11.1.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";
"rts" = "1.0";
"base" = "4.11.1.0";
"integer-gmp" = "1.0.2.0";
};
};
}

25
test/default.nix Normal file
View File

@ -0,0 +1,25 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
# all packages from hackage as nix expressions
hackage = import (fetchFromGitHub { owner = "angerman";
repo = "hackage.nix";
rev = "66c28064da46525711722b75b4adb2ac878897d3";
sha256 = "12ffzzjgirwzha3ngxbniccgn19406iryxspq19kgi4kz9lz6bpr";
name = "hackage-exprs-source"; });
# The new Haskell infra applied to nix representation of Hackage
haskell = import ../. hackage;
in {
cabal-simple = callPackage ./cabal-simple { inherit haskell; };
cabal-22 = callPackage ./cabal-22 { inherit haskell; };
}
## possible test cases
# 1. fully static linking
# 2. presence of haddock
# 3. cabal 2.4 stuff
# 4. multiple libraries in a cabal project