From 235f33b230be1a890e4d9553ddcf02c80b6c4730 Mon Sep 17 00:00:00 2001 From: Sebastian Blunt Date: Sun, 19 Feb 2017 19:57:02 +0100 Subject: [PATCH] Make tests fail if rustfmt encounters an error Previously tests would not fail if they encountered an error such as LineOverflow or TrailingWhitespace. Making the tests error out will fix this mismatch between running rustfmt for real and running the tests. This also modifies all tests that previously contained errors so that they no longer contain errors (in almost all of the tests this is accomplished by setting error_on_line_overflow = false). --- tests/source/comment4.rs | 2 +- tests/source/enum.rs | 1 + tests/source/file-lines-3.rs | 3 ++- tests/source/hard-tabs.rs | 1 + tests/source/imports.rs | 1 + tests/source/issue-913.rs | 4 +++- tests/source/string-lit.rs | 1 + tests/source/string_punctuation.rs | 1 + tests/source/struct_lits.rs | 1 + tests/source/struct_lits_visual.rs | 1 + tests/source/struct_lits_visual_multiline.rs | 1 + tests/source/structs.rs | 1 + tests/system.rs | 4 ++++ tests/target/comment4.rs | 2 +- tests/target/enum.rs | 1 + tests/target/file-lines-3.rs | 3 ++- tests/target/hard-tabs.rs | 1 + tests/target/imports.rs | 1 + tests/target/issue-913.rs | 4 +++- tests/target/string-lit.rs | 1 + tests/target/string_punctuation.rs | 1 + tests/target/struct_lits.rs | 1 + tests/target/struct_lits_visual.rs | 1 + tests/target/struct_lits_visual_multiline.rs | 1 + tests/target/structs.rs | 1 + 25 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/source/comment4.rs b/tests/source/comment4.rs index 69eaa7a681f..0ae5cf4c3f6 100644 --- a/tests/source/comment4.rs +++ b/tests/source/comment4.rs @@ -18,7 +18,7 @@ fn test() { * amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis * felis, pulvinar a semper sed, adipiscing id dolor. */ - // Very looooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split + // Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split // println!("{:?}", rewrite_comment(subslice, // false, diff --git a/tests/source/enum.rs b/tests/source/enum.rs index e55da640d98..70a688428d2 100644 --- a/tests/source/enum.rs +++ b/tests/source/enum.rs @@ -1,4 +1,5 @@ // rustfmt-wrap_comments: true +// rustfmt-error_on_line_overflow: false // Enums test #[atrr] diff --git a/tests/source/file-lines-3.rs b/tests/source/file-lines-3.rs index 29a0e6bb20f..a408fa3ccf6 100644 --- a/tests/source/file-lines-3.rs +++ b/tests/source/file-lines-3.rs @@ -1,4 +1,5 @@ -// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[4,8]},{"file":"tests/source/file-lines-3.rs","range":[10,15]}] +// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[5,9]},{"file":"tests/source/file-lines-3.rs","range":[11,16]}] +// rustfmt-error_on_line_overflow: false fn floaters() { let x = Foo { diff --git a/tests/source/hard-tabs.rs b/tests/source/hard-tabs.rs index 8374b1e70ed..a7173897b0d 100644 --- a/tests/source/hard-tabs.rs +++ b/tests/source/hard-tabs.rs @@ -2,6 +2,7 @@ // rustfmt-single_line_if_else_max_width: 0 // rustfmt-wrap_comments: true // rustfmt-hard_tabs: true +// rustfmt-error_on_line_overflow: false fn main() { let x = Bar; diff --git a/tests/source/imports.rs b/tests/source/imports.rs index adeeba02338..90cb78c2d1f 100644 --- a/tests/source/imports.rs +++ b/tests/source/imports.rs @@ -1,4 +1,5 @@ // rustfmt-normalize_comments: true +// rustfmt-error_on_line_overflow: false // Imports. diff --git a/tests/source/issue-913.rs b/tests/source/issue-913.rs index f58a8b0663b..e1c1b225fa5 100644 --- a/tests/source/issue-913.rs +++ b/tests/source/issue-913.rs @@ -1,3 +1,5 @@ +// rustfmt-error_on_line_overflow: false + mod client { impl Client { fn test(self) -> Result<()> { @@ -10,7 +12,7 @@ fn test(self) -> Result<()> { let next_state = match self.state { State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => { // The pattern cannot be formatted in a way that the match stays - // within the column limit. The rewrite should therefore be + // within the column limit. The rewrite should therefore be // skipped. let x = dont . reformat . meeee(); } diff --git a/tests/source/string-lit.rs b/tests/source/string-lit.rs index 59547cbe62f..eb3fb7012e4 100644 --- a/tests/source/string-lit.rs +++ b/tests/source/string-lit.rs @@ -1,4 +1,5 @@ // rustfmt-force_format_strings: true +// rustfmt-error_on_line_overflow: false // Long string literals fn main() -> &'static str { diff --git a/tests/source/string_punctuation.rs b/tests/source/string_punctuation.rs index efbadebb083..6a0afd45e5a 100644 --- a/tests/source/string_punctuation.rs +++ b/tests/source/string_punctuation.rs @@ -1,4 +1,5 @@ // rustfmt-format_strings: true +// rustfmt-error_on_line_overflow: false fn main() { println!("ThisIsAReallyLongStringWithNoSpaces.It_should_prefer_to_break_onpunctuation:Likethisssssssssssss"); diff --git a/tests/source/struct_lits.rs b/tests/source/struct_lits.rs index c5aaf7ef881..3a8016367b6 100644 --- a/tests/source/struct_lits.rs +++ b/tests/source/struct_lits.rs @@ -1,5 +1,6 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true +// rustfmt-error_on_line_overflow: false // Struct literal expressions. fn main() { diff --git a/tests/source/struct_lits_visual.rs b/tests/source/struct_lits_visual.rs index 1ea26522ea7..9156328dd0f 100644 --- a/tests/source/struct_lits_visual.rs +++ b/tests/source/struct_lits_visual.rs @@ -1,6 +1,7 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual +// rustfmt-error_on_line_overflow: false // Struct literal expressions. diff --git a/tests/source/struct_lits_visual_multiline.rs b/tests/source/struct_lits_visual_multiline.rs index 57714ed989b..16c06934c28 100644 --- a/tests/source/struct_lits_visual_multiline.rs +++ b/tests/source/struct_lits_visual_multiline.rs @@ -2,6 +2,7 @@ // rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual // rustfmt-struct_lit_multiline_style: ForceMulti +// rustfmt-error_on_line_overflow: false // Struct literal expressions. diff --git a/tests/source/structs.rs b/tests/source/structs.rs index cdcccda39a5..d24b2ba1a77 100644 --- a/tests/source/structs.rs +++ b/tests/source/structs.rs @@ -1,5 +1,6 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true +// rustfmt-error_on_line_overflow: false /// A Doc comment #[AnAttribute] diff --git a/tests/system.rs b/tests/system.rs index a2a4c0eeedf..d01a4892024 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -179,6 +179,10 @@ fn check_files(files: I) -> (Vec, u32, u32) println!("Testing '{}'...", file_name); match idempotent_check(file_name) { + Ok(ref report) if report.has_warnings() => { + print!("{}", report); + fails += 1; + } Ok(report) => reports.push(report), Err(msg) => { print_mismatches(msg); diff --git a/tests/target/comment4.rs b/tests/target/comment4.rs index 08f84bb861d..2916f083ca0 100644 --- a/tests/target/comment4.rs +++ b/tests/target/comment4.rs @@ -18,7 +18,7 @@ fn test() { * amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis * felis, pulvinar a semper sed, adipiscing id dolor. */ - // Very looooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split + // Very loooooooooooooooooooooooooooooooooooooooooooooooooooooooong comment that should be split // println!("{:?}", rewrite_comment(subslice, // false, diff --git a/tests/target/enum.rs b/tests/target/enum.rs index 5b3960014b6..9121221c9c4 100644 --- a/tests/target/enum.rs +++ b/tests/target/enum.rs @@ -1,4 +1,5 @@ // rustfmt-wrap_comments: true +// rustfmt-error_on_line_overflow: false // Enums test #[atrr] diff --git a/tests/target/file-lines-3.rs b/tests/target/file-lines-3.rs index d8096dccd67..6652d9c92cd 100644 --- a/tests/target/file-lines-3.rs +++ b/tests/target/file-lines-3.rs @@ -1,4 +1,5 @@ -// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[4,8]},{"file":"tests/source/file-lines-3.rs","range":[10,15]}] +// rustfmt-file_lines: [{"file":"tests/source/file-lines-3.rs","range":[5,9]},{"file":"tests/source/file-lines-3.rs","range":[11,16]}] +// rustfmt-error_on_line_overflow: false fn floaters() { let x = Foo { diff --git a/tests/target/hard-tabs.rs b/tests/target/hard-tabs.rs index 43b00774a22..9a84159663e 100644 --- a/tests/target/hard-tabs.rs +++ b/tests/target/hard-tabs.rs @@ -2,6 +2,7 @@ // rustfmt-single_line_if_else_max_width: 0 // rustfmt-wrap_comments: true // rustfmt-hard_tabs: true +// rustfmt-error_on_line_overflow: false fn main() { let x = Bar; diff --git a/tests/target/imports.rs b/tests/target/imports.rs index 6b1d75d7f20..570b5225da7 100644 --- a/tests/target/imports.rs +++ b/tests/target/imports.rs @@ -1,4 +1,5 @@ // rustfmt-normalize_comments: true +// rustfmt-error_on_line_overflow: false // Imports. diff --git a/tests/target/issue-913.rs b/tests/target/issue-913.rs index c7aee5fe3ab..98f766e7310 100644 --- a/tests/target/issue-913.rs +++ b/tests/target/issue-913.rs @@ -1,3 +1,5 @@ +// rustfmt-error_on_line_overflow: false + mod client { impl Client { fn test(self) -> Result<()> { @@ -10,7 +12,7 @@ fn test(self) -> Result<()> { let next_state = match self.state { State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => { // The pattern cannot be formatted in a way that the match stays - // within the column limit. The rewrite should therefore be + // within the column limit. The rewrite should therefore be // skipped. let x = dont . reformat . meeee(); } diff --git a/tests/target/string-lit.rs b/tests/target/string-lit.rs index 4fba80e1c51..bbca3fe097e 100644 --- a/tests/target/string-lit.rs +++ b/tests/target/string-lit.rs @@ -1,4 +1,5 @@ // rustfmt-force_format_strings: true +// rustfmt-error_on_line_overflow: false // Long string literals fn main() -> &'static str { diff --git a/tests/target/string_punctuation.rs b/tests/target/string_punctuation.rs index d82e1143bc9..f53e149b923 100644 --- a/tests/target/string_punctuation.rs +++ b/tests/target/string_punctuation.rs @@ -1,4 +1,5 @@ // rustfmt-format_strings: true +// rustfmt-error_on_line_overflow: false fn main() { println!("ThisIsAReallyLongStringWithNoSpaces.It_should_prefer_to_break_onpunctuation:\ diff --git a/tests/target/struct_lits.rs b/tests/target/struct_lits.rs index 05840b703d3..a42d8e7aada 100644 --- a/tests/target/struct_lits.rs +++ b/tests/target/struct_lits.rs @@ -1,5 +1,6 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true +// rustfmt-error_on_line_overflow: false // Struct literal expressions. fn main() { diff --git a/tests/target/struct_lits_visual.rs b/tests/target/struct_lits_visual.rs index a9c682af15b..7a0abb480e8 100644 --- a/tests/target/struct_lits_visual.rs +++ b/tests/target/struct_lits_visual.rs @@ -1,6 +1,7 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual +// rustfmt-error_on_line_overflow: false // Struct literal expressions. diff --git a/tests/target/struct_lits_visual_multiline.rs b/tests/target/struct_lits_visual_multiline.rs index 30d8815514b..02bbfa18784 100644 --- a/tests/target/struct_lits_visual_multiline.rs +++ b/tests/target/struct_lits_visual_multiline.rs @@ -2,6 +2,7 @@ // rustfmt-wrap_comments: true // rustfmt-struct_lit_style: Visual // rustfmt-struct_lit_multiline_style: ForceMulti +// rustfmt-error_on_line_overflow: false // Struct literal expressions. diff --git a/tests/target/structs.rs b/tests/target/structs.rs index 40b410c072b..2969438eadd 100644 --- a/tests/target/structs.rs +++ b/tests/target/structs.rs @@ -1,5 +1,6 @@ // rustfmt-normalize_comments: true // rustfmt-wrap_comments: true +// rustfmt-error_on_line_overflow: false /// A Doc comment #[AnAttribute] -- 2.44.0