Skip to content

Commit 29e490c

Browse files
committed
better code coverage
and rename subcommands struct to something more descriptive
1 parent 19b36ee commit 29e490c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

cpp-linter/src/cli/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ pub struct Cli {
5858
pub not_ignored: Option<Vec<String>>,
5959

6060
#[command(subcommand)]
61-
pub commands: Option<SubCommand>,
61+
pub commands: Option<CliCommand>,
6262
}
6363

6464
#[derive(Debug, Subcommand, Clone)]
65-
pub enum SubCommand {
65+
pub enum CliCommand {
6666
/// Display the version of cpp-linter and exit.
6767
Version,
6868
}

cpp-linter/src/run.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use log::{set_max_level, LevelFilter};
1414

1515
// project specific modules/crates
1616
use crate::clang_tools::capture_clang_tools_output;
17-
use crate::cli::{ClangParams, Cli, FeedbackInput, LinesChangedOnly, SubCommand};
17+
use crate::cli::{ClangParams, Cli, CliCommand, FeedbackInput, LinesChangedOnly};
1818
use crate::common_fs::FileFilter;
1919
use crate::logger;
2020
use crate::rest_api::{github::GithubApiClient, RestApiClient};
@@ -43,7 +43,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
4343
pub async fn run_main(args: Vec<String>) -> Result<()> {
4444
let cli = Cli::parse_from(args);
4545

46-
if matches!(cli.commands, Some(SubCommand::Version)) {
46+
if matches!(cli.commands, Some(CliCommand::Version)) {
4747
println!("cpp-linter v{}", VERSION);
4848
return Ok(());
4949
}
@@ -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)