Skip to content

Commit

Permalink
More tests/polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Sep 17, 2024
1 parent 3f77c0b commit 4765472
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
4 changes: 0 additions & 4 deletions tests/testthat/helper-profvis.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
TEST_PAUSE_TIME <- 0.050

repro_profvis <- function(expr, ..., rerun = "pause", interval = 0.010) {
inject(profvis({{ expr }}, ..., rerun = rerun, interval = interval))
}

call_stacks <- function(x) {
prof <- x$x$message$prof
stacks <- split(prof$label, prof$time)
Expand Down
37 changes: 25 additions & 12 deletions tests/testthat/test-profvis.R
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
test_that("Irrelevant stack is trimmed from profiles (#123)", {
test_that("irrelevant stack trimmed from function calls (#123)", {
skip_on_cran()
skip_on_covr()

f <- function() pause(TEST_PAUSE_TIME)
g <- function() f()

out <- repro_profvis(f(), simplify = FALSE)
expect_equal(profile_mode(out), "pause f")

out <- profvis(f(), simplify = TRUE, rerun = "pause", interval = 0.005)
expect_equal(profile_mode(out), "pause f")
out <- profvis(g(), simplify = TRUE, rerun = "pause")
expect_equal(profile_mode(out), "pause f g")

out <- repro_profvis(f(), simplify = TRUE)
expect_equal(profile_mode(out), "pause f")
out <- profvis(g(), simplify = FALSE, rerun = "pause")
expect_equal(profile_mode(out), "pause f g")
})

test_that("Irrelevant stack is trimmed from profiles from inlined code", {
test_that("irrelevant stack trimmed from inlined code (#130)", {
skip_on_cran()
skip_on_covr()

out <- profvis(for (i in 1:1e4) rnorm(100), simplify = TRUE)
out <- profvis(for (i in 1:1e4) rnorm(100), simplify = TRUE, rerun = "rnorm")
expect_equal(profile_mode(out), "rnorm")

out <- profvis(for (i in 1:1e4) rnorm(100), simplify = FALSE)
out <- profvis(for (i in 1:1e4) rnorm(100), simplify = FALSE, rerun = "rnorm")
expect_equal(profile_mode(out), "rnorm")
})

test_that("strips stack above profvis", {
skip_on_cran()
skip_on_covr()

f <- function() pause(TEST_PAUSE_TIME)
profvis_wrap <- function(...) profvis(...)

out <- profvis_wrap(f(), simplify = TRUE, rerun = "pause")
expect_equal(profile_mode(out), "pause f")

out <- profvis_wrap(f(), simplify = FALSE, rerun = "pause")
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")
out <- profvis(f(), rerun = "Sys.sleep")
expect_equal(profile_mode(out), "Sys.sleep f")
})

Expand All @@ -41,6 +53,7 @@ test_that("expr and prof_input are mutually exclusive", {
})

test_that("can capture profile of code with error", {
skip_on_cran()
skip_on_covr()

f <- function() {
Expand Down

0 comments on commit 4765472

Please sign in to comment.