Skip to content

Commit c37a853

Browse files
committed
cargo-rbmt: bring back build before test to catch gating issues
1 parent 3dc756f commit c37a853

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

cargo-rbmt/src/environment.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ pub fn get_packages(
105105
}
106106

107107
if !invalid_packages.is_empty() {
108-
let mut error_msg = format!(
109-
"Package not found in workspace: {}",
110-
invalid_packages.join(", ")
111-
);
108+
let mut error_msg =
109+
format!("Package not found in workspace: {}", invalid_packages.join(", "));
112110

113111
error_msg.push_str("\n\nAvailable packages:");
114112
for name in &available_names {
@@ -119,10 +117,8 @@ pub fn get_packages(
119117
}
120118

121119
// Filter to only requested packages.
122-
let package_info: Vec<(String, PathBuf)> = all_packages
123-
.into_iter()
124-
.filter(|(name, _)| packages.iter().any(|p| p == name))
125-
.collect();
120+
let package_info: Vec<(String, PathBuf)> =
121+
all_packages.into_iter().filter(|(name, _)| packages.iter().any(|p| p == name)).collect();
126122

127123
Ok(package_info)
128124
}

cargo-rbmt/src/test.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
//! Test tasks with feature matrix testing.
1+
//! Build and test tasks with feature matrix testing.
2+
//!
3+
//! `cargo build` runs before `cargo test` throughout this module to try
4+
//! and catch any issues involving `cfg(test)` somehow gating required code.
25
36
use std::ffi::OsStr;
47
use std::fmt;
@@ -130,7 +133,7 @@ impl TestConfig {
130133
}
131134
}
132135

133-
/// Run tests for all crates with the specified toolchain.
136+
/// Run build and test for all crates with the specified toolchain.
134137
pub fn run(
135138
sh: &Shell,
136139
toolchain: Toolchain,
@@ -161,11 +164,12 @@ pub fn run(
161164
Ok(())
162165
}
163166

164-
/// Run basic test and examples.
167+
/// Run basic build, test, and examples.
165168
fn do_test(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std::error::Error>> {
166169
quiet_println("Running basic tests");
167170

168-
// Basic test (includes build).
171+
// Basic build and test.
172+
quiet_cmd!(sh, "cargo --locked build").run()?;
169173
quiet_cmd!(sh, "cargo --locked test").run()?;
170174

171175
// Run examples.
@@ -214,6 +218,8 @@ fn do_feature_matrix(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std:
214218
for features in &config.exact_features {
215219
let features_str = features.join(" ");
216220
quiet_println(&format!("Testing exact features: {}", features_str));
221+
quiet_cmd!(sh, "cargo --locked build --no-default-features --features={features_str}")
222+
.run()?;
217223
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={features_str}")
218224
.run()?;
219225
}
@@ -223,17 +229,20 @@ fn do_feature_matrix(sh: &Shell, config: &TestConfig) -> Result<(), Box<dyn std:
223229
// Handle no-std pattern (rust-miniscript).
224230
if config.features_with_no_std.is_empty() {
225231
quiet_println("Testing no-default-features");
232+
quiet_cmd!(sh, "cargo --locked build --no-default-features").run()?;
226233
quiet_cmd!(sh, "cargo --locked test --no-default-features").run()?;
227234
} else {
228235
let no_std = FeatureFlag::NoStd;
229236
quiet_println("Testing no-std");
237+
quiet_cmd!(sh, "cargo --locked build --no-default-features --features={no_std}").run()?;
230238
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={no_std}").run()?;
231239

232240
loop_features(sh, Some(FeatureFlag::NoStd), &config.features_with_no_std)?;
233241
}
234242

235243
// Test all features.
236244
quiet_println("Testing all-features");
245+
quiet_cmd!(sh, "cargo --locked build --all-features").run()?;
237246
quiet_cmd!(sh, "cargo --locked test --all-features").run()?;
238247

239248
// Test features with std.
@@ -275,20 +284,24 @@ fn loop_features<S: AsRef<str>>(
275284
.chain(additional.iter().map(std::convert::AsRef::as_ref))
276285
.collect::<Vec<_>>()
277286
.join(" "),
278-
None => additional.iter().map(std::convert::AsRef::as_ref).collect::<Vec<_>>().join(" "),
287+
None =>
288+
additional.iter().map(std::convert::AsRef::as_ref).collect::<Vec<_>>().join(" "),
279289
}
280290
}
281291

282292
// Test all features together.
283293
let all_features = combine_features(base, features);
284294
quiet_println(&format!("Testing features: {}", all_features));
295+
quiet_cmd!(sh, "cargo --locked build --no-default-features --features={all_features}").run()?;
285296
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={all_features}").run()?;
286297

287298
// Test each feature individually and all pairs (only if more than one feature).
288299
if features.len() > 1 {
289300
for i in 0..features.len() {
290301
let feature_combo = combine_features(base, &features[i..=i]);
291302
quiet_println(&format!("Testing features: {}", feature_combo));
303+
quiet_cmd!(sh, "cargo --locked build --no-default-features --features={feature_combo}")
304+
.run()?;
292305
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={feature_combo}")
293306
.run()?;
294307

@@ -297,6 +310,11 @@ fn loop_features<S: AsRef<str>>(
297310
let pair = [&features[i], &features[j]];
298311
let feature_combo = combine_features(base, &pair);
299312
quiet_println(&format!("Testing features: {}", feature_combo));
313+
quiet_cmd!(
314+
sh,
315+
"cargo --locked build --no-default-features --features={feature_combo}"
316+
)
317+
.run()?;
300318
quiet_cmd!(
301319
sh,
302320
"cargo --locked test --no-default-features --features={feature_combo}"

0 commit comments

Comments
 (0)