Skip to content

Commit ea360a1

Browse files
committed
Merge #57: Bring back build before test to catch gating issues
c37a853 cargo-rbmt: bring back build before test to catch gating issues (Nick Johnson) Pull request description: As pointed out by @apoelstra in #39 (comment), this isn't a performance thing, it attempts to catch issues where gated test code is actually depended on. ACKs for top commit: tcharding: ACK c37a853 Tree-SHA512: 4df1b9f2261576b05f2c50e97bbf7cb0003f5bf29b3d63e31c0eff863c0094c548cb7e57280854206db16f79eb0005ff54e6452ffea85348f003b2eec3421b95
2 parents 10c544f + c37a853 commit ea360a1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cargo-rbmt/src/test.rs

Lines changed: 21 additions & 4 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.
@@ -283,13 +292,16 @@ fn loop_features<S: AsRef<str>>(
283292
// Test all features together.
284293
let all_features = combine_features(base, features);
285294
quiet_println(&format!("Testing features: {}", all_features));
295+
quiet_cmd!(sh, "cargo --locked build --no-default-features --features={all_features}").run()?;
286296
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={all_features}").run()?;
287297

288298
// Test each feature individually and all pairs (only if more than one feature).
289299
if features.len() > 1 {
290300
for i in 0..features.len() {
291301
let feature_combo = combine_features(base, &features[i..=i]);
292302
quiet_println(&format!("Testing features: {}", feature_combo));
303+
quiet_cmd!(sh, "cargo --locked build --no-default-features --features={feature_combo}")
304+
.run()?;
293305
quiet_cmd!(sh, "cargo --locked test --no-default-features --features={feature_combo}")
294306
.run()?;
295307

@@ -298,6 +310,11 @@ fn loop_features<S: AsRef<str>>(
298310
let pair = [&features[i], &features[j]];
299311
let feature_combo = combine_features(base, &pair);
300312
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()?;
301318
quiet_cmd!(
302319
sh,
303320
"cargo --locked test --no-default-features --features={feature_combo}"

0 commit comments

Comments
 (0)