Debian Codegraph @

tests/testthat/test.R

raw
1 test_that("xopen works", {
2
3 if (Sys.getenv("TESTTHAT_INTERACTIVE") == "") {
4 skip("Need to test this interactively")
5 }
6
7 ## File
8 expect_error(xopen("test.R", quiet = TRUE), NA)
9
10 ## URL
11 expect_error(xopen("https://ps.r-lib.org", quiet = TRUE), NA)
12
13 ## URL with given app
14 expect_error(
15 xopen("https://processx.r-lib.org", app = chrome(), quiet = TRUE),
16 NA)
17
18 ## App only, no target
19 expect_error(xopen(app = chrome(), quiet = TRUE), NA)
20
21 ## App and arguments (need to quit Chrome for this to work...)
22 expect_error(
23 xopen(
24 app = c(chrome(), "--incognito", "https://github.com"),
25 quiet = TRUE),
26 NA)
27 })
28
29 test_that("URLs with spaces", {
30
31 if (Sys.getenv("TESTTHAT_INTERACTIVE") == "") {
32 skip("Need to test this interactively")
33 }
34
35 expect_error(
36 xopen("https://google.com/search?q=a b c", quiet = TRUE),
37 NA)
38 })
39
40 test_that("errors", {
41 skip_on_cran()
42 expect_error(xopen2(tempfile(), quiet = TRUE, timeout1 = 10, timeout2 = 10))
43 })
44
45 test_that("wait_for_finish", {
46 px <- get("get_tool", asNamespace("processx"))("px")
47 proc <- processx::process$new(
48 px, c("errln", "message", "sleep", "100"), stderr = tempfile())
49 on.exit(proc$kill(), add = TRUE)
50
51 proc$poll_io(1000)
52 expect_error(wait_for_finish(proc, "target", 10, 10),
53 "Could not open")
54 expect_error(wait_for_finish(proc, "target", 10, 10),
55 "Standard error")
56 })