From 86f80d3ba8d81b29e66ad415219e60c3f1d48a6b Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 2 Aug 2020 15:27:03 +0100 Subject: [PATCH 1/3] pprust: adjust mixed comment printing This commit adjusts the pretty printing of mixed comments so that the initial zero-break isn't emitted at the beginning of the line. Through this, the `block-comment-wchar` test can have the `pp-exact` file removed, as it no longer converges from pretty printing of the source. Signed-off-by: David Wood --- src/librustc_ast_pretty/pprust.rs | 4 +++- src/test/pretty/block-comment-wchar.pp | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs index b0edb1ca41d..4b228629ad7 100644 --- a/src/librustc_ast_pretty/pprust.rs +++ b/src/librustc_ast_pretty/pprust.rs @@ -450,7 +450,9 @@ fn maybe_print_comment(&mut self, pos: BytePos) { fn print_comment(&mut self, cmnt: &comments::Comment) { match cmnt.style { comments::Mixed => { - self.zerobreak(); + if !self.is_beginning_of_line() { + self.zerobreak(); + } if let Some((last, lines)) = cmnt.lines.split_last() { self.ibox(0); diff --git a/src/test/pretty/block-comment-wchar.pp b/src/test/pretty/block-comment-wchar.pp index 9317b36ba49..2bfcdd75e15 100644 --- a/src/test/pretty/block-comment-wchar.pp +++ b/src/test/pretty/block-comment-wchar.pp @@ -73,7 +73,6 @@ fn f() { */ - /* */ /* @@ -81,7 +80,6 @@ fn f() { Space 6+2: compare A Ogham Space Mark 6+2: compare B */ - /* */ /* From c773226aba7d54fc55fdd6244fb6395a5487f656 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 31 Jul 2020 14:53:44 +0100 Subject: [PATCH 2/3] tests: add regression test for #74745 This commit adds a regression test for #74745. While a `ignore-tidy-trailing-lines` header is required, this doesn't stop the test from reproducing, so long as there is no newline at the end of the file. However, adding the header comments made the test fail due to a bug in pprust, fixed in the previous commit. Signed-off-by: David Wood --- src/test/pretty/issue-74745.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/test/pretty/issue-74745.rs diff --git a/src/test/pretty/issue-74745.rs b/src/test/pretty/issue-74745.rs new file mode 100644 index 00000000000..e255cd6caa8 --- /dev/null +++ b/src/test/pretty/issue-74745.rs @@ -0,0 +1,5 @@ +// ignore-tidy-trailing-newlines +// pretty-compare-only + +/* +*/ \ No newline at end of file From 1530563bd7a3880eec14d78e4a715c1bc4e24074 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 2 Aug 2020 15:31:06 +0100 Subject: [PATCH 3/3] compiletest: print diff for pretty tests This commit modifies compiletest so that a diff of actual and expected output is shown for pretty tests. This makes it far easier to work out what has changed. Signed-off-by: David Wood --- src/tools/compiletest/src/runtest.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 9354cc16a9a..940e16720f6 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -178,27 +178,30 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec String { + use std::fmt::Write; + let mut output = String::new(); let diff_results = make_diff(expected, actual, context_size); for result in diff_results { let mut line_number = result.line_number; for line in result.lines { match line { DiffLine::Expected(e) => { - println!("-\t{}", e); + writeln!(output, "-\t{}", e).unwrap(); line_number += 1; } DiffLine::Context(c) => { - println!("{}\t{}", line_number, c); + writeln!(output, "{}\t{}", line_number, c).unwrap(); line_number += 1; } DiffLine::Resulting(r) => { - println!("+\t{}", r); + writeln!(output, "+\t{}", r).unwrap(); } } } - println!(); + writeln!(output, "").unwrap(); } + output } pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { @@ -655,8 +658,12 @@ fn compare_source(&self, expected: &str, actual: &str) { ------------------------------------------\n\ {}\n\ ------------------------------------------\n\ - \n", - expected, actual + diff:\n\ + ------------------------------------------\n\ + {}\n", + expected, + actual, + write_diff(expected, actual, 3), )); } } @@ -3227,7 +3234,7 @@ fn check_mir_dump(&self) { } let expected_string = fs::read_to_string(&expected_file).unwrap(); if dumped_string != expected_string { - print_diff(&expected_string, &dumped_string, 3); + print!("{}", write_diff(&expected_string, &dumped_string, 3)); panic!( "Actual MIR output differs from expected MIR output {}", expected_file.display() @@ -3452,7 +3459,7 @@ fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize { println!("normalized {}:\n{}\n", kind, actual); } else { println!("diff of {}:\n", kind); - print_diff(expected, actual, 3); + print!("{}", write_diff(expected, actual, 3)); } }