File: test-progress-handlers.R

package info (click to toggle)
r-cran-cli 3.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: ansic: 16,412; cpp: 37; sh: 13; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,684 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

test_that("cli_progress_builtin_handlers", {
  expect_true(is.character(cli_progress_builtin_handlers()))
  expect_true(all(
    c("cli", "shiny", "rstudio") %in% cli_progress_builtin_handlers()
  ))
})

test_that("cli_progress_select_handlers #1", {
  # only handlers
  withr::local_options(
    "cli.progress_handlers" = c("foo", "bar"),
    "cli.progress_handlers_force" = c("forced"),
    "cli.progress_handlers_only" = "logger"
  )
  expect_equal(
    names(cli_progress_select_handlers(list(), environment())),
    "logger"
  )
})

test_that("cli_progress_select_handlers #2", {
  # auto-select
  withr::local_options(
    "cli.progress_handlers" = c("foo", "bar", "baz"),
    "cli.progress_handlers_force" = NULL,
    "cli.progress_handlers_only" = NULL
  )
  fake <- list(
    foo = list(able = function(...) FALSE),
    bar = list(),
    baz = list(),
    forced = list()
  )
  local_mocked_bindings(builtin_handlers = function() fake)
  expect_equal(cli_progress_select_handlers(), fake["bar"])
})

test_that("cli_progress_select_handlers #3", {
  # auto-select
  withr::local_options(
    "cli.progress_handlers" = c("foo", "bar", "baz"),
    "cli.progress_handlers_force" = c("forced"),
    "cli.progress_handlers_only" = NULL
  )
  fake <- list(
    foo = list(able = function(...) FALSE),
    bar = list(able = function(...) TRUE),
    baz = list(),
    forced = list()
  )
  local_mocked_bindings(builtin_handlers = function() fake)
  expect_equal(cli_progress_select_handlers(), fake[c("bar", "forced")])
})

test_that("builtin_handlers", {
  expect_true(is.list(builtin_handlers()))
  expect_true(all(c("cli", "shiny", "rstudio") %in% names(builtin_handlers())))
})