From 2933414a8dce80432fa29f5b4149d541d25595bf Mon Sep 17 00:00:00 2001 From: Paul Lietar Date: Thu, 18 Jan 2024 12:34:41 +0000 Subject: [PATCH] Avoid looking at the RStudio state when running tests inside of it. --- R/interactive.R | 3 ++- R/util.R | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/interactive.R b/R/interactive.R index 332ef7dd..98d9ea30 100644 --- a/R/interactive.R +++ b/R/interactive.R @@ -7,7 +7,8 @@ is_plausible_orderly_report <- function(path) { } rstudio_get_current_active_editor_path <- function() { - if (rstudioapi::isAvailable()) { + # Avoid looking at the RStudio state when running tests inside of it. + if (!is_testing() && rstudioapi::isAvailable()) { rstudioapi::getSourceEditorContext()$path } else { NULL diff --git a/R/util.R b/R/util.R index 5faa86c2..e5b41785 100644 --- a/R/util.R +++ b/R/util.R @@ -641,3 +641,10 @@ paths_are_different <- function(x, y) { x_real != y_real }, error = function(e) FALSE) } + + +is_testing <- function() { + # Copied from testthat, to avoid having the package as a run-time dependency. + # https://github.com/r-lib/testthat/blob/fe50a222c62cc8733b397690caf3b2a95856f902/R/test-env.R#L20 + identical(Sys.getenv("TESTTHAT"), "true") +}