@@ -71,27 +71,43 @@ impl std::fmt::Debug for ProcessFailed {
7171}
7272
7373trait CommandHelper {
74- fn capture_outputs (
74+ fn run_and_capture_outputs (
7575 & mut self ,
7676 cant_fail : bool ,
7777 name : & str ,
7878 stdout : Option < & PathBuf > ,
7979 stderr : Option < & PathBuf > ,
8080 previous_processes_stderr : & [ PathBuf ] ,
8181 ) -> Result < ( ) , TestError > ;
82+
83+ fn run_and_capture_stderr (
84+ & mut self ,
85+ cant_fail : bool ,
86+ name : & str ,
87+ stderr : & PathBuf ,
88+ previous_processes_stderr : & [ PathBuf ] ,
89+ ) -> Result < ( ) , TestError > {
90+ self . run_and_capture_outputs (
91+ cant_fail,
92+ name,
93+ None ,
94+ Some ( stderr) ,
95+ previous_processes_stderr,
96+ )
97+ }
8298}
8399
84100impl CommandHelper for Command {
85101 #[ tracing:: instrument( skip_all, fields( stdout = tracing:: field:: Empty , stderr = tracing:: field:: Empty ) ) ]
86- fn capture_outputs (
102+ fn run_and_capture_outputs (
87103 & mut self ,
88104 cant_fail : bool ,
89105 name : & str ,
90106 stdout : Option < & PathBuf > ,
91107 stderr : Option < & PathBuf > ,
92108 previous_processes_stderr : & [ PathBuf ] ,
93109 ) -> Result < ( ) , TestError > {
94- let output = self . get_output ( true ) ?;
110+ let output = self . run_and_get_output ( true ) ?;
95111 let out_payload = String :: from_utf8_lossy ( & output. stdout ) ;
96112 if let Some ( out) = stdout {
97113 file_helper ( & out_payload, out) ?;
@@ -142,41 +158,98 @@ impl TestCase {
142158 & self ,
143159 opts : & Opts ,
144160 bin_path : & Path ,
145- cli_opts : & Option < Vec < String > > ,
161+ run_clippy : bool ,
162+ run_docs_stable : bool ,
163+ run_docs_nightly : bool ,
164+ cli_passthrough_opts : & Option < Vec < String > > ,
146165 ) -> Result < Option < Vec < PathBuf > > , TestError > {
147166 let ( chip_dir, mut process_stderr_paths) = self
148- . setup_case ( & opts. output_dir , bin_path, cli_opts )
167+ . setup_case ( & opts. output_dir , bin_path, cli_passthrough_opts )
149168 . with_context ( || anyhow ! ( "when setting up case for {}" , self . name( ) ) ) ?;
150169 // Run `cargo check`, capturing stderr to a log file
151170 if !self . skip_check {
152171 let cargo_check_err_file = path_helper_base ( & chip_dir, & [ "cargo-check.err.log" ] ) ;
153172 Command :: new ( "cargo" )
154173 . arg ( "check" )
155174 . current_dir ( & chip_dir)
156- . capture_outputs (
175+ . run_and_capture_stderr (
157176 true ,
158177 "cargo check" ,
159- None ,
160- Some ( & cargo_check_err_file) ,
178+ & cargo_check_err_file,
161179 & process_stderr_paths,
162180 )
163- . with_context ( || "failed to check" ) ?;
181+ . with_context ( || "failed to check with cargo check " ) ?;
164182 process_stderr_paths. push ( cargo_check_err_file) ;
165183 }
184+ if run_docs_nightly {
185+ tracing:: info!( "Checking docs build with nightly" ) ;
186+ let cargo_docs_err_file = path_helper_base ( & chip_dir, & [ "cargo-docs-nightly.err.log" ] ) ;
187+ // Docs are built like docs.rs would build them. Additionally, build with all features.
188+
189+ // Set the RUSTDOCFLAGS environment variable
190+ let rustdocflags = "--cfg docsrs --generate-link-to-definition -Z unstable-options" ;
191+ Command :: new ( "cargo" )
192+ . arg ( "+nightly" )
193+ . arg ( "doc" )
194+ . arg ( "--all-features" )
195+ . env ( "RUSTDOCFLAGS" , rustdocflags) // Set the environment variable
196+ . current_dir ( & chip_dir)
197+ . run_and_capture_stderr (
198+ true ,
199+ "cargo docs nightly" ,
200+ & cargo_docs_err_file,
201+ & process_stderr_paths,
202+ )
203+ . with_context ( || "failed to generate docs with cargo docs" ) ?;
204+ }
205+ if run_docs_stable {
206+ tracing:: info!( "Checking docs build with stable" ) ;
207+ let cargo_docs_err_file = path_helper_base ( & chip_dir, & [ "cargo-docs-stable.err.log" ] ) ;
208+ // Docs are built like docs.rs would build them. Additionally, build with all features.
209+ Command :: new ( "cargo" )
210+ . arg ( "+stable" )
211+ . arg ( "doc" )
212+ . arg ( "--all-features" )
213+ . current_dir ( & chip_dir)
214+ . run_and_capture_stderr (
215+ true ,
216+ "cargo docs stable" ,
217+ & cargo_docs_err_file,
218+ & process_stderr_paths,
219+ )
220+ . with_context ( || "failed to generate docs with cargo docs" ) ?;
221+ }
222+ if run_clippy {
223+ tracing:: info!( "Checking with clippy" ) ;
224+ let cargo_clippy_err_file = path_helper_base ( & chip_dir, & [ "cargo-clippy.err.log" ] ) ;
225+ Command :: new ( "cargo" )
226+ . arg ( "clippy" )
227+ . arg ( "--" )
228+ . arg ( "-D" )
229+ . arg ( "warnings" )
230+ . current_dir ( & chip_dir)
231+ . run_and_capture_stderr (
232+ true ,
233+ "cargo clippy" ,
234+ & cargo_clippy_err_file,
235+ & process_stderr_paths,
236+ )
237+ . with_context ( || "failed to check with cargo clippy" ) ?;
238+ }
166239 Ok ( if opts. verbose > 1 {
167240 Some ( process_stderr_paths)
168241 } else {
169242 None
170243 } )
171244 }
172245
173- #[ tracing:: instrument( skip( self , output_dir, command ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
246+ #[ tracing:: instrument( skip( self , output_dir, passthrough_opts ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
174247
175248 pub fn setup_case (
176249 & self ,
177250 output_dir : & Path ,
178251 svd2rust_bin_path : & Path ,
179- command : & Option < Vec < String > > ,
252+ passthrough_opts : & Option < Vec < String > > ,
180253 ) -> Result < ( PathBuf , Vec < PathBuf > ) , TestError > {
181254 let user = match std:: env:: var ( "USER" ) {
182255 Ok ( val) => val,
@@ -210,10 +283,10 @@ impl TestCase {
210283 . arg ( "none" )
211284 . arg ( "--lib" )
212285 . arg ( & chip_dir)
213- . capture_outputs ( true , "cargo init" , None , None , & [ ] )
286+ . run_and_capture_outputs ( true , "cargo init" , None , None , & [ ] )
214287 . with_context ( || "Failed to cargo init" ) ?;
215288
216- self . prepare_chip_test_toml ( & chip_dir, command ) ?;
289+ self . prepare_chip_test_toml ( & chip_dir, passthrough_opts ) ?;
217290 let chip_svd = self . prepare_svd_file ( & chip_dir) ?;
218291 self . prepare_rust_toolchain_file ( & chip_dir) ?;
219292
@@ -226,7 +299,7 @@ impl TestCase {
226299 & chip_dir,
227300 & lib_rs_file,
228301 & svd2rust_err_file,
229- command ,
302+ passthrough_opts ,
230303 ) ?;
231304 process_stderr_paths. push ( svd2rust_err_file) ;
232305 match self . arch {
@@ -262,7 +335,7 @@ impl TestCase {
262335 . arg ( & new_lib_rs_file)
263336 . arg ( "--outdir" )
264337 . arg ( & src_dir)
265- . capture_outputs (
338+ . run_and_capture_outputs (
266339 true ,
267340 "form" ,
268341 None ,
@@ -291,7 +364,7 @@ impl TestCase {
291364 Command :: new ( rustfmt_bin_path)
292365 . arg ( entry)
293366 . args ( [ "--edition" , "2021" ] )
294- . capture_outputs (
367+ . run_and_capture_outputs (
295368 false ,
296369 "rustfmt" ,
297370 None ,
@@ -417,7 +490,7 @@ impl TestCase {
417490 if let Some ( opts) = self . opts . as_ref ( ) {
418491 base_cmd. args ( opts) ;
419492 }
420- base_cmd. current_dir ( chip_dir) . capture_outputs (
493+ base_cmd. current_dir ( chip_dir) . run_and_capture_outputs (
421494 true ,
422495 "svd2rust" ,
423496 Some ( lib_rs_file) . filter ( |_| {
0 commit comments