Skip to content

Commit 2adab70

Browse files
committed
test(nix): add per-crate cargo test checks
1 parent e77b7e8 commit 2adab70

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
};
7777
};
7878

79+
checks = lib.mapAttrs' (name: crate: lib.nameValuePair "${name}-test" crate.test) workspaceCrates;
80+
7981
devShells.default = pkgs.mkShell {
8082
packages = with pkgs; [
8183
rustToolchain

nix/crate.nix

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
};
1616
openshell-cli = {
1717
dir = "openshell-cli";
18+
nativeCheckInputs = [
19+
pkgs.cacert
20+
pkgs.git
21+
];
1822
assets = [
1923
(root + "/proto")
2024
(root + "/providers")
@@ -28,7 +32,9 @@
2832
(root + "/providers")
2933
(root + "/crates/openshell-prover/registry")
3034
(root + "/crates/openshell-server/migrations")
35+
(root + "/deploy/rpm/gateway.toml.default")
3136
];
37+
cargoTestExtraArgs = "--features test-support";
3238
};
3339
openshell-core = {
3440
dir = "openshell-core";
@@ -41,10 +47,15 @@
4147
};
4248
openshell-sandbox = {
4349
dir = "openshell-sandbox";
50+
nativeCheckInputs = [
51+
pkgs.bash
52+
pkgs.coreutils
53+
];
4454
assets = [
4555
(root + "/proto")
4656
(root + "/crates/openshell-sandbox/data")
4757
(root + "/crates/openshell-sandbox/src/skills")
58+
(root + "/crates/openshell-sandbox/testdata")
4859
];
4960
};
5061
openshell-driver-vm = {

nix/workspace.nix

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ let
9696
dir,
9797
assets ? [ ],
9898
nativeBuildInputs ? [ ],
99+
nativeCheckInputs ? [ ],
99100
buildInputs ? [ ],
100101
env ? { },
102+
cargoTestExtraArgs ? "",
101103
}:
102104
let
103105
closure = closureOf dir;
@@ -107,6 +109,10 @@ let
107109
);
108110
effectiveBuildInputs = lib.unique (closureList closure "buildInputs" ++ buildInputs);
109111
effectiveEnv = lib.recursiveUpdate (closureEnv closure) env;
112+
src = mkSrc {
113+
dirs = closure;
114+
inherit assets;
115+
};
110116
common = {
111117
pname = dir;
112118
inherit version;
@@ -152,18 +158,39 @@ let
152158
'';
153159
}
154160
);
161+
162+
cratesTestDeps = craneLib.buildPackage (
163+
common
164+
// {
165+
pname = "${dir}-test-deps";
166+
src = mkWorkspaceLibsSrc;
167+
inherit nativeCheckInputs;
168+
cargoArtifacts = workspaceLibs;
169+
cargoExtraArgs = "${common.cargoExtraArgs} --tests ${cargoTestExtraArgs}";
170+
doInstallCargoArtifacts = true;
171+
}
172+
);
155173
in
156-
{
174+
let
157175
package = craneLib.buildPackage (
158176
common
159177
// {
160-
src = mkSrc {
161-
dirs = closure;
162-
inherit assets;
163-
};
178+
inherit src;
164179
cargoArtifacts = workspaceLibs;
165180
}
166181
);
182+
183+
test = craneLib.cargoTest (
184+
common
185+
// {
186+
doCheck = true;
187+
inherit src nativeCheckInputs cargoTestExtraArgs;
188+
cargoArtifacts = cratesTestDeps;
189+
}
190+
);
191+
in
192+
{
193+
inherit package test;
167194
};
168195
in
169196
{

0 commit comments

Comments
 (0)