mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(cli): add basic unit tests (#793)
This commit is contained in:
parent
1b5ef7cdc8
commit
4ee56576c7
3 changed files with 53 additions and 2 deletions
1
crates/oxc_cli/fixtures/debugger.js
Normal file
1
crates/oxc_cli/fixtures/debugger.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
debugger;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue