Skip to content

Commit ec0c59e

Browse files
authored
Support for packages with only tests (#1732)
* Support for packages with only tests Fixes #362 * Fix for ghcjs
1 parent eb719db commit ec0c59e

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

builder/comp-builder.nix

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,13 @@ let
454454
target-pkg-and-db = "${ghc.targetPrefix}ghc-pkg -v0 --package-db $out/package.conf.d";
455455
in ''
456456
runHook preInstall
457-
$SETUP_HS copy ${lib.concatStringsSep " " (
458-
setupInstallFlags
459-
++ lib.optional configureAllComponents
460-
(haskellLib.componentTarget componentId)
461-
)}
457+
${ # `Setup copy` does not install tests and benchmarks.
458+
lib.optionalString (!haskellLib.isTest componentId && !haskellLib.isBenchmark componentId) ''
459+
$SETUP_HS copy ${lib.concatStringsSep " " (
460+
setupInstallFlags
461+
++ lib.optional configureAllComponents
462+
(haskellLib.componentTarget componentId)
463+
)}''}
462464
${lib.optionalString (haskellLib.isLibrary componentId) ''
463465
$SETUP_HS register --gen-pkg-config=${name}.conf
464466
${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
@@ -512,7 +514,7 @@ let
512514
if [ -f ${testExecutable} ]; then
513515
mkdir -p $(dirname $out/bin/${exeName})
514516
${if stdenv.hostPlatform.isGhcjs then ''
515-
cat <(echo \#!${lib.getBin buildPackages.nodejs-12_x}/bin/node) ${testExecutable} >| $out/bin/${exeName}
517+
cat <(echo \#!${lib.getBin buildPackages.nodejs-18_x}/bin/node) ${testExecutable} >| $out/bin/${exeName}
516518
chmod +x $out/bin/${exeName}
517519
'' else ''
518520
cp -r ${testExecutable} $(dirname $out/bin/${exeName})

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ let
215215
exe-lib-dlls = callTest ./exe-lib-dlls { inherit util; };
216216
ca-derivations = callTest ./ca-derivations { inherit CADerivationsEnabled; };
217217
ca-derivations-include = callTest ./ca-derivations-include { inherit CADerivationsEnabled; };
218+
test-only = callTest ./test-only { inherit util; };
218219

219220
unit = unitTests;
220221
};

test/test-only/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Main where
2+
main = return ()

test/test-only/cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .

test/test-only/default.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{ stdenv, lib, util, project', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages }:
2+
3+
with lib;
4+
5+
let
6+
project = project' {
7+
inherit compiler-nix-name evalPackages;
8+
src = testSrc "test-only";
9+
};
10+
11+
in recurseIntoAttrs {
12+
ifdInputs = {
13+
inherit (project) plan-nix;
14+
};
15+
16+
run = project.hsPkgs.test-only.checks.my-test;
17+
}

test/test-only/test-only.cabal

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cabal-version: 1.24
2+
name: test-only
3+
version: 1
4+
build-type: Simple
5+
test-suite my-test
6+
type: exitcode-stdio-1.0
7+
main-is: Main.hs
8+
build-depends: base

0 commit comments

Comments
 (0)