File: test-env.R

package info (click to toggle)
r-cran-processx 3.8.6-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,068 kB
  • sloc: ansic: 6,485; sh: 13; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (3)
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
42
43
44
45

test_that("inherit by default", {

  v <- basename(tempfile())
  if (os_type() == "unix") {
    cmd <- c("bash", "-c", paste0("echo $", v))
  } else {
    cmd <- c("cmd",  "/c", paste0("echo %", v, "%"))
  }

  skip_if_no_tool(cmd[1])

  out <- run(cmd[1], cmd[-1])
  expect_true(out$stdout %in% c("\n", paste0("%", v, "%\r\n")))
  gc()
})

test_that("specify custom env", {

  v <- c(basename(tempfile()), basename(tempfile()))
  if (os_type() == "unix") {
    cmd <- c("bash", "-c", paste0("echo ", paste0("$", v, collapse = " ")))
  } else {
    cmd <- c("cmd",  "/c", paste0("echo ", paste0("%", v, "%", collapse = " ")))
  }

  skip_if_no_tool(cmd[1])

  out <- run(cmd[1], cmd[-1], env = structure(c("bar", "baz"), names = v))
  expect_true(out$stdout %in% paste0("bar baz", c("\n", "\r\n")))
  gc()
})

test_that("append to env", {
  withr::local_envvar(FOO = "fooe", BAR = "bare")
  px <- get_tool("px")
  out <- run(
    px,
    c("getenv", "FOO", "getenv", "BAR", "getenv", "BAZ"),
    env = c("current", BAZ = "baze", BAR = "bare2")
  )

  outenv <- strsplit(out$stdout, "\r?\n")[[1]]
  expect_equal(outenv, c("fooe", "bare2", "baze"))
})