diff options
| author | Caleb Cartwright <caleb.cartwright@outlook.com> | 2020-10-29 22:50:25 -0500 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2020-11-02 18:31:51 -0600 |
| commit | 9faba4539b24ac2db69edd385774d085bb0fd120 (patch) | |
| tree | 926899a142152ef8b30022fb5c4312f5180ad759 /src/test | |
| parent | e131797b62fd52f48fb59296c4c700a97250dee4 (diff) | |
fix(parser): better unclosed delims handling
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/mod.rs | 34 | ||||
| -rw-r--r-- | src/test/parser.rs | 50 |
2 files changed, 52 insertions, 32 deletions
diff --git a/src/test/mod.rs b/src/test/mod.rs index 57b5f2a78cd..9b3ca717152 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -11,14 +11,12 @@ use std::thread; use crate::config::{Color, Config, EmitMode, FileName, NewlineStyle, ReportTactic}; use crate::formatting::{ReportedErrors, SourceFile}; -use crate::modules::{ModuleResolutionError, ModuleResolutionErrorKind}; use crate::rustfmt_diff::{make_diff, print_diff, DiffLine, Mismatch, ModifiedChunk, OutputWriter}; use crate::source_file; -use crate::{ - is_nightly_channel, ErrorKind, FormatReport, FormatReportFormatterBuilder, Input, Session, -}; +use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session}; mod configuration_snippet; +mod parser; const DIFF_CONTEXT_SIZE: usize = 3; @@ -485,34 +483,6 @@ fn format_lines_errors_are_reported_with_tabs() { assert!(session.has_formatting_errors()); } -#[test] -fn parser_errors_in_submods_are_surfaced() { - // See also https://github.com/rust-lang/rustfmt/issues/4126 - let filename = "tests/parser/issue-4126/lib.rs"; - let input_file = PathBuf::from(filename); - let exp_mod_name = "invalid"; - let config = read_config(&input_file); - let mut session = Session::<io::Stdout>::new(config, None); - if let Err(ErrorKind::ModuleResolutionError(ModuleResolutionError { module, kind })) = - session.format(Input::File(filename.into())) - { - assert_eq!(&module, exp_mod_name); - if let ModuleResolutionErrorKind::ParseError { - file: unparseable_file, - } = kind - { - assert_eq!( - unparseable_file, - PathBuf::from("tests/parser/issue-4126/invalid.rs"), - ); - } else { - panic!("Expected parser error"); - } - } else { - panic!("Expected ModuleResolution operation error"); - } -} - // For each file, run rustfmt and collect the output. // Returns the number of files checked and the number of failures. fn check_files(files: Vec<PathBuf>, opt_config: &Option<PathBuf>) -> (Vec<FormatReport>, u32, u32) { diff --git a/src/test/parser.rs b/src/test/parser.rs new file mode 100644 index 00000000000..75aed32e68b --- /dev/null +++ b/src/test/parser.rs @@ -0,0 +1,50 @@ +use std::io; +use std::path::PathBuf; + +use super::read_config; + +use crate::modules::{ModuleResolutionError, ModuleResolutionErrorKind}; +use crate::{ErrorKind, Input, Session}; + +#[test] +fn parser_errors_in_submods_are_surfaced() { + // See also https://github.com/rust-lang/rustfmt/issues/4126 + let filename = "tests/parser/issue-4126/lib.rs"; + let input_file = PathBuf::from(filename); + let exp_mod_name = "invalid"; + let config = read_config(&input_file); + let mut session = Session::<io::Stdout>::new(config, None); + if let Err(ErrorKind::ModuleResolutionError(ModuleResolutionError { module, kind })) = + session.format(Input::File(filename.into())) + { + assert_eq!(&module, exp_mod_name); + if let ModuleResolutionErrorKind::ParseError { + file: unparseable_file, + } = kind + { + assert_eq!( + unparseable_file, + PathBuf::from("tests/parser/issue-4126/invalid.rs"), + ); + } else { + panic!("Expected parser error"); + } + } else { + panic!("Expected ModuleResolution operation error"); + } +} + +fn assert_parser_error(filename: &str) { + let file = PathBuf::from(filename); + let config = read_config(&file); + let mut session = Session::<io::Stdout>::new(config, None); + let _ = session.format(Input::File(filename.into())).unwrap(); + assert!(session.has_parsing_errors()); +} + +#[test] +fn crate_parsing_errors_on_unclosed_delims() { + // See also https://github.com/rust-lang/rustfmt/issues/4466 + let filename = "tests/parser/unclosed-delims/issue_4466.rs"; + assert_parser_error(filename); +} |
