Debian Codegraph @

tests/testthat/helper-output.R

raw
1 show_output_in_terminal <- function() {
2 system2("xterm", c("-e", shQuote("head tests/testthat/out/*; sleep 600")))
3 }
4
5 # A data frame with all major types
6 df_all <- pillar:::new_tbl(list(
7 a = c(1, 2.5, NA),
8 b = c(1:2, NA),
9 c = c(T, F, NA),
10 d = c("a", "b", NA),
11 e = factor(c("a", "b", NA)),
12 f = as.Date("2015-12-09") + c(1:2, NA),
13 g = as.POSIXct("2015-12-09 10:51:34.5678", tz = "UTC") + c(1:2, NA),
14 h = as.list(c(1:2, NA)),
15 i = list(list(1, 2:3), list(4:6), list(NA))
16 ))
17
18 # A data frame with strings of varying lengths
19 long_str <- strrep("Abcdefghij", 5)
20 df_str <- pillar:::map(rlang::set_names(1:50), function(i) substr(long_str, 1, i))
21
22 #' `add_special()` is not exported, and used only for initializing default
23 #' values to `expect_pillar_output()`.
24 #' @rdname expect_pillar_output
25 add_special <- function(x) {
26 if (inherits(x, "integer64")) {
27 x <- c(x, bit64::NA_integer64_)
28 } else {
29 x <- x[seq2(1, length(x) + 1)]
30 if (is.numeric(x) && is.double(x)) {
31 x <- c(x, -Inf, Inf)
32 }
33 }
34 x
35 }
36
37 continue <- function(x) {
38 paste0(x, symbol$continue)
39 }
40
41 # from pkgdepends
42 local_colors <- function(.local_envir = parent.frame()) {
43 # This is to restore crayon's cache. This runs after restoring the options.
44 withr::defer(envir = .local_envir, {
45 num_colors(forget = TRUE)
46 })
47
48 # We run this first, so this will run last by withr, to restore the
49 # original options.
50 withr::local_options(
51 list(cli.num_colors = 16L),
52 .local_envir = .local_envir
53 )
54
55 # Added safety
56 num_colors(forget = TRUE)
57 }
58
59 local_utf8 <- function(enable = TRUE, .local_envir = parent.frame()) {
60 withr::local_options(
61 list(cli.unicode = enable),
62 .local_envir = .local_envir
63 )
64 }