File: test-reproducible-output.R

package info (click to toggle)
r-cran-evaluate 1.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: sh: 13; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download
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
46
47
48
test_that("local_reproducible_output() respects local context", {
  local_reproducible_output(width = 105)
  expect_equal(getOption("width"), 105)

  local({
    local_reproducible_output(width = 110)
    expect_equal(getOption("width"), 110)
  })

  expect_equal(getOption("width"), 105)
})

test_that("local_envvar respects local context", {
  local_envvar(test = "a")
  expect_equal(Sys.getenv("test"), "a")

  local({
    local_envvar(test = "b")
    expect_equal(Sys.getenv("test"), "b")
  })

  expect_equal(Sys.getenv("test"), "a")
  local({
    local_envvar(test = NA)
    expect_equal(Sys.getenv("test"), "")
  })

  expect_equal(Sys.getenv("test"), "a")
})

test_that("local_collate respects local context", {
  locale <- switch(Sys.info()[["sysname"]],
    Darwin = ,
    Linux = "en_US.UTF-8",
    Windows = if (getRversion() >= "4.2") "en-US"
  )
  skip_if(is.null(locale), "Don't know good locale to use for this platform")

  local_collate("C")
  expect_equal(Sys.getlocale("LC_COLLATE"), "C")

  local({
    local_collate(locale)
    expect_equal(Sys.getlocale("LC_COLLATE"), locale)
  })

  expect_equal(Sys.getlocale("LC_COLLATE"), "C")
})