Skip to content

Commit 44da60a

Browse files
committed
better code coverage
1 parent 19b36ee commit 44da60a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cpp-linter/src/run.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
5757
}
5858

5959
if cli.source_options.repo_root != "." {
60-
env::set_current_dir(Path::new(&cli.source_options.repo_root)).unwrap_or_else(|_| {
61-
panic!(
62-
"'{}' is inaccessible or does not exist",
60+
env::set_current_dir(Path::new(&cli.source_options.repo_root)).map_err(|e| {
61+
anyhow!(
62+
"'{}' is inaccessible or does not exist: {e:?}",
6363
cli.source_options.repo_root
6464
)
65-
});
65+
})?;
6666
}
6767

6868
let rest_api_client = GithubApiClient::new()?;
@@ -240,4 +240,16 @@ mod test {
240240
.await;
241241
assert!(result.is_ok());
242242
}
243+
244+
#[tokio::test]
245+
async fn bad_repo_root() {
246+
env::remove_var("GITHUB_OUTPUT"); // avoid writing to GH_OUT in parallel-running tests
247+
let result = run_main(vec![
248+
"cpp-linter".to_string(),
249+
"-r".to_string(),
250+
"some-non-existent-dir".to_string(),
251+
])
252+
.await;
253+
assert!(result.is_err());
254+
}
243255
}

0 commit comments

Comments
 (0)