diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-08-12 15:21:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-12 15:21:17 -0400 |
commit | 8eed24cd3d9cea5179c65e43d23fbf6cf4d873ca (patch) | |
tree | 3047d60a9f8e972a601de011460dee151ad4c558 /cli/args | |
parent | ee2f4e745c33797ac9fd20571e77cef73ea585bf (diff) |
fix(coverage): ensure coverage is only collected in certain situations (#15467)
Diffstat (limited to 'cli/args')
-rw-r--r-- | cli/args/flags.rs | 6 | ||||
-rw-r--r-- | cli/args/mod.rs | 21 |
2 files changed, 25 insertions, 2 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 9feef54b0..f47d5b121 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -162,6 +162,12 @@ pub struct RunFlags { pub script: String, } +impl RunFlags { + pub fn is_stdin(&self) -> bool { + self.script == "-" + } +} + #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct TaskFlags { pub cwd: Option<String>, diff --git a/cli/args/mod.rs b/cli/args/mod.rs index ecbc53db7..85e44aca2 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -278,8 +278,25 @@ impl CliOptions { self.flags.compat } - pub fn coverage_dir(&self) -> Option<&String> { - self.flags.coverage_dir.as_ref() + pub fn coverage_dir(&self) -> Option<String> { + fn allow_coverage(sub_command: &DenoSubcommand) -> bool { + match sub_command { + DenoSubcommand::Test(_) => true, + DenoSubcommand::Run(flags) => !flags.is_stdin(), + _ => false, + } + } + + if allow_coverage(self.sub_command()) { + self + .flags + .coverage_dir + .as_ref() + .map(ToOwned::to_owned) + .or_else(|| env::var("DENO_UNSTABLE_COVERAGE_DIR").ok()) + } else { + None + } } pub fn enable_testing_features(&self) -> bool { |