about summary refs log tree commit diff
path: root/pkgs/profpatsch/write-rust.nix
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-02-14 15:21:18 +0100
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2021-02-14 15:26:52 +0100
commit2c6c013291932e4d82712b4672e3958b52563634 (patch)
tree6d651b604dde0c3fb00d2b0a15311683cbba4442 /pkgs/profpatsch/write-rust.nix
parent587fcc7b89cda8abbbd1f08722b2b3e1349869c8 (diff)
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 :)
Diffstat (limited to 'pkgs/profpatsch/write-rust.nix')
-rw-r--r--pkgs/profpatsch/write-rust.nix30
1 files changed, 28 insertions, 2 deletions
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
     ;
 }