Examples for 'cli::test_that_cli'


Test cli output with testthat

Aliases: test_that_cli

Keywords:

### ** Examples

# testthat cannot record or compare snapshots when you run these
# examples interactively, so you might want to copy them into a test
# file

# Default configurations
cli::test_that_cli("success", {
  testthat::local_edition(3)
  testthat::expect_snapshot({
    cli::cli_alert_success("wow")
  })
})
Can't compare snapshot to reference when testing interactively
i Run `devtools::test()` or `testthat::test_file()` to see changes
i Current value:
Code
  cli::cli_alert_success("wow")
Message <cliMessage>
  v wow
── Skip (scripts.R:45:16): success [plain] ─────────────────────────────────────
Reason: empty test
Can't compare snapshot to reference when testing interactively
i Run `devtools::test()` or `testthat::test_file()` to see changes
i Current value:
Code
  cli::cli_alert_success("wow")
Message <cliMessage>
  v wow
── Skip (scripts.R:45:16): success [ansi] ──────────────────────────────────────
Reason: empty test
Can't compare snapshot to reference when testing interactively
ℹ Run `devtools::test()` or `testthat::test_file()` to see changes
ℹ Current value:
Code
  cli::cli_alert_success("wow")
Message <cliMessage>
  ✔ wow
── Skip (scripts.R:45:16): success [unicode] ───────────────────────────────────
Reason: empty test
Can't compare snapshot to reference when testing interactively
ℹ Run `devtools::test()` or `testthat::test_file()` to see changes
ℹ Current value:
Code
  cli::cli_alert_success("wow")
Message <cliMessage>
  ✔ wow
── Skip (scripts.R:45:16): success [fancy] ─────────────────────────────────────
Reason: empty test
[[1]]
[1] FALSE

[[2]]
[1] FALSE

[[3]]
[1] FALSE

[[4]]
[1] FALSE

[[5]]
NULL

[[6]]
NULL

[[7]]
NULL

[[8]]
NULL

[[9]]
NULL

[[10]]
NULL

[[11]]
NULL

[[12]]
NULL
# Only use two configurations, because this output does not have colors
cli::test_that_cli(configs = c("plain", "unicode"), "cat_bullet", {
  testthat::local_edition(3)
  testthat::expect_snapshot({
    cli::cat_bullet(letters[1:5])
  })
})
Can't compare snapshot to reference when testing interactively
i Run `devtools::test()` or `testthat::test_file()` to see changes
i Current value:
Code
  cli::cat_bullet(letters[1:5])
Output
  * a
  * b
  * c
  * d
  * e
── Skip (scripts.R:45:16): cat_bullet [plain] ──────────────────────────────────
Reason: empty test
Can't compare snapshot to reference when testing interactively
ℹ Run `devtools::test()` or `testthat::test_file()` to see changes
ℹ Current value:
Code
  cli::cat_bullet(letters[1:5])
Output
  • a
  • b
  • c
  • d
  • e
── Skip (scripts.R:45:16): cat_bullet [unicode] ────────────────────────────────
Reason: empty test
[[1]]
[1] FALSE

[[2]]
NULL

[[3]]
[1] FALSE

[[4]]
NULL

[[5]]
NULL

[[6]]
NULL

[[7]]
NULL

[[8]]
NULL

[[9]]
NULL

[[10]]
NULL

[[11]]
NULL

[[12]]
NULL
# You often need to evaluate all cli calls of a test case in the same
# environment. Use `local()` to do that:
cli::test_that_cli("theming", {
  testthat::local_edition(3)
  testthat::expect_snapshot(local({
    cli::cli_div(theme = list(".alert" = list(before = "!!! ")))
    cli::cli_alert("wow")
  }))
})
Can't compare snapshot to reference when testing interactively
i Run `devtools::test()` or `testthat::test_file()` to see changes
i Current value:
Code
  local({
    cli::cli_div(theme = list(.alert = list(before = "!!! ")))
    cli::cli_alert("wow")
  })
Message <cliMessage>
  !!! wow
── Skip (scripts.R:45:16): theming [plain] ─────────────────────────────────────
Reason: empty test
Can't compare snapshot to reference when testing interactively
i Run `devtools::test()` or `testthat::test_file()` to see changes
i Current value:
Code
  local({
    cli::cli_div(theme = list(.alert = list(before = "!!! ")))
    cli::cli_alert("wow")
  })
Message <cliMessage>
  !!! wow
── Skip (scripts.R:45:16): theming [ansi] ──────────────────────────────────────
Reason: empty test
Can't compare snapshot to reference when testing interactively
ℹ Run `devtools::test()` or `testthat::test_file()` to see changes
ℹ Current value:
Code
  local({
    cli::cli_div(theme = list(.alert = list(before = "!!! ")))
    cli::cli_alert("wow")
  })
Message <cliMessage>
  !!! wow
── Skip (scripts.R:45:16): theming [unicode] ───────────────────────────────────
Reason: empty test
Can't compare snapshot to reference when testing interactively
ℹ Run `devtools::test()` or `testthat::test_file()` to see changes
ℹ Current value:
Code
  local({
    cli::cli_div(theme = list(.alert = list(before = "!!! ")))
    cli::cli_alert("wow")
  })
Message <cliMessage>
  !!! wow
── Skip (scripts.R:45:16): theming [fancy] ─────────────────────────────────────
Reason: empty test
[[1]]
[1] FALSE

[[2]]
[1] FALSE

[[3]]
[1] FALSE

[[4]]
[1] FALSE

[[5]]
NULL

[[6]]
NULL

[[7]]
NULL

[[8]]
NULL

[[9]]
NULL

[[10]]
NULL

[[11]]
NULL

[[12]]
NULL

[Package cli version 3.6.3 Index]