summaryrefslogtreecommitdiff
path: root/pkgs/test/haskell
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/test/haskell')
-rw-r--r--pkgs/test/haskell/default.nix7
-rw-r--r--pkgs/test/haskell/documentationTarball/default.nix17
-rw-r--r--pkgs/test/haskell/setBuildTarget/Bar.hs4
-rw-r--r--pkgs/test/haskell/setBuildTarget/Foo.hs4
-rw-r--r--pkgs/test/haskell/setBuildTarget/Setup.hs2
-rw-r--r--pkgs/test/haskell/setBuildTarget/default.nix38
-rw-r--r--pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal16
-rw-r--r--pkgs/test/haskell/shellFor/default.nix33
8 files changed, 121 insertions, 0 deletions
diff --git a/pkgs/test/haskell/default.nix b/pkgs/test/haskell/default.nix
new file mode 100644
index 000000000000..eb389f4051f8
--- /dev/null
+++ b/pkgs/test/haskell/default.nix
@@ -0,0 +1,7 @@
+{ lib, callPackage }:
+
+lib.recurseIntoAttrs {
+ shellFor = callPackage ./shellFor { };
+ documentationTarball = callPackage ./documentationTarball { };
+ setBuildTarget = callPackage ./setBuildTarget { };
+}
diff --git a/pkgs/test/haskell/documentationTarball/default.nix b/pkgs/test/haskell/documentationTarball/default.nix
new file mode 100644
index 000000000000..aec3dc41f268
--- /dev/null
+++ b/pkgs/test/haskell/documentationTarball/default.nix
@@ -0,0 +1,17 @@
+{ pkgs, haskellPackages }:
+
+let
+ drv = haskellPackages.vector;
+ docs = pkgs.haskell.lib.documentationTarball drv;
+
+in pkgs.runCommand "test haskell.lib.documentationTarball" { } ''
+ tar xvzf "${docs}/${drv.name}-docs.tar.gz"
+
+ # Check for Haddock html
+ find "${drv.name}-docs" | grep -q "Data-Vector.html"
+
+ # Check for source html
+ find "${drv.name}-docs" | grep -q "src/Data.Vector.html"
+
+ touch "$out"
+''
diff --git a/pkgs/test/haskell/setBuildTarget/Bar.hs b/pkgs/test/haskell/setBuildTarget/Bar.hs
new file mode 100644
index 000000000000..010014082c7d
--- /dev/null
+++ b/pkgs/test/haskell/setBuildTarget/Bar.hs
@@ -0,0 +1,4 @@
+module Main where
+
+main :: IO ()
+main = putStrLn "Hello, Bar!"
diff --git a/pkgs/test/haskell/setBuildTarget/Foo.hs b/pkgs/test/haskell/setBuildTarget/Foo.hs
new file mode 100644
index 000000000000..fec7bb11fe6c
--- /dev/null
+++ b/pkgs/test/haskell/setBuildTarget/Foo.hs
@@ -0,0 +1,4 @@
+module Main where
+
+main :: IO ()
+main = putStrLn "Hello, Foo!"
diff --git a/pkgs/test/haskell/setBuildTarget/Setup.hs b/pkgs/test/haskell/setBuildTarget/Setup.hs
new file mode 100644
index 000000000000..9a994af677b0
--- /dev/null
+++ b/pkgs/test/haskell/setBuildTarget/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/pkgs/test/haskell/setBuildTarget/default.nix b/pkgs/test/haskell/setBuildTarget/default.nix
new file mode 100644
index 000000000000..b1335e2a74cf
--- /dev/null
+++ b/pkgs/test/haskell/setBuildTarget/default.nix
@@ -0,0 +1,38 @@
+{ pkgs, haskellPackages }:
+
+let
+ # This can be regenerated by running `cabal2nix .` in the current directory.
+ pkgDef =
+ { mkDerivation, base, lib }:
+ mkDerivation {
+ pname = "haskell-setBuildTarget";
+ version = "0.1.0.0";
+ src = ./.;
+ isLibrary = false;
+ isExecutable = true;
+ executableHaskellDepends = [ base ];
+ license = lib.licenses.bsd3;
+ };
+
+ drv = haskellPackages.callPackage pkgDef {};
+
+ test = target: excluded:
+ let only = pkgs.haskell.lib.setBuildTarget drv target;
+ in ''
+ if [[ ! -f "${only}/bin/${target}" ]]; then
+ echo "${target} was not built"
+ exit 1
+ fi
+
+ if [[ -f "${only}/bin/${excluded}" ]]; then
+ echo "${excluded} was built, when it should not have been"
+ exit 1
+ fi
+ '';
+
+in pkgs.runCommand "test haskell.lib.setBuildTarget" {} ''
+ ${test "foo" "bar"}
+ ${test "bar" "foo"}
+ touch "$out"
+''
+
diff --git a/pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal b/pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal
new file mode 100644
index 000000000000..7395e139451c
--- /dev/null
+++ b/pkgs/test/haskell/setBuildTarget/haskell-setBuildTarget.cabal
@@ -0,0 +1,16 @@
+cabal-version: >=1.10
+name: haskell-setBuildTarget
+version: 0.1.0.0
+author: Isaac Shapira
+maintainer: fresheyeball@protonmail.com
+build-type: Simple
+
+executable foo
+ main-is: Foo.hs
+ build-depends: base
+ default-language: Haskell2010
+
+executable bar
+ main-is: Bar.hs
+ build-depends: base
+ default-language: Haskell2010
diff --git a/pkgs/test/haskell/shellFor/default.nix b/pkgs/test/haskell/shellFor/default.nix
new file mode 100644
index 000000000000..37ad2e90d89e
--- /dev/null
+++ b/pkgs/test/haskell/shellFor/default.nix
@@ -0,0 +1,33 @@
+{ lib, writeText, haskellPackages, cabal-install }:
+
+(haskellPackages.shellFor {
+ packages = p: [ p.constraints p.linear ];
+ nativeBuildInputs = [ cabal-install ];
+ phases = [ "unpackPhase" "buildPhase" "installPhase" ];
+ unpackPhase = ''
+ sourceRoot=$(pwd)/scratch
+ mkdir -p "$sourceRoot"
+ cd "$sourceRoot"
+ tar -xf ${haskellPackages.constraints.src}
+ tar -xf ${haskellPackages.linear.src}
+ cp ${writeText "cabal.project" "packages: constraints* linear*"} cabal.project
+ '';
+ buildPhase = ''
+ export HOME=$(mktemp -d)
+ mkdir -p $HOME/.cabal
+ touch $HOME/.cabal/config
+ cabal v2-build --offline --verbose constraints linear --ghc-options="-O0 -j$NIX_BUILD_CORES"
+ '';
+ installPhase = ''
+ touch $out
+ '';
+}).overrideAttrs (oldAttrs: {
+ meta =
+ let
+ oldMeta = oldAttrs.meta or {};
+ oldMaintainers = oldMeta.maintainers or [];
+ additionalMaintainers = with lib.maintainers; [ cdepillabout ];
+ allMaintainers = oldMaintainers ++ additionalMaintainers;
+ in
+ oldMeta // { maintainers = allMaintainers; };
+})