forked from r-lib/usethis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-ui.R
41 lines (33 loc) 路 1.12 KB
/
test-ui.R
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
test_that("basic UI actions behave as expected", {
# suppress test silencing
withr::local_options(list(usethis.quiet = FALSE))
verify_output(test_path("test-ui-samples.txt"), {
ui_line("line")
ui_todo("to do")
ui_done("done")
ui_oops("oops")
ui_info("info")
ui_code_block(c("x <- 1", "y <- 2"))
ui_stop("an error")
ui_warn("a warning")
})
})
test_that("ui_silence() suppresses output", {
# suppress test silencing
withr::local_options(list(usethis.quiet = FALSE))
expect_output(ui_silence(ui_line()), NA)
})
test_that("trailing slash behaviour of ui_path()", {
# target doesn't exist so no empirical evidence that it's a directory
expect_match(ui_path("abc"), "abc'$")
# path suggests it's a directory
expect_match(ui_path("abc/"), "abc/'$")
expect_match(ui_path("abc//"), "abc/'$")
# path is known to be a directory
tmpdir <- fs::file_temp(pattern = "ui_path")
on.exit(fs::dir_delete(tmpdir))
fs::dir_create(tmpdir)
expect_match(ui_path(tmpdir), "/'$")
expect_match(ui_path(paste0(tmpdir, "/")), "[^/]/'$")
expect_match(ui_path(paste0(tmpdir, "//")), "[^/]/'$")
})