File: test-profvis.R

package info (click to toggle)
r-cran-profvis 0.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 868 kB
  • sloc: javascript: 1,943; ansic: 41; sh: 13; makefile: 8
file content (65 lines) | stat: -rw-r--r-- 1,757 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 <- profvis(g(), simplify = TRUE, rerun = "pause")
  expect_equal(profile_mode(out), "pause f g")

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

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, rerun = "rnorm")
  expect_equal(profile_mode(out), "rnorm")

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

test_that("expr and prof_input are mutually exclusive", {
  expect_snapshot(profvis(expr = f(), prof_input = "foo.R"), error = TRUE)
})

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

  f <- function() {
    pause(TEST_PAUSE_TIME)
    stop("error")
  }
  expect_snapshot(out <- profvis(f(), rerun = "pause"))
  expect_equal(profile_mode(out), "pause f")
})