From 6e823001c86c10e27f2687e21115fa1d74a90cdc Mon Sep 17 00:00:00 2001 From: l3ops Date: Tue, 8 Nov 2022 17:57:00 +0100 Subject: [PATCH] add tests --- crates/rome_cli/tests/commands/check.rs | 53 ++++++++++++++++++++++++ crates/rome_cli/tests/commands/ci.rs | 53 ++++++++++++++++++++++++ crates/rome_cli/tests/commands/format.rs | 47 +++++++++++++++++++++ 3 files changed, 153 insertions(+) diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index f8f504fe624..03ed983ae64 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -777,3 +777,56 @@ fn files_max_size_parse_error() { result, )); } + +#[test] +fn max_diagnostics_default() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + for i in 0..60 { + let file_path = PathBuf::from(format!("src/file_{i}.js")); + fs.insert(file_path, LINT_ERROR.as_bytes()); + } + + let result = run_cli( + DynRef::Borrowed(&mut fs), + DynRef::Borrowed(&mut console), + Arguments::from_vec(vec![OsString::from("check"), OsString::from("src")]), + ); + + match result { + Err(Termination::CheckError) => {} + _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), + } + + assert_eq!(console.out_buffer.len(), 21); +} + +#[test] +fn max_diagnostics() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + for i in 0..60 { + let file_path = PathBuf::from(format!("src/file_{i}.js")); + fs.insert(file_path, LINT_ERROR.as_bytes()); + } + + let result = run_cli( + DynRef::Borrowed(&mut fs), + DynRef::Borrowed(&mut console), + Arguments::from_vec(vec![ + OsString::from("check"), + OsString::from("--max-diagnostics"), + OsString::from("10"), + Path::new("src").as_os_str().into(), + ]), + ); + + match result { + Err(Termination::CheckError) => {} + _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), + } + + assert_eq!(console.out_buffer.len(), 11); +} diff --git a/crates/rome_cli/tests/commands/ci.rs b/crates/rome_cli/tests/commands/ci.rs index 95c3c89dfa5..67eb66aa9b3 100644 --- a/crates/rome_cli/tests/commands/ci.rs +++ b/crates/rome_cli/tests/commands/ci.rs @@ -511,3 +511,56 @@ fn ci_runs_linter_not_formatter_issue_3495() { result, )); } + +#[test] +fn max_diagnostics_default() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + for i in 0..60 { + let file_path = PathBuf::from(format!("src/file_{i}.js")); + fs.insert(file_path, UNFORMATTED.as_bytes()); + } + + let result = run_cli( + DynRef::Borrowed(&mut fs), + DynRef::Borrowed(&mut console), + Arguments::from_vec(vec![OsString::from("ci"), OsString::from("src")]), + ); + + match result { + Err(Termination::CheckError) => {} + _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), + } + + assert_eq!(console.out_buffer.len(), 51); +} + +#[test] +fn max_diagnostics() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + for i in 0..60 { + let file_path = PathBuf::from(format!("src/file_{i}.js")); + fs.insert(file_path, UNFORMATTED.as_bytes()); + } + + let result = run_cli( + DynRef::Borrowed(&mut fs), + DynRef::Borrowed(&mut console), + Arguments::from_vec(vec![ + OsString::from("ci"), + OsString::from("--max-diagnostics"), + OsString::from("10"), + OsString::from("src"), + ]), + ); + + match result { + Err(Termination::CheckError) => {} + _ => panic!("run_cli returned {result:?} for a failed CI check, expected an error"), + } + + assert_eq!(console.out_buffer.len(), 11); +} diff --git a/crates/rome_cli/tests/commands/format.rs b/crates/rome_cli/tests/commands/format.rs index a5fc0359b3b..16fe0ffc88c 100644 --- a/crates/rome_cli/tests/commands/format.rs +++ b/crates/rome_cli/tests/commands/format.rs @@ -1153,3 +1153,50 @@ fn files_max_size_parse_error() { result, )); } + +#[test] +fn max_diagnostics_default() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + for i in 0..60 { + let file_path = PathBuf::from(format!("src/file_{i}.js")); + fs.insert(file_path, UNFORMATTED.as_bytes()); + } + + let result = run_cli( + DynRef::Borrowed(&mut fs), + DynRef::Borrowed(&mut console), + Arguments::from_vec(vec![OsString::from("format"), OsString::from("src")]), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_eq!(console.out_buffer.len(), 52); +} + +#[test] +fn max_diagnostics() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + for i in 0..60 { + let file_path = PathBuf::from(format!("src/file_{i}.js")); + fs.insert(file_path, UNFORMATTED.as_bytes()); + } + + let result = run_cli( + DynRef::Borrowed(&mut fs), + DynRef::Borrowed(&mut console), + Arguments::from_vec(vec![ + OsString::from("format"), + OsString::from("--max-diagnostics"), + OsString::from("10"), + OsString::from("src"), + ]), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_eq!(console.out_buffer.len(), 12); +}