fix(cli): Ensure we can run on files

This commit is contained in:
Ed Page 2021-06-05 13:46:40 -05:00
parent 6e8f7cf9d3
commit 60fe94c292
2 changed files with 12 additions and 4 deletions

View file

@ -172,13 +172,14 @@ fn run_checks(
let mut errors_found = false;
for path in args.path.iter() {
let cwd = if path == std::path::Path::new("-") {
global_cwd.as_path()
global_cwd.clone()
} else if path.is_file() {
path.parent().unwrap()
let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
cwd.pop();
cwd
} else {
path.as_path()
path.clone()
};
let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
engine
.init_dir(&cwd)

View file

@ -22,3 +22,10 @@ fn test_stdin_correct() {
.write_stdin("Apropriate world");
cmd.assert().success().stdout("Appropriate world");
}
#[test]
fn test_file_failure() {
let mut cmd = Command::cargo_bin("typos").unwrap();
cmd.arg("README.md");
cmd.assert().code(2);
}