mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge pull request #10163 from dotCooCoo/fix/warm-builds-integration-tests
xtask: the cache warm builds integration tests too
This commit is contained in:
1 file changed
+36
-9
+36
-9
@@ -267,12 +267,14 @@ fn cmd_test() -> Result<(), String> {
|
||||
test_packages(&["--workspace".to_owned()], "--workspace", None)
|
||||
}
|
||||
|
||||
/// The test targets that [`test_packages`] runs and `ci warm` builds.
|
||||
const TARGETS: [&str; 3] = ["--lib", "--bins", "--tests"];
|
||||
|
||||
/// [`cmd_test`] for the packages `select` picks (`--workspace` or `-p` ids), shown as `shown`;
|
||||
/// with `part`, only that part's share of their tests (xtask/src/shards.rs), which needs nextest.
|
||||
/// A part runs its counted share, then its pinned tests, each with nextest's default thread count.
|
||||
/// Every run finishes before the first error is returned.
|
||||
fn test_packages(select: &[String], shown: &str, part: Option<shards::Part>) -> Result<(), String> {
|
||||
const TARGETS: [&str; 3] = ["--lib", "--bins", "--tests"];
|
||||
if let Some(part) = part {
|
||||
if !has_nextest() {
|
||||
return Err(format!("cargo nextest run {shown}: a shard that runs part of a crate's tests needs cargo-nextest"));
|
||||
@@ -393,11 +395,13 @@ fn cmd_ci_shard() -> Result<(), String> {
|
||||
run_steps(&steps)
|
||||
}
|
||||
|
||||
/// `cargo xtask ci warm`: for each test shard, builds its crates' library and binary tests without
|
||||
/// running them, then builds what the checks shard builds, so one dependency-cache entry holds the
|
||||
/// dependencies of every shard with the features that shard builds them with (cargo resolves
|
||||
/// features over the packages each command selects). The integration tests are left out: they
|
||||
/// build no dependency that the library tests do not, since both take the crate's dev-dependencies.
|
||||
/// `cargo xtask ci warm`: for each test shard, builds its crates' library, binary and integration
|
||||
/// tests without running them, then builds what the checks shard builds, so one dependency-cache
|
||||
/// entry holds the dependencies of every shard with the features that shard builds them with (cargo
|
||||
/// resolves features over the packages each command selects). The test builds select the same
|
||||
/// targets as the test shards ([`TARGETS`]), so the cache also holds the test executables the
|
||||
/// shards run, and cargo does not warn (`cargo::unused_dependencies`) about a dev-dependency that
|
||||
/// only an integration test uses.
|
||||
///
|
||||
/// In a leg that saves the cache, every build records its units in `CRAFT_CACHE_UNITS`
|
||||
/// (xtask/src/cache_units.rs), xtask's own build included.
|
||||
@@ -414,9 +418,8 @@ fn cmd_ci_warm() -> Result<(), String> {
|
||||
steps.push((
|
||||
"build tests",
|
||||
Box::new(move || {
|
||||
let mut c = cargo();
|
||||
c.arg("test").args(shards::select(&crates)).args(["--lib", "--bins", "--no-run"]);
|
||||
cache_units::run(c, &format!("cargo test --lib --bins --no-run ({})", shards::names(&crates)))
|
||||
let (c, what) = warm_tests(&crates);
|
||||
cache_units::run(c, &what)
|
||||
}),
|
||||
));
|
||||
}
|
||||
@@ -447,6 +450,13 @@ fn cmd_ci_warm() -> Result<(), String> {
|
||||
run_steps(&steps)
|
||||
}
|
||||
|
||||
/// The command `ci warm` builds one test shard's tests with, and its description.
|
||||
fn warm_tests(crates: &[shards::Member]) -> (Command, String) {
|
||||
let mut c = cargo();
|
||||
c.arg("test").args(shards::select(crates)).args(TARGETS).arg("--no-run");
|
||||
(c, format!("cargo test {} --no-run ({})", TARGETS.join(" "), shards::names(crates)))
|
||||
}
|
||||
|
||||
/// Runs `steps` in turn, stopping at the first that fails; the summary names the steps that passed
|
||||
/// and, after a failure, the one that failed and those skipped.
|
||||
fn run_steps(steps: &[Step]) -> Result<(), String> {
|
||||
@@ -588,3 +598,20 @@ fn i18n_report_packages(select: &[String], shown: &str) -> Result<(), String> {
|
||||
c.arg("test").args(select).args(["--lib", "--bins", "--tests", "--", "i18n::tests::untranslated_report", "--exact", "--nocapture"]);
|
||||
run(c, &format!("cargo test {shown} --lib --bins --tests -- i18n::tests::untranslated_report --exact --nocapture"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn warm_builds_the_test_targets_the_shards_run() {
|
||||
let crates = [shards::Member { name: "a".into(), id: "path+file:///w/a#0.1.0".into(), version: "0.1.0".into(), doctests: true }];
|
||||
let (c, what) = warm_tests(&crates);
|
||||
let args: Vec<String> = c.get_args().map(|a| a.to_string_lossy().into_owned()).collect();
|
||||
assert_eq!(args, ["test", "-p", "path+file:///w/a#0.1.0", "--lib", "--bins", "--tests", "--no-run"]);
|
||||
for target in TARGETS {
|
||||
assert!(args.iter().any(|a| a == target), "ci warm does not build {target}");
|
||||
}
|
||||
assert_eq!(what, "cargo test --lib --bins --tests --no-run (a)");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user