@@ -12,7 +12,7 @@ extern crate failure;
12
12
extern crate difference;
13
13
14
14
use std:: ffi:: OsString ;
15
- use std:: { env , fs } ;
15
+ use std:: fs ;
16
16
use std:: path:: { Path , PathBuf } ;
17
17
use std:: collections:: HashSet ;
18
18
use std:: process:: Output ;
@@ -32,9 +32,6 @@ mod settings {
32
32
pub const CHECK_JSON : & str = "RUSTFIX_TEST_CHECK_JSON" ;
33
33
pub const RECORD_JSON : & str = "RUSTFIX_TEST_RECORD_JSON" ;
34
34
pub const RECORD_FIXED_RUST : & str = "RUSTFIX_TEST_RECORD_FIXED_RUST" ;
35
-
36
- // set automatically
37
- pub const MODE : & str = "RUSTFIX_MODE" ;
38
35
}
39
36
40
37
fn compile ( file : & Path , mode : & str ) -> Result < Output , Error > {
@@ -118,15 +115,15 @@ fn diff(expected: &str, actual: &str) -> String {
118
115
Difference :: Rem ( rem) => ( "-" , rem) ,
119
116
} ;
120
117
if !different {
121
- write ! ( & mut res, "differences found (+ == actual, - == expected):\n " ) ;
118
+ write ! ( & mut res, "differences found (+ == actual, - == expected):\n " ) . unwrap ( ) ;
122
119
different = true ;
123
120
}
124
121
for diff in diff. lines ( ) {
125
- writeln ! ( & mut res, "{} {}" , prefix, diff) ;
122
+ writeln ! ( & mut res, "{} {}" , prefix, diff) . unwrap ( ) ;
126
123
}
127
124
}
128
125
if different {
129
- write ! ( & mut res, "" ) ;
126
+ write ! ( & mut res, "" ) . unwrap ( ) ;
130
127
}
131
128
132
129
res
@@ -137,13 +134,21 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
137
134
let json_file = file. with_extension ( "json" ) ;
138
135
let fixed_file = file. with_extension ( "fixed.rs" ) ;
139
136
137
+ let filter_suggestions = if mode == fixmode:: EVERYTHING {
138
+ rustfix:: Filter :: Everything
139
+ } else {
140
+ rustfix:: Filter :: MachineApplicableOnly
141
+ } ;
142
+
140
143
debug ! ( "next up: {:?}" , file) ;
141
144
let code = read_file ( file)
142
145
. context ( format ! ( "could not read {}" , file. display( ) ) ) ?;
143
146
let errors = compile_and_get_json_errors ( file, mode)
144
147
. context ( format ! ( "could compile {}" , file. display( ) ) ) ?;
145
- let suggestions = rustfix:: get_suggestions_from_json ( & errors, & HashSet :: new ( ) )
146
- . context ( "could not load suggestions" ) ?;
148
+ let suggestions =
149
+ rustfix:: get_suggestions_from_json (
150
+ & errors, & HashSet :: new ( ) , filter_suggestions,
151
+ ) . context ( "could not load suggestions" ) ?;
147
152
148
153
if std:: env:: var ( settings:: RECORD_JSON ) . is_ok ( ) {
149
154
use std:: io:: Write ;
@@ -155,8 +160,10 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
155
160
if std:: env:: var ( settings:: CHECK_JSON ) . is_ok ( ) {
156
161
let expected_json = read_file ( & json_file)
157
162
. context ( format ! ( "could not load json fixtures for {}" , file. display( ) ) ) ?; ;
158
- let expected_suggestions = rustfix:: get_suggestions_from_json ( & expected_json, & HashSet :: new ( ) )
159
- . context ( "could not load expected suggesitons" ) ?;
163
+ let expected_suggestions =
164
+ rustfix:: get_suggestions_from_json (
165
+ & expected_json, & HashSet :: new ( ) , filter_suggestions,
166
+ ) . context ( "could not load expected suggesitons" ) ?;
160
167
161
168
ensure ! (
162
169
expected_suggestions == suggestions,
0 commit comments