2022-05-30 14:33:35 +03:00
|
|
|
{ haskellNix ? import ../default.nix { inherit checkMaterialization; }
|
2020-07-08 13:54:01 +03:00
|
|
|
, pkgs ? import nixpkgs nixpkgsArgs
|
2021-02-22 08:27:36 +03:00
|
|
|
, nixpkgs ? haskellNix.sources.nixpkgs-unstable
|
2020-03-31 04:12:40 +03:00
|
|
|
, nixpkgsArgs ? haskellNix.nixpkgsArgs
|
2019-11-29 13:28:47 +03:00
|
|
|
, ifdLevel ? 1000
|
2020-07-08 13:54:01 +03:00
|
|
|
, compiler-nix-name
|
|
|
|
, checkMaterialization ? false
|
2019-03-20 01:39:34 +03:00
|
|
|
}:
|
2018-12-20 04:59:49 +03:00
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
|
|
|
let
|
2021-08-06 06:54:39 +03:00
|
|
|
inherit (import ../ci-lib.nix { inherit pkgs; }) dimension platformFilterGeneric filterAttrsOnlyRecursive;
|
2021-03-28 11:03:20 +03:00
|
|
|
isDisabled = d: d.meta.disabled or false;
|
|
|
|
|
2020-02-05 04:11:47 +03:00
|
|
|
# Set recurseForDerivations for both children and grand-children values in
|
|
|
|
# the input association list, but only if the key is "ifdInputs".
|
|
|
|
#
|
|
|
|
# withIfdInputs :: AttrSet -> AttrSet
|
|
|
|
#
|
|
|
|
# The values in the input attribute set must be attribute sets themselves.
|
|
|
|
#
|
|
|
|
# >>> withIfdInputs { ifdInputs = { plan-nix = { a = true; b = "hello"; }; }; cat = 2; }
|
|
|
|
# { ifdInputs = {
|
|
|
|
# plan-nix = {
|
|
|
|
# a = true;
|
|
|
|
# b = "hello";
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# cat = 2;
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# >>> withIfdInputs { dog = "hello"; }
|
|
|
|
# { dog = "hello"; }
|
|
|
|
#
|
|
|
|
# >>> withIfdInputs { }
|
|
|
|
# { }
|
|
|
|
withIfdInputs =
|
|
|
|
builtins.mapAttrs
|
|
|
|
(name: val:
|
|
|
|
if name == "ifdInputs"
|
|
|
|
then
|
|
|
|
pkgs.recurseIntoAttrs
|
|
|
|
(builtins.mapAttrs (_: v: pkgs.haskell-nix.withInputs v) val)
|
|
|
|
else val
|
|
|
|
);
|
|
|
|
|
2020-07-08 13:54:01 +03:00
|
|
|
util = import ./util.nix { cabal-install = pkgs.evalPackages.haskell-nix.cabal-install.${compiler-nix-name}; };
|
2020-02-05 04:11:47 +03:00
|
|
|
|
|
|
|
# Map the values in an association list over the withIfdInputs function.
|
|
|
|
#
|
|
|
|
# addIfdInputsToVal :: AttrSet -> AttrSet
|
|
|
|
#
|
|
|
|
# The values in the input association list must be attribute sets themselves.
|
|
|
|
addIfdInputsToVal = builtins.mapAttrs (_: val: withIfdInputs val);
|
|
|
|
|
2021-03-28 11:03:20 +03:00
|
|
|
# Keep only the attribute with the key "ifdInputs" and "meta".
|
|
|
|
# Meta is needed for `meta.disabled` to work at this level.
|
2020-02-05 04:11:47 +03:00
|
|
|
#
|
|
|
|
# filterAttrsIfdInputs :: AttrSet -> AttrSet
|
|
|
|
#
|
|
|
|
# >>> filterAttrsIfdInputs { ifdInputs = 1; foobar = 2 }
|
|
|
|
# { ifdInputs = 1 }
|
|
|
|
#
|
|
|
|
# >>> filterAttrsIfdInputs { foobar = "hello" }
|
|
|
|
# { }
|
2021-03-28 11:03:20 +03:00
|
|
|
filterAttrsIfdInputs = pkgs.lib.filterAttrs (n: _: n == "ifdInputs" || n == "meta");
|
2020-02-05 04:11:47 +03:00
|
|
|
|
|
|
|
# Remove all keys and values in a attribute set where the key
|
|
|
|
# doesn't equal "ifdInputs". Set the "recurseForDerivations"
|
|
|
|
# key in the resulting value.
|
|
|
|
#
|
|
|
|
# filterNonIfdInputsSetRecurse :: AttrSet -> AttrSet
|
|
|
|
#
|
|
|
|
# >>> filterNonIfdInputsSetRecurse { ifdInputs = 1; foobar = 2 }
|
|
|
|
# { ifdInputs = 1; recurseForDerivations = true }
|
|
|
|
#
|
|
|
|
# >>> filterNonIfdInputsSetRecurse { foobar = "hello" }
|
|
|
|
# { recurseForDerivations = true; }
|
|
|
|
filterNonIfdInputsSetRecurse = attrs:
|
|
|
|
pkgs.recurseIntoAttrs (filterAttrsIfdInputs attrs);
|
|
|
|
|
|
|
|
# Filter all out all the keys/values for child values of this attribute set
|
|
|
|
# where the key is not equal to "ifdInputs".
|
|
|
|
#
|
|
|
|
# filterNonIfdInputsValues :: AttrSet -> AttrSet
|
|
|
|
#
|
|
|
|
# The values in the input AttrSet must be attribute sets themselves.
|
|
|
|
#
|
|
|
|
# >>> filterNonIfdInputsValues { foo = { ifdInputs = 1; cat = 2; }; bar = { dog = "hello"; }; }
|
|
|
|
# { foo = {
|
|
|
|
# ifdInputs = 1;
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# bar = {
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# >>> filterNonIfdInputsValues { }
|
|
|
|
# { }
|
|
|
|
filterNonIfdInputsValues = attrs:
|
|
|
|
builtins.mapAttrs (_: d: filterNonIfdInputsSetRecurse d) attrs;
|
|
|
|
|
|
|
|
# Call filterNonIfdInputsValues on the input attribute set, but only
|
|
|
|
# if ifdLevel is less than 3. Otherwise, just return the attribute set.
|
|
|
|
#
|
|
|
|
# filterNonIfdInputsValuesLTLevel3 :: AttrSet -> AttrSet
|
|
|
|
#
|
|
|
|
# >>> filterNonIfdInputsValuesLTLevel3 2 { cabal-doctests = { ifdInputs = {...}; run = ""; }; cabal-simple = { run = ""; }; }
|
|
|
|
# { cabal-doctests = {
|
|
|
|
# ifdInputs = {...};
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# cabal-simple = {
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# >>> filterNonIfdInputsValuesLTLevel3 1000 { cabal-doctests = { ifdInputs = {...}; run = "..."; }; cabal-simple = { run = "..."; }; }
|
|
|
|
# { cabal-doctests = {
|
|
|
|
# ifdInputs = {...};
|
|
|
|
# run = "...";
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# cabal-simple = {
|
|
|
|
# run = "...";
|
|
|
|
# recurseForDerivations = true;
|
|
|
|
# };
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# >>> filterNonIfdInputsValuesLTLevel3 0 { }
|
|
|
|
# { }
|
|
|
|
filterNonIfdInputsValuesLTLevel3 = ifdLevel: attrs:
|
|
|
|
if ifdLevel < 3
|
|
|
|
then filterNonIfdInputsValues attrs
|
|
|
|
else attrs;
|
2019-01-30 08:26:54 +03:00
|
|
|
|
2020-04-20 04:27:52 +03:00
|
|
|
testSrcRoot = haskell-nix.haskellLib.cleanGit { src = ../.; subDir = "test"; };
|
|
|
|
testSrc = subDir: haskell-nix.haskellLib.cleanSourceWith { src = testSrcRoot; inherit subDir; };
|
2021-01-14 02:34:06 +03:00
|
|
|
# Use the following reproduce issues that may arise on hydra as a
|
|
|
|
# result of building a snapshot not a git repo.
|
|
|
|
# testSrcRoot = pkgs.copyPathToStore ./.;
|
|
|
|
# testSrc = subDir: testSrcRoot + "/${subDir}";
|
|
|
|
testSrcRootWithGitDir = haskell-nix.haskellLib.cleanGit { src = ../.; subDir = "test"; includeSiblings = true; keepGitDir = true; };
|
|
|
|
testSrcWithGitDir = subDir: haskell-nix.haskellLib.cleanSourceWith { src = testSrcRootWithGitDir; inherit subDir; includeSiblings = true; };
|
2020-04-20 04:27:52 +03:00
|
|
|
callTest = x: args: haskell-nix.callPackage x (args // { inherit testSrc; });
|
|
|
|
|
2019-11-15 04:20:16 +03:00
|
|
|
# Run unit tests with: nix-instantiate --eval --strict -A unit.tests
|
|
|
|
# An empty list means success.
|
2020-02-05 04:11:47 +03:00
|
|
|
unitTests =
|
|
|
|
let
|
2022-02-17 14:42:11 +03:00
|
|
|
tests = haskell-nix.callPackage ./unit.nix { inherit compiler-nix-name; };
|
2020-02-05 04:11:47 +03:00
|
|
|
testsFailedEcho = lib.concatMapStringsSep "\n" (t: "echo ${t.name} failed") tests;
|
|
|
|
testsFinalLine = if builtins.length tests == 0 then "\ntouch $out" else "\nexit 1";
|
|
|
|
testsScript = testsFailedEcho + testsFinalLine;
|
|
|
|
in
|
|
|
|
runCommand "unit-tests" { passthru = { inherit tests; }; } testsScript;
|
|
|
|
|
|
|
|
# All tests.
|
|
|
|
allTests = {
|
2020-07-08 13:54:01 +03:00
|
|
|
cabal-simple = callTest ./cabal-simple { inherit util compiler-nix-name; };
|
2021-03-28 11:03:20 +03:00
|
|
|
cabal-simple-debug = callTest ./cabal-simple-debug { inherit util compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
cabal-simple-prof = callTest ./cabal-simple-prof { inherit util compiler-nix-name; };
|
|
|
|
cabal-sublib = callTest ./cabal-sublib { inherit util compiler-nix-name; };
|
2021-08-17 15:44:03 +03:00
|
|
|
with-packages = callTest ./with-packages { inherit util compiler-nix-name; };
|
2021-11-13 02:43:04 +03:00
|
|
|
builder-haddock = callTest ./builder-haddock { inherit compiler-nix-name; };
|
2021-08-17 15:44:03 +03:00
|
|
|
stack-simple = callTest ./stack-simple { inherit compiler-nix-name; };
|
|
|
|
stack-local-resolver = callTest ./stack-local-resolver { inherit compiler-nix-name; };
|
|
|
|
stack-local-resolver-subdir = callTest ./stack-local-resolver-subdir { inherit compiler-nix-name; };
|
|
|
|
stack-remote-resolver = callTest ./stack-remote-resolver { inherit compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
shell-for-setup-deps = callTest ./shell-for-setup-deps { inherit compiler-nix-name; };
|
|
|
|
setup-deps = import ./setup-deps { inherit pkgs compiler-nix-name; };
|
2021-08-17 15:44:03 +03:00
|
|
|
callStackToNix = callTest ./call-stack-to-nix { inherit compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
callCabalProjectToNix = callTest ./call-cabal-project-to-nix { inherit compiler-nix-name; };
|
|
|
|
cabal-source-repo = callTest ./cabal-source-repo { inherit compiler-nix-name; };
|
2020-08-06 05:59:26 +03:00
|
|
|
cabal-source-repo-comments = callTest ./cabal-source-repo-comments { inherit compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
buildable = callTest ./buildable { inherit compiler-nix-name; };
|
|
|
|
project-flags-cabal = callTest ./project-flags/cabal.nix { inherit compiler-nix-name; };
|
2021-08-17 15:44:03 +03:00
|
|
|
project-flags-stack = callTest ./project-flags/stack.nix { inherit compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
ghc-options-cabal = callTest ./ghc-options/cabal.nix { inherit compiler-nix-name; };
|
2021-08-17 15:44:03 +03:00
|
|
|
ghc-options-stack = callTest ./ghc-options/stack.nix { inherit compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
exe-only = callTest ./exe-only { inherit util compiler-nix-name; };
|
2021-08-17 15:44:03 +03:00
|
|
|
stack-source-repo = callTest ./stack-source-repo { inherit compiler-nix-name; };
|
2021-03-20 04:25:30 +03:00
|
|
|
cabal-doctests = callTest ./cabal-doctests { inherit util compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
extra-hackage = callTest ./extra-hackage { inherit compiler-nix-name; };
|
2022-02-17 14:42:11 +03:00
|
|
|
ghcjs-overlay = callTest ./ghcjs-overlay { inherit compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
hls-cabal = callTest ./haskell-language-server/cabal.nix { inherit compiler-nix-name; };
|
|
|
|
hls-stack = callTest ./haskell-language-server/stack.nix { inherit compiler-nix-name; };
|
|
|
|
cabal-hpack = callTest ./cabal-hpack { inherit util compiler-nix-name; };
|
|
|
|
index-state = callTest ./index-state { inherit compiler-nix-name; };
|
2022-02-17 14:42:11 +03:00
|
|
|
sha256map = callTest ./sha256map { inherit compiler-nix-name; };
|
2021-03-28 11:03:20 +03:00
|
|
|
# fully-static = callTest ./fully-static { inherit (pkgs) buildPackages; };
|
2021-06-15 10:50:45 +03:00
|
|
|
shell-for = callTest ./shell-for { inherit compiler-nix-name; };
|
2020-11-17 12:22:53 +03:00
|
|
|
cabal-22 = callTest ./cabal-22 { inherit util compiler-nix-name; };
|
|
|
|
coverage = callTest ./coverage { inherit compiler-nix-name; };
|
2020-12-11 11:57:35 +03:00
|
|
|
coverage-golden = callTest ./coverage-golden { inherit compiler-nix-name;};
|
2020-12-10 10:47:57 +03:00
|
|
|
coverage-no-libs = callTest ./coverage-no-libs { inherit compiler-nix-name; };
|
2021-08-17 15:44:03 +03:00
|
|
|
snapshots = callTest ./snapshots { inherit compiler-nix-name; };
|
2020-07-08 13:54:01 +03:00
|
|
|
sublib-docs = callTest ./sublib-docs { inherit util compiler-nix-name; };
|
2021-01-14 02:34:06 +03:00
|
|
|
githash = haskell-nix.callPackage ./githash { inherit compiler-nix-name; testSrc = testSrcWithGitDir; };
|
2022-01-08 17:11:37 +03:00
|
|
|
c-ffi = callTest ./c-ffi { inherit util compiler-nix-name; };
|
2022-03-25 11:44:02 +03:00
|
|
|
th-dlls = callTest ./th-dlls { inherit util compiler-nix-name; };
|
2022-04-25 17:04:33 +03:00
|
|
|
external-static-plugin = callTest ./external-static-plugin { inherit compiler-nix-name; };
|
2022-05-19 11:21:16 +03:00
|
|
|
exe-dlls = callTest ./exe-dlls { inherit util compiler-nix-name; };
|
|
|
|
exe-lib-dlls = callTest ./exe-lib-dlls { inherit util compiler-nix-name; };
|
2021-03-28 11:03:20 +03:00
|
|
|
|
|
|
|
unit = unitTests;
|
2020-02-05 04:11:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
# This is the same as allTests, but filter out all the key/vaules from the
|
|
|
|
# tests other than the "ifdInputs" key if the input ifdLevel is less than 3.
|
|
|
|
allTestsRemoveIfdLTLevel3 = ifdLevel:
|
|
|
|
filterNonIfdInputsValuesLTLevel3 ifdLevel allTests;
|
|
|
|
|
|
|
|
# This is the same as allTestsRemoveIfdLTLevel3, but make sure
|
|
|
|
# recurseForDerivations is set on all child values under the
|
|
|
|
# ifdInputs key.
|
|
|
|
allTestsWithIfdInputs = ifdLevel:
|
|
|
|
addIfdInputsToVal (allTestsRemoveIfdLTLevel3 ifdLevel);
|
|
|
|
|
|
|
|
# This is the same as allTestsWithIfdInputs, but returns an empty attribute set
|
|
|
|
# if the input ifdLevel is 0 or 1.
|
|
|
|
#
|
|
|
|
# Here is the result based on the input ifdLevel:
|
|
|
|
#
|
|
|
|
# - input ifdLevel is 0 or 1: {}
|
|
|
|
# - input ifdLevel is 2: filter out everything from the children of allTests
|
|
|
|
# except for the ifdInputs attribute
|
|
|
|
# - input ifdLevel is 3 or greater: return allTests
|
|
|
|
optionalIfdTests = ifdLevel:
|
|
|
|
pkgs.lib.optionalAttrs (ifdLevel > 1) (allTestsWithIfdInputs ifdLevel);
|
2021-03-28 11:03:20 +03:00
|
|
|
in filterAttrsOnlyRecursive (_: v: !(isDisabled v))
|
|
|
|
(pkgs.recurseIntoAttrs (optionalIfdTests ifdLevel))
|
2018-12-20 04:59:49 +03:00
|
|
|
|
2019-04-02 06:08:25 +03:00
|
|
|
## more possible test cases
|
2018-12-20 04:59:49 +03:00
|
|
|
# 1. fully static linking
|
2019-04-02 06:08:25 +03:00
|
|
|
# 2. cabal 2.4 stuff
|
|
|
|
# 3. cross-compiling
|