feat(cli): add basic unit tests (#793)

This commit is contained in:
Boshen 2023-08-25 21:26:14 +08:00 committed by GitHub
parent 1b5ef7cdc8
commit 4ee56576c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 2 deletions

View file

@ -0,0 +1 @@
debugger;

View file

@ -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;

View file

@ -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);
}
}