From beed354904133f5ea823df92d6a0e52c2fb48e3b Mon Sep 17 00:00:00 2001 From: sterni Date: Sun, 14 Feb 2021 12:41:39 +0100 Subject: feat(users/Profpatsch/writers): testRustSimple to test rust crates 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 --- users/Profpatsch/writers/default.nix | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'users/Profpatsch/writers') 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 ; } -- cgit 1.4.1