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
36use std:: ffi:: OsStr ;
47use 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.
134137pub 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.
165168fn 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