diff --git a/tests/testthat/test-ansi-hyperlink.R b/tests/testthat/test-ansi-hyperlink.R index 8e74e785..8b4de70f 100644 --- a/tests/testthat/test-ansi-hyperlink.R +++ b/tests/testthat/test-ansi-hyperlink.R @@ -290,8 +290,8 @@ test_that("ansi_has_hyperlink_support", { expect_false(ansi_has_hyperlink_support()) # are we in rstudio with support? - local_mocked_bindings(num_ansi_colors = function() 257L) local_mocked_bindings( + num_ansi_colors = function() 257L, rstudio_detect = function() list(type = "rstudio_console", hyperlink = TRUE) ) expect_true(ansi_has_hyperlink_support()) @@ -299,26 +299,30 @@ test_that("ansi_has_hyperlink_support", { test_that("ansi_has_hyperlink_support 2", { local_clean_cli_context() - local_mocked_bindings(num_ansi_colors = function() 256L) - - local_mocked_bindings(isatty = function(...) FALSE) + local_mocked_bindings( + num_ansi_colors = function() 256L, + isatty = function(...) FALSE + ) expect_false(ansi_has_hyperlink_support()) }) test_that("ansi_has_hyperlink_support 3", { local_clean_cli_context() - local_mocked_bindings(num_ansi_colors = function() 256L) - - local_mocked_bindings(isatty = function(...) TRUE) - local_mocked_bindings(is_windows = function() TRUE) + local_mocked_bindings( + num_ansi_colors = function() 256L, + isatty = function(...) TRUE, + is_windows = function() TRUE + ) withr::local_envvar(WT_SESSION = "4c464723-f51f-4612-83f7-31e1c75abd83") expect_true(ansi_has_hyperlink_support()) }) test_that("ansi_has_hyperlink_support 4", { local_clean_cli_context() - local_mocked_bindings(num_ansi_colors = function() 256L) - local_mocked_bindings(isatty = function(...) TRUE) + local_mocked_bindings( + num_ansi_colors = function() 256L, + isatty = function(...) TRUE + ) withr::local_envvar("CI" = "true") expect_false(ansi_has_hyperlink_support()) @@ -329,8 +333,10 @@ test_that("ansi_has_hyperlink_support 4", { test_that("ansi_has_hyperlink_support 5", { local_clean_cli_context() - local_mocked_bindings(num_ansi_colors = function() 256L) - local_mocked_bindings(isatty = function(...) TRUE) + local_mocked_bindings( + num_ansi_colors = function() 256L, + isatty = function(...) TRUE + ) withr::local_envvar( TERM_PROGRAM = "iTerm.app", @@ -341,8 +347,10 @@ test_that("ansi_has_hyperlink_support 5", { test_that("ansi_has_hyperlink_support 5", { local_clean_cli_context() - local_mocked_bindings(num_ansi_colors = function() 256L) - local_mocked_bindings(isatty = function(...) TRUE) + local_mocked_bindings( + num_ansi_colors = function() 256L, + isatty = function(...) TRUE + ) withr::local_envvar(VTE_VERSION = "0.51.1") expect_true(ansi_has_hyperlink_support()) diff --git a/tests/testthat/test-format-conditions.R b/tests/testthat/test-format-conditions.R index c62a0178..9056d554 100644 --- a/tests/testthat/test-format-conditions.R +++ b/tests/testthat/test-format-conditions.R @@ -61,9 +61,7 @@ test_that_cli("format_message", { test_that_cli(configs = "ansi", "color in RStudio", { local_mocked_bindings( - rstudio_detect = function() list(type = "rstudio_console", num_colors = 256) - ) - local_mocked_bindings( + rstudio_detect = function() list(type = "rstudio_console", num_colors = 256), get_rstudio_theme = function() list(foreground = "rgb(0, 0, 0)") ) expect_snapshot({ diff --git a/tests/testthat/test-num-ansi-colors.R b/tests/testthat/test-num-ansi-colors.R index 28974242..29a5b3f1 100644 --- a/tests/testthat/test-num-ansi-colors.R +++ b/tests/testthat/test-num-ansi-colors.R @@ -48,9 +48,11 @@ test_that("cli.default_num_colors #2", { cli.default_num_colors = NULL ) - local_mocked_bindings(os_type = function() "windows") - local_mocked_bindings(commandArgs = function() "--ess") - local_mocked_bindings(is_emacs_with_color = function() TRUE) + local_mocked_bindings( + os_type = function() "windows", + commandArgs = function() "--ess", + is_emacs_with_color = function() TRUE + ) expect_equal(num_ansi_colors(), 8L) @@ -75,8 +77,10 @@ test_that("cli.default_num_colors #4", { # Unix emacs with color withr::local_envvar(COLORTERM = NA_character_) - local_mocked_bindings(os_type = function() "unix") - local_mocked_bindings(is_emacs_with_color = function() TRUE) + local_mocked_bindings( + os_type = function() "unix", + is_emacs_with_color = function() TRUE + ) withr::local_options(cli.default_num_colors = NULL) @@ -91,12 +95,12 @@ test_that("cli.default_num_colors #5", { # rstudio terminal on Windows withr::local_envvar(COLORTERM = NA_character_) - local_mocked_bindings(os_type = function() "windows") - local_mocked_bindings(win10_build = function() 10586) local_mocked_bindings( - rstudio_detect = function() list(type = "rstudio_terminal") + os_type = function() "windows", + win10_build = function() 10586, + rstudio_detect = function() list(type = "rstudio_terminal"), + system2 = function(...) TRUE ) - local_mocked_bindings(system2 = function(...) TRUE) withr::local_options(cli.default_num_colors = NULL) expect_equal(detect_tty_colors(), 8L) @@ -111,12 +115,12 @@ test_that("cli.default_num_colors #6", { withr::local_envvar(COLORTERM = NA_character_) withr::local_options(cli.default_num_colors = NULL) - local_mocked_bindings(os_type = function() "windows") - local_mocked_bindings(win10_build = function() 10586) local_mocked_bindings( - rstudio_detect = function() list(type = "not_rstudio") + os_type = function() "windows", + win10_build = function() 10586, + rstudio_detect = function() list(type = "not_rstudio"), + system2 = function(...) TRUE ) - local_mocked_bindings(system2 = function(...) TRUE) expect_equal(detect_tty_colors(), 256L) local_mocked_bindings(win10_build = function() 14931) @@ -134,8 +138,10 @@ test_that("cli.default_num_colors #7", { ConEmuANSI = "ON" ) withr::local_options(cli.default_num_colors = NULL) - local_mocked_bindings(os_type = function() "windows") - local_mocked_bindings(win10_build = function() 1) + local_mocked_bindings( + os_type = function() "windows", + win10_build = function() 1 + ) expect_equal(detect_tty_colors(), 8L) withr::local_options(cli.default_num_colors = 123L) @@ -150,9 +156,11 @@ test_that("cli.default_num_colors #8", { TERM = "xterm" ) - local_mocked_bindings(os_type = function() "unix") - local_mocked_bindings(is_emacs_with_color = function() FALSE) - local_mocked_bindings(system = function(...) "8") + local_mocked_bindings( + os_type = function() "unix", + is_emacs_with_color = function() FALSE, + system = function(...) "8" + ) withr::local_options(cli.default_num_colors = NULL) expect_equal(detect_tty_colors(), 256L) @@ -167,8 +175,10 @@ test_that("ESS_BACKGROUND_MODE", { ESS_BACKGROUND_MODE = NA_character_ ) - local_mocked_bindings(is_iterm = function() FALSE) - local_mocked_bindings(is_emacs = function() TRUE) + local_mocked_bindings( + is_iterm = function() FALSE, + is_emacs = function() TRUE + ) expect_false(detect_dark_theme("auto")) diff --git a/tests/testthat/test-rlang-errors.R b/tests/testthat/test-rlang-errors.R index 761f849c..db37c54f 100644 --- a/tests/testthat/test-rlang-errors.R +++ b/tests/testthat/test-rlang-errors.R @@ -94,9 +94,7 @@ test_that("cli_abort width in RStudio", { test_that_cli(configs = "ansi", "color in RStudio", { local_mocked_bindings( - rstudio_detect = function() list(type = "rstudio_console", num_colors = 256) - ) - local_mocked_bindings( + rstudio_detect = function() list(type = "rstudio_console", num_colors = 256), get_rstudio_theme = function() list(foreground = "rgb(0, 0, 0)") ) expect_snapshot({ diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 9e273935..10368873 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -80,8 +80,8 @@ test_that("is_latex_output", { local_mocked_bindings(loadedNamespaces = function() "foobar") expect_false(is_latex_output()) - local_mocked_bindings(loadedNamespaces = function() "knitr") local_mocked_bindings( + loadedNamespaces = function() "knitr", get = function(x, ...) { if (x == "is_latex_output") { function() TRUE