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 <mail@profpatsch.de>
			
			
This commit is contained in:
		
							parent
							
								
									abbc538ef3
								
							
						
					
					
						commit
						beed354904
					
				
					 1 changed files with 30 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,9 +1,11 @@
 | 
				
			||||||
{ depot, pkgs, lib, ... }:
 | 
					{ depot, pkgs, lib, ... }:
 | 
				
			||||||
let
 | 
					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.yants) defun struct restrict attrs list string drv any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  inherit (depot.nix) drvSeqL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  FlakeError =
 | 
					  FlakeError =
 | 
				
			||||||
    restrict
 | 
					    restrict
 | 
				
			||||||
      "flake error"
 | 
					      "flake error"
 | 
				
			||||||
| 
						 | 
					@ -111,6 +113,32 @@ let
 | 
				
			||||||
      '';
 | 
					      '';
 | 
				
			||||||
    } // args);
 | 
					    } // 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 {
 | 
					  tests = import ./tests.nix {
 | 
				
			||||||
    inherit
 | 
					    inherit
 | 
				
			||||||
      depot
 | 
					      depot
 | 
				
			||||||
| 
						 | 
					@ -129,6 +157,7 @@ in {
 | 
				
			||||||
    rustSimple
 | 
					    rustSimple
 | 
				
			||||||
    rustSimpleBin
 | 
					    rustSimpleBin
 | 
				
			||||||
    rustSimpleLib
 | 
					    rustSimpleLib
 | 
				
			||||||
 | 
					    testRustSimple
 | 
				
			||||||
    tests
 | 
					    tests
 | 
				
			||||||
    ;
 | 
					    ;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue