Skip to content

Commit 75db8c4

Browse files
committed
Add tests for extra-hackages functionality
1 parent 1f2b87d commit 75db8c4

22 files changed

+340
-1
lines changed

overlays/haskell.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@ self: super: {
201201
dotCabal = { index-state, sha256, cabal-install, extra-hackage-tarballs ? [], ... }@args:
202202
let
203203
allTarballs = [ (hackageTarball args) ] ++ extra-hackage-tarballs;
204+
allNames = self.lib.concatMapStringsSep "-" (tarball: tarball.name) allTarballs;
205+
# Main Hackage index-state is embedded in its name and thus will propagate to
206+
# dotCabalName anyway.
207+
dotCabalName = "dot-cabal-" + allNames;
204208
in
205-
self.runCommand "dot-cabal-at-${builtins.replaceStrings [":"] [""] index-state}" { nativeBuildInputs = [ cabal-install ]; } ''
209+
self.runCommand dotCabalName { nativeBuildInputs = [ cabal-install ]; } ''
206210
mkdir -p $out/.cabal
207211
cat <<EOF > $out/.cabal/config
208212
${self.lib.concatStrings (

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ let
175175
exe-only = callTest ./exe-only { inherit util; };
176176
stack-source-repo = callTest ./stack-source-repo {};
177177
lookup-sha256 = callTest ./lookup-sha256 {};
178+
extra-hackage = callTest ./extra-hackage {};
178179

179180
unit = unitTests;
180181
};

test/extra-hackage/01-index.tar.gz

747 Bytes
Binary file not shown.

test/extra-hackage/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Tests for extra Hackage functionality
2+
3+
This directory contains two packages, `external-package-demo` and `external-package-user`, the
4+
second one depends on the first one. Both packages were created with `cabal init`.
5+
6+
`external-package-demo` was uploaded to local Hackage at `localhost` and `01-index.tar.gz` from that
7+
Hackage was downloaded to this directory. Then the index file was processed with `hackage-to-nix`,
8+
the result is in `hackage/` directory.
9+
10+
The tests check that `cabalProject'` is able to construct plan with dependencies from extra Hackage
11+
and then build the package itself.

test/extra-hackage/default.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{ cabalProject', testSrc }:
2+
3+
let
4+
5+
hackage = import ./hackage;
6+
7+
tarball = {
8+
name = "extra-hackage-demo";
9+
index = ./01-index.tar.gz;
10+
};
11+
12+
demo-src = ./external-package-demo-0.1.0.0.tar.gz;
13+
14+
project = cabalProject' {
15+
src = testSrc "extra-hackage/external-package-user";
16+
17+
extra-hackages = [ hackage ];
18+
extra-hackage-tarballs = [ tarball ];
19+
20+
modules = [
21+
# To prevent nix-build from trying to download it from the
22+
# actual Hackage.
23+
{ packages.external-package-demo.src = demo-src; }
24+
];
25+
};
26+
27+
in
28+
project
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for external-package-demo
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Main where
2+
3+
import qualified MyLib (someFunc)
4+
5+
main :: IO ()
6+
main = do
7+
putStrLn "Hello, Haskell!"
8+
MyLib.someFunc
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLib (someFunc) where
2+
3+
someFunc :: IO ()
4+
someFunc = putStrLn "someFunc"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

0 commit comments

Comments
 (0)