@@ -29,8 +29,6 @@ mod fixmode {
29
29
30
30
mod settings {
31
31
// can be set as env var to debug
32
- pub const CHECK_JSON : & str = "RUSTFIX_TEST_CHECK_JSON" ;
33
- pub const RECORD_JSON : & str = "RUSTFIX_TEST_RECORD_JSON" ;
34
32
pub const RECORD_FIXED_RUST : & str = "RUSTFIX_TEST_RECORD_FIXED_RUST" ;
35
33
}
36
34
@@ -62,20 +60,6 @@ fn compile(file: &Path, mode: &str) -> Result<Output, Error> {
62
60
Ok ( res)
63
61
}
64
62
65
- fn compile_and_get_json_errors ( file : & Path , mode : & str ) -> Result < String , Error > {
66
- let res = compile ( file, mode) ?;
67
- let stderr = String :: from_utf8 ( res. stderr ) ?;
68
-
69
- match res. status . code ( ) {
70
- Some ( 0 ) | Some ( 1 ) | Some ( 101 ) => Ok ( stderr) ,
71
- _ => Err ( format_err ! (
72
- "failed with status {:?}: {}" ,
73
- res. status. code( ) ,
74
- stderr
75
- ) ) ,
76
- }
77
- }
78
-
79
63
fn compiles_without_errors ( file : & Path , mode : & str ) -> Result < ( ) , Error > {
80
64
let res = compile ( file, mode) ?;
81
65
@@ -122,7 +106,8 @@ fn diff(expected: &str, actual: &str) -> String {
122
106
write ! (
123
107
& mut res,
124
108
"differences found (+ == actual, - == expected):\n "
125
- ) . unwrap ( ) ;
109
+ )
110
+ . unwrap ( ) ;
126
111
different = true ;
127
112
}
128
113
for diff in diff. lines ( ) {
@@ -149,39 +134,12 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
149
134
150
135
debug ! ( "next up: {:?}" , file) ;
151
136
let code = read_file ( file) . context ( format ! ( "could not read {}" , file. display( ) ) ) ?;
152
- let errors = compile_and_get_json_errors ( file , mode )
153
- . context ( format ! ( "could compile {}" , file. display( ) ) ) ?;
137
+ let errors = read_file ( & json_file )
138
+ . with_context ( |_| format ! ( "could not load json suggestions for {}" , file. display( ) ) ) ?;
154
139
let suggestions =
155
140
rustfix:: get_suggestions_from_json ( & errors, & HashSet :: new ( ) , filter_suggestions)
156
141
. context ( "could not load suggestions" ) ?;
157
142
158
- if std:: env:: var ( settings:: RECORD_JSON ) . is_ok ( ) {
159
- use std:: io:: Write ;
160
- let mut recorded_json = fs:: File :: create ( & file. with_extension ( "recorded.json" ) ) . context (
161
- format ! ( "could not create recorded.json for {}" , file. display( ) ) ,
162
- ) ?;
163
- recorded_json. write_all ( errors. as_bytes ( ) ) ?;
164
- }
165
-
166
- if std:: env:: var ( settings:: CHECK_JSON ) . is_ok ( ) {
167
- let expected_json = read_file ( & json_file) . context ( format ! (
168
- "could not load json fixtures for {}" ,
169
- file. display( )
170
- ) ) ?;
171
- let expected_suggestions =
172
- rustfix:: get_suggestions_from_json ( & expected_json, & HashSet :: new ( ) , filter_suggestions)
173
- . context ( "could not load expected suggesitons" ) ?;
174
-
175
- ensure ! (
176
- expected_suggestions == suggestions,
177
- "got unexpected suggestions from clippy:\n {}" ,
178
- diff(
179
- & format!( "{:?}" , expected_suggestions) ,
180
- & format!( "{:?}" , suggestions)
181
- )
182
- ) ;
183
- }
184
-
185
143
let fixed = apply_suggestions ( & code, & suggestions)
186
144
. context ( format ! ( "could not apply suggestions to {}" , file. display( ) ) ) ?;
187
145
0 commit comments