diff options
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 { |