Commit 111e3e57 authored by Profpatsch's avatar Profpatsch

buildSupport: withTests nixpkgs testing base function

The idea is that you can test derivations without having to rebuild if a test
fails or needing a VM-test.

So
foo = withTests { t1 = ''exit 1''; } fooDrv
will build fooDrv, but fail the build of foo because test t1 exits ≠ 0.

This is the base building block for a nixpkgs testing framework with no nixos
dependency.
parent fabafb32
{ runCommand, lib }:
{
/* Takes a derivation and an attribute set of
* test names to tests.
* Tests are shell fragments which test the
* derivation and should result in failure if
* the functionality is not as expected. */
withTests = tests: drv: let
drvOutputs = drv.outputs or ["out"];
in
assert (drv ? drvAttrs); # not a derivation!
runCommand drv.name {
# we inherit all attributes in order to replicate
# the original derivation as much as possible
outputs = drvOutputs;
passthru = drv.drvAttrs;
# depend on each test (by putting in builder context)
tests = lib.mapAttrsToList
(name: testScript:
runCommand "${drv.name}-test-${name}" {} ''
${testScript}
touch "$out"
'')
tests;
}
# the outputs of the original derivation are replicated
# by creating a symlink
(lib.concatMapStrings (output: ''
ln -s ${lib.escapeShellArg drv.${output}} "${"$"}${output}"
'') drvOutputs);
}
......@@ -69,6 +69,12 @@ let
inherit lib; inherit (self) stdenv stdenvNoCC; inherit (self.xorg) lndir;
};
packageTests = self: super:
import ../build-support/package-tests.nix {
inherit (super) runCommand; inherit lib;
};
stdenvBootstappingAndPlatforms = self: super: {
buildPackages = (if buildPackages == null then self else buildPackages)
// { recurseForDerivations = false; };
......@@ -124,6 +130,7 @@ let
platformCompat
stdenvAdapters
trivialBuilders
packageTests
splice
allPackages
aliases
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment