Debian Codegraph @

tests/testthat/helper-snapshot.R

raw
1 snapshot_variant <- function(...) {
2 matrix <- c(...)
3
4 bad_variants <- setdiff(matrix, c("os", "output-enc"))
5 if (length(bad_variants) > 0) {
6 abort(paste0("Unknown variant selector: ", bad_variants[[1]]))
7 }
8
9 variant <- NULL
10
11 if ("os" %in% matrix) {
12 variant <- c(variant, testthat_os())
13 }
14
15 if ("output-enc" %in% matrix) {
16 if (cli::is_utf8_output()) {
17 variant <- c(variant, "unicode")
18 } else {
19 variant <- c(variant, "ansi")
20 }
21 }
22
23 if (is.null(variant)) {
24 return(NULL)
25 }
26 paste(variant, collapse = "-")
27 }
28
29 testthat_os <- function() {
30 os <- tolower(Sys.info()[["sysname"]])
31 switch(os,
32 darwin = "mac",
33 sunos = "solaris",
34 os
35 )
36 }