From 8eed24cd3d9cea5179c65e43d23fbf6cf4d873ca Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 12 Aug 2022 15:21:17 -0400 Subject: fix(coverage): ensure coverage is only collected in certain situations (#15467) --- cli/args/flags.rs | 6 ++++++ cli/args/mod.rs | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'cli/args') 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, 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 { + 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 { -- cgit v1.2.3