Skip to content

Commit 6c687cb

Browse files
committed
---
yaml --- r: 3903 b: refs/heads/master c: b9635df h: refs/heads/master i: 3901: f85b6e3 3899: 2a8719a 3895: 4ca980e 3887: 3e36109 3871: 8663147 3839: 6e467bf v: v3
1 parent 7d53f6f commit 6c687cb

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 7885bdc5750b10cab267052284df1f8bfc284fa8
2+
refs/heads/master: b9635df6fef51f9611ecc9fbb6c3edb71a968286

trunk/src/fuzzer/fuzzer.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ fn read_whole_file(&str filename) -> str {
4949
str::unsafe_from_bytes(io::file_reader(filename).read_whole_stream())
5050
}
5151

52+
fn write_file(&str filename, &str content) {
53+
io::file_writer(filename, [io::create]).write_str(content);
54+
}
55+
5256
fn file_contains(&str filename, &str needle) -> bool {
5357
auto contents = read_whole_file(filename);
5458
ret str::find(contents, needle) != -1;
@@ -160,8 +164,8 @@ fn pp_variants(&ast::crate crate, &codemap::codemap cmap, &str filename) {
160164
}
161165
}
162166

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()));
165169
auto cm4 = codemap::new_codemap();
166170
if (true
167171
&& !contains(str3, "][]") // https://github.com/graydon/rust/issues/669
@@ -171,25 +175,29 @@ fn check_roundtrip(@ast::crate crate2, &codemap::codemap cmap, &str fakefilename
171175
&& !contains(str3, "spawn") // more precedence issues
172176
&& !contains(str3, "bind") // more precedence issues?
173177
) {
174-
auto crate4 = parser::parse_crate_from_source_str(fakefilename, str3, ~[], cm4);
178+
auto crate4 = parser::parse_crate_from_source_str(filename, str3, ~[], cm4);
175179
// 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()));
177181
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???
179183
} 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";
184188
}
185189
}
186190
}
187191

188192
fn main(vec[str] args) {
193+
if (vec::len(args) != 2u) {
194+
log_err #fmt("usage: %s <testdir>", args.(0));
195+
ret;
196+
}
189197
auto files = ~[];
190-
auto root = "/Users/jruderman/code/rust/src/"; // XXX
198+
auto root = args.(1);
191199
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));
193201

194202
for (str file in files) {
195203
log_err "=== " + file + " ===";
@@ -200,7 +208,7 @@ fn main(vec[str] args) {
200208
&& !str::ends_with(file, "block-expr-precedence.rs") // https://github.com/graydon/rust/issues/674
201209
&& !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"???
202210
) {
203-
check_roundtrip(crate, cm, file + ".pp.rs");
211+
check_roundtrip(crate, cm, file);
204212
}
205213
//pprust::print_crate(cm, crate, file, devnull(), pprust::no_ann());
206214
// Currently hits https://github.com/graydon/rust/issues/675

0 commit comments

Comments
 (0)