diff --git a/crates/oxc_cli/fixtures/debugger.js b/crates/oxc_cli/fixtures/debugger.js new file mode 100644 index 000000000..eab746921 --- /dev/null +++ b/crates/oxc_cli/fixtures/debugger.js @@ -0,0 +1 @@ +debugger; diff --git a/crates/oxc_cli/src/command.rs b/crates/oxc_cli/src/command.rs index 766014ade..8647a538e 100644 --- a/crates/oxc_cli/src/command.rs +++ b/crates/oxc_cli/src/command.rs @@ -187,8 +187,9 @@ pub struct CheckOptions { #[bpaf(positional("PATH"))] pub path: PathBuf, } -#[cfg(all(test, not(target_os = "windows")))] // windows binary has an`.exe` extension, which - // invalidates the snapshots + +// windows binary has an`.exe` extension, which invalidates the snapshots +#[cfg(all(test, not(target_os = "windows")))] mod snapshot { use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; use std::process::Command; diff --git a/crates/oxc_cli/src/lint/mod.rs b/crates/oxc_cli/src/lint/mod.rs index 40e974f86..69b7d7da3 100644 --- a/crates/oxc_cli/src/lint/mod.rs +++ b/crates/oxc_cli/src/lint/mod.rs @@ -84,3 +84,52 @@ impl Runner for LintRunner { } } } + +#[cfg(all(test, not(target_os = "windows")))] +mod test { + use super::LintRunner; + use crate::{lint_command, CliRunResult, Runner}; + + fn test(args: &[&str]) -> CliRunResult { + let options = lint_command().run_inner(args).unwrap().lint_options; + LintRunner::new(options).run() + } + + #[test] + fn dir() { + let args = &["--quiet", "fixtures"]; + let CliRunResult::LintResult { + number_of_rules, + number_of_files, + number_of_warnings, + number_of_errors, + .. + } = test(args) + else { + unreachable!() + }; + assert!(number_of_rules > 0); + assert_eq!(number_of_files, 1); + assert_eq!(number_of_warnings, 1); + assert_eq!(number_of_errors, 0); + } + + #[test] + fn file() { + let args = &["--quiet", "fixtures/debugger.js"]; + let CliRunResult::LintResult { + number_of_rules, + number_of_files, + number_of_warnings, + number_of_errors, + .. + } = test(args) + else { + unreachable!() + }; + assert!(number_of_rules > 0); + assert_eq!(number_of_files, 1); + assert_eq!(number_of_warnings, 1); + assert_eq!(number_of_errors, 0); + } +}