Skip to content

Commit

Permalink
feat(rust): make doctest opt-in
Browse files Browse the repository at this point in the history
Doctest is only supported for library crates - make it opt-in for now to
avoid the guesswork

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
  • Loading branch information
rvolosatovs committed Oct 21, 2024
1 parent 8c0d0a8 commit 2483173
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
3 changes: 1 addition & 2 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ in
assert attrs.${system} ? "${name}-x86_64-unknown-linux-musl-oci";
assert attrs.${system} ? ${name}; x;
in
assert flakes.rust.complex.checks.${system} ? doctest;
assert flakes.rust.complex.packages.${system} ? default;
assert flakes.rust.hello-multibin.packages.${system} ? default;
assert flakes.rust.hello-multibin.packages.${system} ? rust-hello-multibin-wasm32-wasip2;
assert flakes.rust.hello.packages.${system} ? default;
assert flakes.rust.hello.packages.${system} ? rust-hello-wasm32-wasip2-oci;
assert flakes.rust.hello.packages.${system} ? rust-hello-wasm32-wasip2;
assert flakes.rust.lib.checks.${system} ? doctest;
assert flakes.rust.lib.packages.${system} ? rust-lib-wasm32-wasip2;
assert flakes.rust.workspace.checks.${system} ? doctest;
assert flakes.rust.workspace.packages.${system} ? default;
assert flakes.rust.workspace.packages.${system} ? rust-workspace-wasm32-wasip2;
(assertRustPackages flakes.rust.complex.packages "rust-complex")
Expand Down
1 change: 1 addition & 0 deletions examples/rust-complex/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

build.workspace = true;
clippy.workspace = true;
test.doc = true;
test.workspace = true;

buildOverrides = {
Expand Down
1 change: 1 addition & 0 deletions lib/rust/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ in {

defaultTestConfig.allFeatures = false;
defaultTestConfig.allTargets = false;
defaultTestConfig.doc = false;
defaultTestConfig.excludes = [];
defaultTestConfig.features = [];
defaultTestConfig.noDefaultFeatures = false;
Expand Down
23 changes: 13 additions & 10 deletions lib/rust/mkAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,24 @@ with self.lib.rust.targets;
}
callCraneWithDeps (mkHostArgs craneArgs);

callHostCraneCheckWithDeps = craneArgs:
trace' "callHostCraneCheckWithDeps" {
inherit craneArgs;
}
callHostCraneWithDeps (craneArgs
// {
doCheck = true; # without performing the actual testing, this check is useless
});

checks =
{
clippy = callHostCraneWithDeps {} hostCraneLib.cargoClippy;
doc = callHostCraneWithDeps {} hostCraneLib.cargoDoc;
doctest =
callHostCraneWithDeps {
doCheck = true; # without performing the actual testing, this check is useless
}
hostCraneLib.cargoDocTest;
fmt = callHostCrane {} hostCraneLib.cargoFmt;
nextest =
callHostCraneWithDeps {
doCheck = true; # without performing the actual testing, this check is useless
}
hostCraneLib.cargoNextest;
nextest = callHostCraneCheckWithDeps {} hostCraneLib.cargoNextest;
}
// (optionalAttrs (test ? doc && test.doc)) {
doctest = callHostCraneCheckWithDeps {} hostCraneLib.cargoDocTest;
}
// (optionalAttrs (pathExists "${src}/Cargo.lock") {
# TODO: Use `cargoLock` if `Cargo.lock` missing
Expand Down

0 comments on commit 2483173

Please sign in to comment.