Skip to content

Commit

Permalink
feat(coverage): add default coverage include dir (denoland#21625)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k committed Dec 18, 2023
1 parent 5b2caed commit 6b482d7
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ pub struct CompletionsFlags {
pub buf: Box<[u8]>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub enum CoverageType {
#[default]
Summary,
Detailed,
Lcov,
Html,
}

#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct CoverageFlags {
pub files: FileFlags,
pub output: Option<PathBuf>,
Expand Down Expand Up @@ -1422,10 +1423,9 @@ Generate html reports from lcov:
)
.arg(
Arg::new("files")
.num_args(1..)
.num_args(0..)
.value_parser(value_parser!(PathBuf))
.action(ArgAction::Append)
.required(true)
.value_hint(ValueHint::AnyPath),
)
})
Expand Down Expand Up @@ -3307,9 +3307,10 @@ fn completions_parse(
}

fn coverage_parse(flags: &mut Flags, matches: &mut ArgMatches) {
let default_files = vec![PathBuf::from("coverage")];
let files = match matches.remove_many::<PathBuf>("files") {
Some(f) => f.collect(),
None => vec![],
None => default_files,
};
let ignore = match matches.remove_many::<PathBuf>("ignore") {
Some(f) => f.collect(),
Expand Down Expand Up @@ -7914,10 +7915,9 @@ mod tests {
include: vec![PathBuf::from("foo.json")],
ignore: vec![],
},
output: None,
include: vec![r"^file:".to_string()],
exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()],
r#type: CoverageType::Summary
..CoverageFlags::default()
}),
..Flags::default()
}
Expand Down Expand Up @@ -7950,6 +7950,27 @@ mod tests {
}
);
}

#[test]
fn coverage_with_default_files() {
let r = flags_from_vec(svec!["deno", "coverage",]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Coverage(CoverageFlags {
files: FileFlags {
include: vec![PathBuf::from("coverage")],
ignore: vec![],
},
include: vec![r"^file:".to_string()],
exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()],
..CoverageFlags::default()
}),
..Flags::default()
}
);
}

#[test]
fn location_with_bad_scheme() {
#[rustfmt::skip]
Expand Down

0 comments on commit 6b482d7

Please sign in to comment.