11use crate :: errors:: * ;
2+ use crate :: tests:: TestCase ;
23use reqwest;
34use std:: fs:: { self , File , OpenOptions } ;
45use std:: io:: prelude:: * ;
56use std:: path:: PathBuf ;
67use std:: process:: { Command , Output } ;
7- use crate :: tests:: TestCase ;
88
99static CRATES_ALL : & [ & str ] = & [ "bare-metal = \" 0.2.0\" " , "vcell = \" 0.1.0\" " ] ;
1010static CRATES_MSP430 : & [ & str ] = & [ "msp430 = \" 0.1.0\" " ] ;
1111static CRATES_CORTEX_M : & [ & str ] = & [ "cortex-m = \" 0.5.0\" " , "cortex-m-rt = \" 0.5.0\" " ] ;
1212static CRATES_RISCV : & [ & str ] = & [ "riscv = \" 0.4.0\" " , "riscv-rt = \" 0.4.0\" " ] ;
1313static PROFILE_ALL : & [ & str ] = & [ "[profile.dev]" , "incremental = false" ] ;
1414static FEATURES_ALL : & [ & str ] = & [ "[features]" ] ;
15- static FEATURES_CORTEX_M : & [ & str ] = & [ "const-fn = [\" bare-metal/const-fn\" , \" cortex-m/const-fn\" ]" ] ;
15+ static FEATURES_CORTEX_M : & [ & str ] =
16+ & [ "const-fn = [\" bare-metal/const-fn\" , \" cortex-m/const-fn\" ]" ] ;
1617static FEATURES_EMPTY : & [ & str ] = & [ ] ;
1718
1819fn path_helper ( input : & [ & str ] ) -> PathBuf {
@@ -66,20 +67,26 @@ impl CommandHelper for Output {
6667 } ;
6768
6869 if cant_fail && !self . status . success ( ) {
69- return Err (
70- ErrorKind :: ProcessFailed ( name. into ( ) ,
71- stdout. cloned ( ) ,
72- stderr. cloned ( ) ,
73- previous_processes_stderr. to_vec ( ) ,
74- ) . into ( )
75- ) ;
70+ return Err ( ErrorKind :: ProcessFailed (
71+ name. into ( ) ,
72+ stdout. cloned ( ) ,
73+ stderr. cloned ( ) ,
74+ previous_processes_stderr. to_vec ( ) ,
75+ )
76+ . into ( ) ) ;
7677 }
7778
7879 Ok ( ( ) )
7980 }
8081}
8182
82- pub fn test ( t : & TestCase , bin_path : & PathBuf , rustfmt_bin_path : Option < & PathBuf > , nightly : bool , verbosity : u8 ) -> Result < Option < Vec < PathBuf > > > {
83+ pub fn test (
84+ t : & TestCase ,
85+ bin_path : & PathBuf ,
86+ rustfmt_bin_path : Option < & PathBuf > ,
87+ nightly : bool ,
88+ verbosity : u8 ,
89+ ) -> Result < Option < Vec < PathBuf > > > {
8390 let user = match std:: env:: var ( "USER" ) {
8491 Ok ( val) => val,
8592 Err ( _) => "rusttester" . into ( ) ,
@@ -90,7 +97,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
9097 if let Err ( err) = fs:: remove_dir_all ( & chip_dir) {
9198 match err. kind ( ) {
9299 std:: io:: ErrorKind :: NotFound => ( ) ,
93- _ => Err ( err) . chain_err ( || "While removing chip directory" ) ?
100+ _ => Err ( err) . chain_err ( || "While removing chip directory" ) ?,
94101 }
95102 }
96103
@@ -151,7 +158,7 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
151158 file_helper ( & svd, & svd_file) ?;
152159
153160 // Generate the lib.rs from the SVD file using the specified `svd2rust` binary
154- // If the architecture is cortex-m we move the generated lib.rs file to src/
161+ // If the architecture is cortex-m or msp430 we move the generated lib.rs file to src/
155162 let lib_rs_file = path_helper_base ( & chip_dir, & [ "src" , "lib.rs" ] ) ;
156163 let svd2rust_err_file = path_helper_base ( & chip_dir, & [ "svd2rust.err.log" ] ) ;
157164 let target = match t. arch {
@@ -173,21 +180,25 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
173180 output. capture_outputs (
174181 true ,
175182 "svd2rust" ,
176- if t. arch != CortexM { Some ( & lib_rs_file ) } else { None } , // use Option.filter
183+ Some ( & lib_rs_file ) . filter ( |_| ( t. arch != CortexM ) && ( t . arch != Msp430 ) ) ,
177184 Some ( & svd2rust_err_file) ,
178185 & [ ] ,
179186 ) ?;
180187 process_stderr_paths. push ( svd2rust_err_file) ;
181188
182- if let CortexM = t. arch {
183- // TODO: Give error the path to stderr
184- fs:: rename ( path_helper_base ( & chip_dir, & [ "lib.rs" ] ) , & lib_rs_file) . chain_err ( || "While moving lib.rs file" ) ?
189+ match t. arch {
190+ CortexM | Msp430 => {
191+ // TODO: Give error the path to stderr
192+ fs:: rename ( path_helper_base ( & chip_dir, & [ "lib.rs" ] ) , & lib_rs_file)
193+ . chain_err ( || "While moving lib.rs file" ) ?
194+ }
195+ _ => { }
185196 }
186197
187198 let rustfmt_err_file = path_helper_base ( & chip_dir, & [ "rustfmt.err.log" ] ) ;
188199 if let Some ( rustfmt_bin_path) = rustfmt_bin_path {
189200 // Run `cargo fmt`, capturing stderr to a log file
190-
201+
191202 let output = Command :: new ( rustfmt_bin_path)
192203 . arg ( lib_rs_file)
193204 . output ( )
@@ -200,7 +211,6 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
200211 & process_stderr_paths,
201212 ) ?;
202213 process_stderr_paths. push ( rustfmt_err_file) ;
203-
204214 }
205215 // Run `cargo check`, capturing stderr to a log file
206216 let cargo_check_err_file = path_helper_base ( & chip_dir, & [ "cargo-check.err.log" ] ) ;
@@ -215,7 +225,11 @@ pub fn test(t: &TestCase, bin_path: &PathBuf, rustfmt_bin_path: Option<&PathBuf>
215225 None ,
216226 Some ( & cargo_check_err_file) ,
217227 & process_stderr_paths,
218- ) ?;
228+ ) ?;
219229 process_stderr_paths. push ( cargo_check_err_file) ;
220- Ok ( if verbosity > 1 { Some ( process_stderr_paths) } else { None } )
230+ Ok ( if verbosity > 1 {
231+ Some ( process_stderr_paths)
232+ } else {
233+ None
234+ } )
221235}
0 commit comments