]> git.lizzy.rs Git - rust.git/blobdiff - tests/system.rs
return non-zero exit code if there were errors
[rust.git] / tests / system.rs
index 6b13e77a7be40dd906f0af45922e3e9052612bcf..2a6b1a9e19c15323dd573d3fd96efec11568166c 100644 (file)
@@ -143,10 +143,20 @@ fn self_tests() {
 fn stdin_formatting_smoke_test() {
     let input = Input::Text("fn main () {}".to_owned());
     let config = Config::default();
-    let (file_map, _report) = format_input(input, &config);
+    let (error_summary, file_map, _report) = format_input(input, &config);
+    assert!(error_summary.has_no_errors());
     assert_eq!(file_map["stdin"].to_string(), "fn main() {}\n")
 }
 
+#[test]
+fn format_lines_errors_are_reported() {
+    let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap();
+    let input = Input::Text(format!("fn {}() {{}}", long_identifier));
+    let config = Config::default();
+    let (error_summary, _file_map, _report) = format_input(input, &config);
+    assert!(error_summary.has_formatting_errors());
+}
+
 // For each file, run rustfmt and collect the output.
 // Returns the number of files checked and the number of failures.
 fn check_files<I>(files: I) -> (Vec<FormatReport>, u32, u32)
@@ -202,7 +212,8 @@ fn read_config(filename: &str) -> Config {
 
 fn format_file<P: Into<PathBuf>>(filename: P, config: &Config) -> (FileMap, FormatReport) {
     let input = Input::File(filename.into());
-    format_input(input, &config)
+    let (_error_summary, file_map, report) = format_input(input, &config);
+    return (file_map, report);
 }
 
 pub fn idempotent_check(filename: String) -> Result<FormatReport, HashMap<String, Vec<Mismatch>>> {