@@ -49,6 +49,10 @@ fn read_whole_file(&str filename) -> str {
49
49
str:: unsafe_from_bytes ( io:: file_reader ( filename) . read_whole_stream ( ) )
50
50
}
51
51
52
+ fn write_file ( & str filename , & str content ) {
53
+ io:: file_writer ( filename, [ io:: create] ) . write_str ( content) ;
54
+ }
55
+
52
56
fn file_contains ( & str filename , & str needle ) -> bool {
53
57
auto contents = read_whole_file ( filename) ;
54
58
ret str:: find ( contents, needle) != -1 ;
@@ -160,8 +164,8 @@ fn pp_variants(&ast::crate crate, &codemap::codemap cmap, &str filename) {
160
164
}
161
165
}
162
166
163
- fn check_roundtrip( @ast:: crate crate2, & codemap:: codemap cmap, & str fakefilename ) {
164
- auto str3 = as_str( bind pprust:: print_crate( cmap, crate2, "empty.rs" , _, pprust:: no_ann( ) ) ) ;
167
+ fn check_roundtrip( @ast:: crate crate2, & codemap:: codemap cmap, & str filename ) {
168
+ auto str3 = as_str( bind pprust:: print_crate( cmap, crate2, filename , _, pprust:: no_ann( ) ) ) ;
165
169
auto cm4 = codemap:: new_codemap( ) ;
166
170
if ( true
167
171
&& !contains( str3, "][]" ) // https://github.com/graydon/rust/issues/669
@@ -171,25 +175,29 @@ fn check_roundtrip(@ast::crate crate2, &codemap::codemap cmap, &str fakefilename
171
175
&& !contains( str3, "spawn" ) // more precedence issues
172
176
&& !contains( str3, "bind" ) // more precedence issues?
173
177
) {
174
- auto crate4 = parser:: parse_crate_from_source_str( fakefilename , str3, ~[ ] , cm4) ;
178
+ auto crate4 = parser:: parse_crate_from_source_str( filename , str3, ~[ ] , cm4) ;
175
179
// should compare crates at this point, but it's easier to compare strings
176
- auto str5 = as_str( bind pprust:: print_crate( cmap, crate4, "empty.rs" , _, pprust:: no_ann( ) ) ) ;
180
+ auto str5 = as_str( bind pprust:: print_crate( cmap, crate4, filename , _, pprust:: no_ann( ) ) ) ;
177
181
if ( !str:: is_ascii( str3) ) {
178
- log_err "Non-ASCII in " + fakefilename ; // why does non-ASCII work correctly with "rustc --pretty normal" but not here???
182
+ log_err "Non-ASCII in " + filename ; // why does non-ASCII work correctly with "rustc --pretty normal" but not here???
179
183
} else if ( str3 ! = str5) {
180
- log_err "Mismatch: " + fakefilename ;
181
- log_err "str3: \n " + str3 ;
182
- log_err "str5: \n " + str5 ;
183
- fail "Mismatch" ;
184
+ write_file ( "round-trip-a.rs" , str3 ) ;
185
+ write_file ( "round-trip-b.rs" , str5 ) ;
186
+ std :: run :: run_program ( "kdiff3" , [ "round-trip-a.rs" , "round-trip-b.rs" ] ) ;
187
+ fail "Mismatch" ;
184
188
}
185
189
}
186
190
}
187
191
188
192
fn main( vec[ str ] args) {
193
+ if ( vec:: len( args) != 2 u) {
194
+ log_err #fmt( "usage: %s <testdir>" , args. ( 0 ) ) ;
195
+ ret;
196
+ }
189
197
auto files = ~[ ] ;
190
- auto root = "/Users/jruderman/code/rust/src/" ; // XXX
198
+ auto root = args . ( 1 ) ;
191
199
find_rust_files( files, root) ; // not using time here because that currently screws with passing-a-mutable-array
192
- log_err uint :: str ( ivec:: len( files) ) + " files" ;
200
+ log_err #fmt ( "%u files" , ivec:: len( files) ) ;
193
201
194
202
for ( str file in files) {
195
203
log_err "=== " + file + " ===" ;
@@ -200,7 +208,7 @@ fn main(vec[str] args) {
200
208
&& !str:: ends_with( file, "block-expr-precedence.rs" ) // https://github.com/graydon/rust/issues/674
201
209
&& !str:: ends_with( file, "syntax-extension-fmt.rs" ) // an issue where -2147483648 gains an extra negative sign each time through, which i can't reproduce using "rustc --pretty normal"???
202
210
) {
203
- check_roundtrip( crate , cm, file + ".pp.rs" ) ;
211
+ check_roundtrip( crate , cm, file) ;
204
212
}
205
213
//pprust::print_crate(cm, crate, file, devnull(), pprust::no_ann());
206
214
// Currently hits https://github.com/graydon/rust/issues/675
0 commit comments