Merge pull request #279 from epage/fix

fix(cli): Don't panic
This commit is contained in:
Ed Page 2021-06-07 08:03:32 -05:00 committed by GitHub
commit 083020270c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 7 deletions

View file

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header --> <!-- next-header -->
## [Unreleased] - ReleaseDate ## [Unreleased] - ReleaseDate
#### Bug Fixes
- Fix the prior `typos <file>` fix that broke all other forms
- Extend the fix to other modes (`--dump-config`, etc)
## [1.0.5] - 2021-06-05 ## [1.0.5] - 2021-06-05
#### Bug Fixes #### Bug Fixes

View file

@ -66,11 +66,13 @@ fn run_dump_config(args: &args::Args, output_path: &std::path::Path) -> proc_exi
let path = &args.path[0]; let path = &args.path[0];
let cwd = if path == std::path::Path::new("-") { let cwd = if path == std::path::Path::new("-") {
global_cwd.as_path() global_cwd
} else if path.is_file() { } else if path.is_file() {
path.parent().unwrap() let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
cwd.pop();
cwd
} else { } else {
path.as_path() path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
}; };
let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?; let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
@ -108,11 +110,13 @@ fn run_type_list(args: &args::Args) -> proc_exit::ExitResult {
let path = &args.path[0]; let path = &args.path[0];
let cwd = if path == std::path::Path::new("-") { let cwd = if path == std::path::Path::new("-") {
global_cwd.as_path() global_cwd
} else if path.is_file() { } else if path.is_file() {
path.parent().unwrap() let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
cwd.pop();
cwd
} else { } else {
path.as_path() path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
}; };
let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?; let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
@ -178,7 +182,7 @@ fn run_checks(
cwd.pop(); cwd.pop();
cwd cwd
} else { } else {
path.clone() path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
}; };
engine engine

View file

@ -29,3 +29,16 @@ fn test_file_failure() {
cmd.arg("README.md"); cmd.arg("README.md");
cmd.assert().code(2); cmd.assert().code(2);
} }
#[test]
fn test_relative_dir_failure() {
let mut cmd = Command::cargo_bin("typos").unwrap();
cmd.arg(".");
cmd.assert().code(2);
}
#[test]
fn test_assumed_dir_failure() {
let mut cmd = Command::cargo_bin("typos").unwrap();
cmd.assert().code(2);
}