Skip to content

Commit

Permalink
Improved helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Sep 12, 2024
1 parent 1e12a0c commit 9061761
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions tests/testthat/helper-profvis.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
12 changes: 6 additions & 6 deletions tests/testthat/test-profvis.R
Original file line number Diff line number Diff line change
@@ -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")
})

0 comments on commit 9061761

Please sign in to comment.