Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leops committed Nov 8, 2022
1 parent 2e1bca2 commit 6e82300
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
53 changes: 53 additions & 0 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
53 changes: 53 additions & 0 deletions crates/rome_cli/tests/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
47 changes: 47 additions & 0 deletions crates/rome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 6e82300

Please sign in to comment.