From 2c6c013291932e4d82712b4672e3958b52563634 Mon Sep 17 00:00:00 2001 From: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> Date: Sun, 14 Feb 2021 15:21:18 +0100 Subject: pkgs/profpatsch: vendor testRustSimple from tvl testRustSimple builds and runs the tests of a buildRustCrate derivation automatically using drvSeqL, returning its non-test variant. Really looking forward to pkgs.tvl :) --- pkgs/profpatsch/write-rust.nix | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'pkgs/profpatsch/write-rust.nix') diff --git a/pkgs/profpatsch/write-rust.nix b/pkgs/profpatsch/write-rust.nix index bf6c1eb2..afbeb80b 100644 --- a/pkgs/profpatsch/write-rust.nix +++ b/pkgs/profpatsch/write-rust.nix @@ -1,6 +1,6 @@ -{ pkgs, runExeclineLocal, getBins }: +{ pkgs, runExeclineLocal, getBins, drvSeqL }: let - bins = getBins pkgs.coreutils [ "ln" ]; + bins = getBins pkgs.coreutils [ "ln" "ls" "touch" ]; writeRustSimple = name: args: srcFile: linkTo name "${writeRustSimpleBin name args srcFile}/bin/${name}"; @@ -35,10 +35,36 @@ let ''; } // args); + /* Takes a `buildRustCrate` derivation as an input, + * builds it with `{ buildTests = true; }` and runs + * all tests found in its `tests` dir. If they are + * all successful, `$out` will point to the crate + * built with `{ buildTests = false; }`, otherwise + * it will fail to build. + * + * See also the documentation on `drvSeqL` which is + * used to implement this behavior. + */ + testRustSimple = rustDrv: + let + crate = buildTests: rustDrv.override { inherit buildTests; }; + tests = runExeclineLocal "${rustDrv.name}-tests-run" {} [ + "importas" "out" "out" + "if" [ + "pipeline" [ bins.ls "${crate true}/tests" ] + "forstdin" "test" + "importas" "test" "test" + "${crate true}/tests/$test" + ] + bins.touch "$out" + ]; + in drvSeqL [ tests ] (crate false); + in { inherit writeRustSimple writeRustSimpleBin writeRustSimpleLib + testRustSimple ; } -- cgit 1.4.1