From ddfd1d84dbe6b38fce55f30bcf9e870c3cad5819 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Mon, 21 Oct 2024 15:12:10 +0200 Subject: [PATCH] feat(rust): add `doctest` check Signed-off-by: Roman Volosatovs --- checks/default.nix | 1 + examples/rust-complex/flake.nix | 1 + lib/rust/default.nix | 1 + lib/rust/mkAttrs.nix | 18 +++++++++++++----- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/checks/default.nix b/checks/default.nix index ead5c64..4978fd8 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -74,6 +74,7 @@ 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-wasip1; diff --git a/examples/rust-complex/flake.nix b/examples/rust-complex/flake.nix index e4f471a..c94f96d 100644 --- a/examples/rust-complex/flake.nix +++ b/examples/rust-complex/flake.nix @@ -14,6 +14,7 @@ build.workspace = true; clippy.workspace = true; + test.doc = true; test.workspace = true; buildOverrides = { diff --git a/lib/rust/default.nix b/lib/rust/default.nix index d1a6106..4dd86f8 100644 --- a/lib/rust/default.nix +++ b/lib/rust/default.nix @@ -128,6 +128,7 @@ in { defaultTestConfig.allFeatures = false; defaultTestConfig.allTargets = false; + defaultTestConfig.doc = false; defaultTestConfig.excludes = []; defaultTestConfig.features = []; defaultTestConfig.noDefaultFeatures = false; diff --git a/lib/rust/mkAttrs.nix b/lib/rust/mkAttrs.nix index d59acbf..507078d 100644 --- a/lib/rust/mkAttrs.nix +++ b/lib/rust/mkAttrs.nix @@ -210,16 +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; 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