File: test-progress-utils.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 (43 lines) | stat: -rw-r--r-- 1,053 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

test_that("cli_progress_num", {
  withr::local_options(cli.progress_handlers_only = "cli")
  fun <- function() {
    before <- cli_progress_num()
    cli_progress_bar()
    after <- cli_progress_num()
    expect_equal(before + 1, after)
  }

  capture_cli_messages(fun())
})

test_that("cli_progress_cleanup", {
  fun <- function() {
    num <- NULL
    cli::cli_progress_bar()
    fun2 <- function() {
      cli::cli_progress_bar()
      cli::cli_progress_cleanup()
      num <<- cli::cli_progress_num()
    }
    fun2()
  }

  out <- callr::r(fun)
  expect_equal(out, 0L)
})

test_that("should_run_progress_examples", {
  withr::local_envvar(NOT_CRAN = "true")
  expect_true(should_run_progress_examples())

  local_mocked_bindings(is_rcmd_check = function() TRUE)
  expect_false(should_run_progress_examples())
})

test_that("is_rcmd_check", {
  withr::local_envvar(NOT_CRAN = NA, "_R_CHECK_PACKAGE_NAME_" = NA)
  expect_false(is_rcmd_check())
  withr::local_envvar(NOT_CRAN = NA, "_R_CHECK_PACKAGE_NAME_" = "cli")
  expect_true(is_rcmd_check())
})