@@ -12,7 +12,7 @@ extern crate failure;
1212extern crate difference;
1313
1414use std:: ffi:: OsString ;
15- use std:: { env , fs } ;
15+ use std:: fs ;
1616use std:: path:: { Path , PathBuf } ;
1717use std:: collections:: HashSet ;
1818use std:: process:: Output ;
@@ -32,9 +32,6 @@ mod settings {
3232 pub const CHECK_JSON : & str = "RUSTFIX_TEST_CHECK_JSON" ;
3333 pub const RECORD_JSON : & str = "RUSTFIX_TEST_RECORD_JSON" ;
3434 pub const RECORD_FIXED_RUST : & str = "RUSTFIX_TEST_RECORD_FIXED_RUST" ;
35-
36- // set automatically
37- pub const MODE : & str = "RUSTFIX_MODE" ;
3835}
3936
4037fn compile ( file : & Path , mode : & str ) -> Result < Output , Error > {
@@ -118,15 +115,15 @@ fn diff(expected: &str, actual: &str) -> String {
118115 Difference :: Rem ( rem) => ( "-" , rem) ,
119116 } ;
120117 if !different {
121- write ! ( & mut res, "differences found (+ == actual, - == expected):\n " ) ;
118+ write ! ( & mut res, "differences found (+ == actual, - == expected):\n " ) . unwrap ( ) ;
122119 different = true ;
123120 }
124121 for diff in diff. lines ( ) {
125- writeln ! ( & mut res, "{} {}" , prefix, diff) ;
122+ writeln ! ( & mut res, "{} {}" , prefix, diff) . unwrap ( ) ;
126123 }
127124 }
128125 if different {
129- write ! ( & mut res, "" ) ;
126+ write ! ( & mut res, "" ) . unwrap ( ) ;
130127 }
131128
132129 res
@@ -137,13 +134,21 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
137134 let json_file = file. with_extension ( "json" ) ;
138135 let fixed_file = file. with_extension ( "fixed.rs" ) ;
139136
137+ let filter_suggestions = if mode == fixmode:: EVERYTHING {
138+ rustfix:: Filter :: Everything
139+ } else {
140+ rustfix:: Filter :: MachineApplicableOnly
141+ } ;
142+
140143 debug ! ( "next up: {:?}" , file) ;
141144 let code = read_file ( file)
142145 . context ( format ! ( "could not read {}" , file. display( ) ) ) ?;
143146 let errors = compile_and_get_json_errors ( file, mode)
144147 . 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" ) ?;
147152
148153 if std:: env:: var ( settings:: RECORD_JSON ) . is_ok ( ) {
149154 use std:: io:: Write ;
@@ -155,8 +160,10 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
155160 if std:: env:: var ( settings:: CHECK_JSON ) . is_ok ( ) {
156161 let expected_json = read_file ( & json_file)
157162 . 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" ) ?;
160167
161168 ensure ! (
162169 expected_suggestions == suggestions,
0 commit comments