From a5a35795e0243c0a1f3a531fb305c076e7bc0e84 Mon Sep 17 00:00:00 2001 From: MEO265 <99362508+meo265@users.noreply.github.com> Date: Sun, 1 Jun 2025 18:51:20 +0200 Subject: [PATCH 1/3] Add test for call_2_string with `full_stack=FALSE` --- tests/testthat/test-utils.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 6439d1f..6379b45 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -210,6 +210,13 @@ test_that("call_2_string (full_stack=TRUE) handels call not in current context", ) }) +test_that("call_2_string (full_stack=FALSE) handels call not in current context", { + ext_call <- quote(some_function(1L, 2L)) + expect_true( + endsWith(call_2_string(ext_call, full_stack = FALSE), "some_function(1L, 2L)") + ) +}) + test_that("test call_2_string (cut off) via condition handler", { old <- set_call_options(log_call = TRUE, full_stack = TRUE, confirm = FALSE) # Function is needed to create a predictable call stack and a call to cut off From 8689dbf85e5c0b23addbeb4fe1d66452a80154d7 Mon Sep 17 00:00:00 2001 From: MEO265 <99362508+meo265@users.noreply.github.com> Date: Sun, 1 Jun 2025 19:50:02 +0200 Subject: [PATCH 2/3] Add tests for call option configuration and its effect on call handlers --- tests/testthat/test-configurations.R | 113 +++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/tests/testthat/test-configurations.R b/tests/testthat/test-configurations.R index dce9ccd..fee3d03 100644 --- a/tests/testthat/test-configurations.R +++ b/tests/testthat/test-configurations.R @@ -151,3 +151,116 @@ test_that("test call option configuration", { expect_silent(old <- set_call_options(.arg_list = list(log_call = FALSE, full_stack = FALSE), confirm = FALSE)) expect_identical(old, list(log_call = FALSE, full_stack = TRUE)) }) +cleanup() + +test_that("test call option configuration (effect on call handlers)", { + old <- set_call_options(log_call = TRUE, full_stack = FALSE, confirm = FALSE) + on.exit(set_call_options(.arg_list = old, confirm = FALSE)) + # Test loggit (via function call to garantee a call object) + f <- function() loggit(log_lvl = "DEBUG", log_msg = "Test message with call", echo = FALSE) + g <- function() f() + g() + log_tmp <- read_logs() + expect_true(is.na(log_tmp[["log_call"]])) + cleanup() + # Test debuginfo + f <- function() debuginfo("Test message with call", echo = FALSE) + g <- function() f() + g() + log_tmp <- read_logs() + expect_identical(log_tmp[["log_call"]], "f()") + cleanup() + # Test message + f <- function() message("Test message with call", echo = FALSE) + g <- function() f() + suppressMessages(g()) + log_tmp <- read_logs() + # Message uses an alternative call approach + expect_identical(log_tmp[["log_call"]], "message(\"Test message with call\", echo = FALSE)") + cleanup() + # Test warning + f <- function() warning("Test message with call", echo = FALSE) + g <- function() f() + suppressWarnings(g()) + log_tmp <- read_logs() + expect_identical(log_tmp[["log_call"]], "f()") + cleanup() + # Test error + f <- function() stop("Test message with call", echo = FALSE) + g <- function() f() + try(g(), silent = TRUE) + log_tmp <- read_logs() + expect_identical(log_tmp[["log_call"]], "f()") + cleanup() + # Test stopifnot + f <- function() stopifnot(FALSE, "Test message with call", echo = FALSE) + g <- function() f() + try(g(), silent = TRUE) + log_tmp <- read_logs() + expect_identical(log_tmp[["log_call"]], "f()") +}) +cleanup() + +test_that("test call option configuration (effect on call handlers) II", { + old <- set_call_options(log_call = FALSE, confirm = FALSE) + on.exit(set_call_options(.arg_list = old, confirm = FALSE)) + # Test loggit (via function call to garantee a call object) + loggit(log_lvl = "DEBUG", log_msg = "Test message with call", echo = FALSE) + debuginfo("Test message with call", echo = FALSE) + suppressMessages(message("Test message with call", echo = FALSE)) + suppressWarnings(warning("Test message with call", echo = FALSE)) + try(stop("Test message with call", echo = FALSE), silent = TRUE) + try(stopifnot(FALSE, "Test message with call", echo = FALSE), silent = TRUE) + log_tmp <- read_logs() + expect_true(!"log_call" %in% names(log_tmp)) +}) +cleanup() + + +test_that("test call option configuration (effect on call handlers) III", { + old <- set_call_options(log_call = TRUE, full_stack = TRUE, confirm = FALSE) + on.exit(set_call_options(.arg_list = old, confirm = FALSE)) + # Test loggit (via function call to garantee a call object) + f <- function() loggit(log_lvl = "DEBUG", log_msg = "Test message with call", echo = FALSE) + g <- function() f() + g() + log_tmp <- read_logs() + expect_true(is.na(log_tmp[["log_call"]])) + cleanup() + # Test debuginfo + f <- function() debuginfo("Test message with call", echo = FALSE) + g <- function() f() + g() + log_tmp <- read_logs() + expect_true(grepl(log_tmp[["log_call"]], pattern = "\ng().*\nf()")) + cleanup() + # Test message + f <- function() message("Test message with call", echo = FALSE) + g <- function() f() + suppressMessages(g()) + log_tmp <- read_logs() + # Message uses an alternative call approach + expect_true(grepl(log_tmp[["log_call"]], pattern = "\ng\\(\\).*\nmessage\\(\"Test message with call\", echo = FALSE\\)")) + cleanup() + # Test warning + f <- function() warning("Test message with call", echo = FALSE) + g <- function() f() + suppressWarnings(g()) + log_tmp <- read_logs() + expect_true(grepl(log_tmp[["log_call"]], pattern = "\ng().*\nf()")) + cleanup() + # Test error + f <- function() stop("Test message with call", echo = FALSE) + g <- function() f() + try(g(), silent = TRUE) + log_tmp <- read_logs() + expect_true(grepl(log_tmp[["log_call"]], pattern = "\ng().*\nf()")) + cleanup() + # Test stopifnot + f <- function() stopifnot(FALSE, "Test message with call", echo = FALSE) + g <- function() f() + try(g(), silent = TRUE) + log_tmp <- read_logs() + expect_true(grepl(log_tmp[["log_call"]], pattern = "\ng().*\nf()")) +}) +cleanup() \ No newline at end of file From a9c661c0af287d7b24891193cd105ebe43e609de Mon Sep 17 00:00:00 2001 From: MEO265 <99362508+meo265@users.noreply.github.com> Date: Sun, 1 Jun 2025 19:54:33 +0200 Subject: [PATCH 3/3] Lint --- tests/testthat/test-configurations.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-configurations.R b/tests/testthat/test-configurations.R index fee3d03..6a1f37d 100644 --- a/tests/testthat/test-configurations.R +++ b/tests/testthat/test-configurations.R @@ -212,7 +212,7 @@ test_that("test call option configuration (effect on call handlers) II", { try(stop("Test message with call", echo = FALSE), silent = TRUE) try(stopifnot(FALSE, "Test message with call", echo = FALSE), silent = TRUE) log_tmp <- read_logs() - expect_true(!"log_call" %in% names(log_tmp)) + expect_false("log_call" %in% names(log_tmp)) }) cleanup() @@ -240,7 +240,9 @@ test_that("test call option configuration (effect on call handlers) III", { suppressMessages(g()) log_tmp <- read_logs() # Message uses an alternative call approach - expect_true(grepl(log_tmp[["log_call"]], pattern = "\ng\\(\\).*\nmessage\\(\"Test message with call\", echo = FALSE\\)")) + expect_true(grepl( + log_tmp[["log_call"]], pattern = "\ng\\(\\).*\nmessage\\(\"Test message with call\", echo = FALSE\\)" + )) cleanup() # Test warning f <- function() warning("Test message with call", echo = FALSE) @@ -263,4 +265,4 @@ test_that("test call option configuration (effect on call handlers) III", { log_tmp <- read_logs() expect_true(grepl(log_tmp[["log_call"]], pattern = "\ng().*\nf()")) }) -cleanup() \ No newline at end of file +cleanup()