diff options
author | VishnuJin <45007338+VishnuJin@users.noreply.github.com> | 2022-02-15 21:03:21 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-15 16:33:21 +0100 |
commit | 2dc5dba8baf148a525cbb7987cdad0ba6398c5e4 (patch) | |
tree | c75d955be827e4e9215370a52c58fb8ecd6f05f2 /cli/flags.rs | |
parent | d2ab1ed37853b57aab487b9244e477f586b90fca (diff) |
feat(coverage): add "--output" flag (#13289)
This commit adds "--output" to "deno coverage" subcommand.
It can be used instead of piping output to a file.
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index cdf6a9ec9..6bb03b993 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -62,6 +62,7 @@ pub struct CompletionsFlags { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct CoverageFlags { pub files: Vec<PathBuf>, + pub output: Option<PathBuf>, pub ignore: Vec<PathBuf>, pub include: Vec<String>, pub exclude: Vec<String>, @@ -687,7 +688,7 @@ an url to match it must match the include pattern and not match the exclude patt Write a report using the lcov format: - deno coverage --lcov cov_profile > cov.lcov + deno coverage --lcov --output=cov.lcov cov_profile/ Generate html reports from lcov: @@ -730,6 +731,18 @@ Generate html reports from lcov: .help("Output coverage report in lcov format") .takes_value(false), ) + .arg(Arg::new("output") + .requires("lcov") + .long("output") + .help("Output file (defaults to stdout) for lcov") + .long_help("Exports the coverage report in lcov format to the given file. +Filename should be passed along with '=' +For example '--output=foo.lcov' +If no --output arg is specified then the report is written to stdout." + ) + .takes_value(true) + .require_equals(true) + ) .arg( Arg::new("files") .takes_value(true) @@ -1864,8 +1877,10 @@ fn coverage_parse(flags: &mut Flags, matches: &clap::ArgMatches) { None => vec![], }; let lcov = matches.is_present("lcov"); + let output = matches.value_of("output").map(PathBuf::from); flags.subcommand = DenoSubcommand::Coverage(CoverageFlags { files, + output, ignore, include, exclude, @@ -4782,6 +4797,7 @@ mod tests { Flags { subcommand: DenoSubcommand::Coverage(CoverageFlags { files: vec![PathBuf::from("foo.json")], + output: None, ignore: vec![], include: vec![r"^file:".to_string()], exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()], @@ -4793,6 +4809,30 @@ mod tests { } #[test] + fn coverage_with_lcov_and_out_file() { + let r = flags_from_vec(svec![ + "deno", + "coverage", + "--lcov", + "--output=foo.lcov", + "foo.json" + ]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Coverage(CoverageFlags { + files: vec![PathBuf::from("foo.json")], + ignore: vec![], + include: vec![r"^file:".to_string()], + exclude: vec![r"test\.(js|mjs|ts|jsx|tsx)$".to_string()], + lcov: true, + output: Some(PathBuf::from("foo.lcov")), + }), + ..Flags::default() + } + ); + } + #[test] fn location_with_bad_scheme() { #[rustfmt::skip] let r = flags_from_vec(svec!["deno", "run", "--location", "foo:", "mod.ts"]); |