From 9061761ea51c1cef0978f5cc48df0caf200b41c0 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 12 Sep 2024 16:04:50 -0500 Subject: [PATCH] Improved helpers --- tests/testthat/helper-profvis.R | 10 +++++++--- tests/testthat/test-profvis.R | 12 ++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/testthat/helper-profvis.R b/tests/testthat/helper-profvis.R index 98760ef4..44d29ebb 100644 --- a/tests/testthat/helper-profvis.R +++ b/tests/testthat/helper-profvis.R @@ -20,8 +20,12 @@ zap_trailing_space <- function(lines) { gsub(" $", "", lines) } -profvis_modal_value <- function(prof) { +profile_calls <- function(x) { + prof <- x$x$message$prof stacks <- split(prof$label, prof$time) - stacks <- vapply(stacks, paste, "", collapse = " ") - modal_value0(stacks) + vapply(stacks, paste, "", collapse = " ") +} + +profile_mode <- function(x) { + modal_value0(profile_calls(x)) } diff --git a/tests/testthat/test-profvis.R b/tests/testthat/test-profvis.R index 1706555f..3120170f 100644 --- a/tests/testthat/test-profvis.R +++ b/tests/testthat/test-profvis.R @@ -1,26 +1,26 @@ test_that("Irrelevant stack is trimmed from profiles (#123)", { skip_on_cran() skip_on_covr() - + f <- function() pause(TEST_PAUSE_TIME) out <- repro_profvis(f(), simplify = FALSE) - expect_equal(profvis_modal_value(out$x$message$prof), "pause f") + expect_equal(profile_mode(out), "pause f") out <- profvis(f(), simplify = TRUE, rerun = "pause", interval = 0.005) - expect_equal(profvis_modal_value(out$x$message$prof), "pause f") + expect_equal(profile_mode(out), "pause f") out <- repro_profvis(f(), simplify = TRUE) - expect_equal(profvis_modal_value(out$x$message$prof), "pause f") + expect_equal(profile_mode(out), "pause f") }) test_that("defaults to elapsed timing", { skip_on_cran() skip_on_covr() skip_if_not(has_event()) - + f <- function() Sys.sleep(TEST_PAUSE_TIME) out <- repro_profvis(f(), rerun = "Sys.sleep") - expect_equal(profvis_modal_value(out$x$message$prof), "Sys.sleep f") + expect_equal(profile_mode(out), "Sys.sleep f") })