1
1
use errors:: * ;
2
- use std :: io :: prelude :: * ;
2
+ use reqwest ;
3
3
use std:: fs:: { remove_dir_all, File , OpenOptions } ;
4
+ use std:: io:: prelude:: * ;
5
+ use std:: path:: PathBuf ;
4
6
use std:: process:: { Command , Output } ;
5
7
use tests:: TestCase ;
6
- use reqwest;
7
- use std:: path:: PathBuf ;
8
8
9
9
static CRATES_ALL : & [ & str ] = & [ "bare-metal = \" 0.1.0\" " , "vcell = \" 0.1.0\" " ] ;
10
10
static CRATES_MSP430 : & [ & str ] = & [ "msp430 = \" 0.1.0\" " ] ;
@@ -50,25 +50,25 @@ impl CommandHelper for Output {
50
50
stdout : Option < & PathBuf > ,
51
51
stderr : Option < & PathBuf > ,
52
52
) -> Result < ( ) > {
53
- if cant_fail && !self . status . success ( ) {
54
- bail ! ( format!( "Process Failed! - {}" , name) )
55
- }
56
-
57
53
if let Some ( out) = stdout {
58
54
let out_payload = String :: from_utf8_lossy ( & self . stdout ) ;
59
55
file_helper ( & out_payload, out) ?;
60
- }
56
+ } ;
61
57
62
58
if let Some ( err) = stderr {
63
59
let err_payload = String :: from_utf8_lossy ( & self . stderr ) ;
64
60
file_helper ( & err_payload, err) ?;
61
+ } ;
62
+
63
+ if cant_fail && !self . status . success ( ) {
64
+ return Err ( ErrorKind :: ProcessFailed ( name. into ( ) , stdout. cloned ( ) , stderr. cloned ( ) ) . into ( ) )
65
65
}
66
66
67
67
Ok ( ( ) )
68
68
}
69
69
}
70
70
71
- pub fn test ( t : & TestCase , bin_path : & PathBuf ) -> Result < ( ) > {
71
+ pub fn test ( t : & TestCase , bin_path : & PathBuf , rustfmt_bin_path : Option < & PathBuf > ) -> Result < ( ) > {
72
72
let user = match :: std:: env:: var ( "USER" ) {
73
73
Ok ( val) => val,
74
74
Err ( _) => "rusttester" . into ( ) ,
@@ -135,10 +135,8 @@ pub fn test(t: &TestCase, bin_path: &PathBuf) -> Result<()> {
135
135
& RiscV => "riscv" ,
136
136
} ;
137
137
Command :: new ( bin_path)
138
- . arg ( "-i" )
139
- . arg ( & chip_svd)
140
- . arg ( "--target" )
141
- . arg ( target)
138
+ . args ( & [ "-i" , & chip_svd] )
139
+ . args ( & [ "--target" , & target] )
142
140
. current_dir ( & chip_dir)
143
141
. output ( )
144
142
. chain_err ( || "failed to execute process" ) ?
@@ -149,16 +147,15 @@ pub fn test(t: &TestCase, bin_path: &PathBuf) -> Result<()> {
149
147
Some ( & svd2rust_err_file) ,
150
148
) ?;
151
149
152
- // TODO: rustfmt < 0.4.0 seems to mangle some doc comments. Omit until this is fixed
153
- // Run `cargo fmt`, capturing stderr to a log file
154
- // let cargo_fmt_err_file = path_helper_base(&chip_dir, &["cargo-fmt.err.log"]);
155
- // Command::new("cargo")
156
- // .arg("fmt")
157
- // .current_dir(&chip_dir)
158
- // .output()
159
- // .chain_err(|| "failed to format")?
160
- // .capture_outputs(false, "cargo fmt", None, Some(&cargo_fmt_err_file))?;
161
-
150
+ if let Some ( rustfmt_bin_path) = rustfmt_bin_path {
151
+ // Run `cargo fmt`, capturing stderr to a log file
152
+ let fmt_err_file = path_helper_base ( & chip_dir, & [ "rustfmt.err.log" ] ) ;
153
+ Command :: new ( rustfmt_bin_path)
154
+ . arg ( lib_rs_file)
155
+ . output ( )
156
+ . chain_err ( || "failed to format" ) ?
157
+ . capture_outputs ( false , "rustfmt" , None , Some ( & fmt_err_file) ) ?;
158
+ }
162
159
// Run `cargo check`, capturing stderr to a log file
163
160
let cargo_check_err_file = path_helper_base ( & chip_dir, & [ "cargo-check.err.log" ] ) ;
164
161
Command :: new ( "cargo" )
0 commit comments