1pub(crate) mod diff;
4pub(crate) mod lint_markers;
5pub(crate) mod merge;
6
7use anyhow::Result;
8use clap::{Parser, Subcommand};
9
10#[derive(Parser)]
12pub struct CoverageCommand {
13 #[command(subcommand)]
15 pub command: CoverageSubcommands,
16
17 #[command(flatten)]
19 pub repo: crate::cli::repo_arg::RepoArg,
20}
21
22#[derive(Subcommand)]
24pub enum CoverageSubcommands {
25 Diff(Box<diff::DiffCommand>),
27 LintMarkers(lint_markers::LintMarkersCommand),
29 Merge(merge::MergeCommand),
31}
32
33impl CoverageCommand {
34 pub fn execute(self) -> Result<()> {
39 let repo = self.repo.path();
40 match self.command {
41 CoverageSubcommands::Diff(cmd) => cmd.execute(repo),
42 CoverageSubcommands::LintMarkers(cmd) => cmd.execute(repo),
43 CoverageSubcommands::Merge(cmd) => cmd.execute(repo),
44 }
45 }
46}
47
48#[cfg(test)]
49#[allow(clippy::unwrap_used, clippy::expect_used)]
50mod tests {
51 use super::*;
52
53 #[test]
56 fn dispatches_to_diff() {
57 let cmd = CoverageCommand {
58 command: CoverageSubcommands::Diff(Box::new(diff::DiffCommand {
59 report: vec![std::path::PathBuf::from("/nonexistent/report.lcov")],
60 report_format: diff::ReportFormat::Auto,
61 base_ref: Some("HEAD".to_string()),
62 head_ref: None,
63 baseline_report: None,
64 baseline_report_format: diff::ReportFormat::Auto,
65 output: diff::OutputFormatArg::Markdown,
66 format: None,
67 fail_under_patch: None,
68 fail_under_lines: None,
69 strip_prefix: None,
70 ignore_filename_regex: Vec::new(),
71 context_dir: None,
72 collapse_ranges: false,
73 all_files: false,
74 artifact_url: None,
75 run_url: None,
76 base_sha: None,
77 head_sha: None,
78 commit_url: None,
79 })),
80 repo: crate::cli::repo_arg::RepoArg::default(),
81 };
82 assert!(cmd.execute().is_err());
84 }
85
86 #[test]
89 fn dispatches_to_merge() {
90 let dir = tempfile::tempdir().unwrap();
91 let output = dir.path().join("merged.lcov");
92 let cmd = CoverageCommand {
93 command: CoverageSubcommands::Merge(merge::MergeCommand {
94 report: vec![dir.path().join("missing.lcov")],
95 report_format: diff::ReportFormat::Auto,
96 output: output.clone(),
97 strip_prefix: None,
98 }),
99 repo: crate::cli::repo_arg::RepoArg::default(),
100 };
101 assert!(cmd.execute().is_err());
102 assert!(!output.exists());
103 }
104}