@@ -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,80 @@ impl TestCase {
142158 & self ,
143159 opts : & Opts ,
144160 bin_path : & Path ,
145- cli_opts : & Option < Vec < String > > ,
161+ run_clippy : bool ,
162+ run_docs : bool ,
163+ cli_passthrough_opts : & Option < Vec < String > > ,
146164 ) -> Result < Option < Vec < PathBuf > > , TestError > {
147165 let ( chip_dir, mut process_stderr_paths) = self
148- . setup_case ( & opts. output_dir , bin_path, cli_opts )
166+ . setup_case ( & opts. output_dir , bin_path, cli_passthrough_opts )
149167 . with_context ( || anyhow ! ( "when setting up case for {}" , self . name( ) ) ) ?;
150168 // Run `cargo check`, capturing stderr to a log file
151169 if !self . skip_check {
152170 let cargo_check_err_file = path_helper_base ( & chip_dir, & [ "cargo-check.err.log" ] ) ;
153171 Command :: new ( "cargo" )
154172 . arg ( "check" )
155173 . current_dir ( & chip_dir)
156- . capture_outputs (
174+ . run_and_capture_stderr (
157175 true ,
158176 "cargo check" ,
159- None ,
160- Some ( & cargo_check_err_file) ,
177+ & cargo_check_err_file,
161178 & process_stderr_paths,
162179 )
163- . with_context ( || "failed to check" ) ?;
180+ . with_context ( || "failed to check with cargo check " ) ?;
164181 process_stderr_paths. push ( cargo_check_err_file) ;
165182 }
183+ if run_docs {
184+ tracing:: info!( "Checking docs build" ) ;
185+ let cargo_docs_err_file = path_helper_base ( & chip_dir, & [ "cargo-docs.err.log" ] ) ;
186+ // Docs are built like docs.rs would build them. Additionally, build with all features.
187+
188+ // Set the RUSTDOCFLAGS environment variable
189+ let rustdocflags = "--cfg docsrs --generate-link-to-definition -Z unstable-options" ;
190+ Command :: new ( "cargo" )
191+ . arg ( "+nightly" )
192+ . arg ( "doc" )
193+ . arg ( "--all-features" )
194+ . env ( "RUSTDOCFLAGS" , rustdocflags) // Set the environment variable
195+ . current_dir ( & chip_dir)
196+ . run_and_capture_stderr (
197+ true ,
198+ "cargo docs" ,
199+ & cargo_docs_err_file,
200+ & process_stderr_paths,
201+ )
202+ . with_context ( || "failed to generate docs with cargo docs" ) ?;
203+ }
204+ if run_clippy {
205+ tracing:: info!( "Checking with clippy" ) ;
206+ let cargo_clippy_err_file = path_helper_base ( & chip_dir, & [ "cargo-clippy.err.log" ] ) ;
207+ Command :: new ( "cargo" )
208+ . arg ( "clippy" )
209+ . arg ( "--" )
210+ . arg ( "-D" )
211+ . arg ( "warnings" )
212+ . current_dir ( & chip_dir)
213+ . run_and_capture_stderr (
214+ true ,
215+ "cargo clippy" ,
216+ & cargo_clippy_err_file,
217+ & process_stderr_paths,
218+ )
219+ . with_context ( || "failed to check with cargo clippy" ) ?;
220+ }
166221 Ok ( if opts. verbose > 1 {
167222 Some ( process_stderr_paths)
168223 } else {
169224 None
170225 } )
171226 }
172227
173- #[ tracing:: instrument( skip( self , output_dir, command ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
228+ #[ tracing:: instrument( skip( self , output_dir, passthrough_opts ) , fields( name = %self . name( ) , chip_dir = tracing:: field:: Empty ) ) ]
174229
175230 pub fn setup_case (
176231 & self ,
177232 output_dir : & Path ,
178233 svd2rust_bin_path : & Path ,
179- command : & Option < Vec < String > > ,
234+ passthrough_opts : & Option < Vec < String > > ,
180235 ) -> Result < ( PathBuf , Vec < PathBuf > ) , TestError > {
181236 let user = match std:: env:: var ( "USER" ) {
182237 Ok ( val) => val,
@@ -209,10 +264,10 @@ impl TestCase {
209264 . arg ( "none" )
210265 . arg ( "--lib" )
211266 . arg ( & chip_dir)
212- . capture_outputs ( true , "cargo init" , None , None , & [ ] )
267+ . run_and_capture_outputs ( true , "cargo init" , None , None , & [ ] )
213268 . with_context ( || "Failed to cargo init" ) ?;
214269
215- self . prepare_chip_test_toml ( & chip_dir, command ) ?;
270+ self . prepare_chip_test_toml ( & chip_dir, passthrough_opts ) ?;
216271 let chip_svd = self . prepare_svd_file ( & chip_dir) ?;
217272 self . prepare_rust_toolchain_file ( & chip_dir) ?;
218273
@@ -225,7 +280,7 @@ impl TestCase {
225280 & chip_dir,
226281 & lib_rs_file,
227282 & svd2rust_err_file,
228- command ,
283+ passthrough_opts ,
229284 ) ?;
230285 process_stderr_paths. push ( svd2rust_err_file) ;
231286 match self . arch {
@@ -261,7 +316,7 @@ impl TestCase {
261316 . arg ( & new_lib_rs_file)
262317 . arg ( "--outdir" )
263318 . arg ( & src_dir)
264- . capture_outputs (
319+ . run_and_capture_outputs (
265320 true ,
266321 "form" ,
267322 None ,
@@ -290,7 +345,7 @@ impl TestCase {
290345 Command :: new ( rustfmt_bin_path)
291346 . arg ( entry)
292347 . args ( [ "--edition" , "2021" ] )
293- . capture_outputs (
348+ . run_and_capture_outputs (
294349 false ,
295350 "rustfmt" ,
296351 None ,
@@ -416,7 +471,7 @@ impl TestCase {
416471 if let Some ( opts) = self . opts . as_ref ( ) {
417472 base_cmd. args ( opts) ;
418473 }
419- base_cmd. current_dir ( chip_dir) . capture_outputs (
474+ base_cmd. current_dir ( chip_dir) . run_and_capture_outputs (
420475 true ,
421476 "svd2rust" ,
422477 Some ( lib_rs_file) . filter ( |_| {
0 commit comments