diff options
author | sterni <sternenseemann@systemli.org> | 2021-02-14T11·41+0100 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-02-14T12·40+0000 |
commit | beed354904133f5ea823df92d6a0e52c2fb48e3b (patch) | |
tree | ad79ce09ded02844b415f04f448c6e26bce2e097 | |
parent | abbc538ef348f4faa31c93d145193a38b2af9bf9 (diff) |
feat(users/Profpatsch/writers): testRustSimple to test rust crates r/2215
testRustSimple is intended to wrap rustSimpleLib and rustSimpleBin and theoretically pkgs.buildRustCrate with { buildTests = false; } while building and running their tests, making them fail if the tests don't succeed. This is implemented using nix.drvSeqL which is a perfect fit here: * { buildTests = true; } only returns an output with the test binaries and does not actually run the tests. With drvSeqL we can easily wrap this derivation. * { buildTests = true } doesn't contain anything other derivations want to depend on, so it is an derivation output we don't want to have. drvSeqL hides the tests derivation away and only requires us to build it once. * Usually drvSeqL has the issue that tests (or advantage) are not rebuilt if the test derivation changes. This is no question in this case as due to the embedded nature of Rust's test, both the derivation with and without tests change anyways regardless of which part was changed. Future work: Allow injecting other tests? Change-Id: If6ecfb3a360ce059320dbb05642b391b617aede7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2529 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
-rw-r--r-- | users/Profpatsch/writers/default.nix | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/users/Profpatsch/writers/default.nix b/users/Profpatsch/writers/default.nix index 4eb354c305ab..b9359b6f11c5 100644 --- a/users/Profpatsch/writers/default.nix +++ b/users/Profpatsch/writers/default.nix @@ -1,9 +1,11 @@ { depot, pkgs, lib, ... }: let - bins = depot.nix.getBins pkgs.coreutils ["printf" "mkdir" "cat" "ln"]; + bins = depot.nix.getBins pkgs.coreutils ["printf" "mkdir" "cat" "ln" "ls" "touch" ]; inherit (depot.nix.yants) defun struct restrict attrs list string drv any; + inherit (depot.nix) drvSeqL; + FlakeError = restrict "flake error" @@ -111,6 +113,32 @@ 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 `nix.drvSeqL` which is used to implement + * this behavior. + */ + testRustSimple = rustDrv: + let + crate = buildTests: rustDrv.override { inherit buildTests; }; + tests = depot.nix.runExecline.local "${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); + + tests = import ./tests.nix { inherit depot @@ -129,6 +157,7 @@ in { rustSimple rustSimpleBin rustSimpleLib + testRustSimple tests ; } |