library(testthat)
library(jeksterslabRterm)
library(jeksterslabRutils)
context("Test term_renviron.")

Set test parameters

tmp <- file.path(
  tempdir(),
  util_rand_str()
)
dir.create(tmp)
on.exit(
  unlink(
    tmp,
    recursive = TRUE
  )
)
fn_renviron <- file.path(
  tmp,
  ".Renviron"
)
libpath <- file.path(
  tmp,
  "lib"
)

Run test

term_renviron(
  dir = tmp,
  overwrite = TRUE,
  GITHUB_PAT = "123456",
  libpath = libpath
)
#> Output file: /tmp/RtmpfxDxfk/mCwwRqML/.Renviron
#> User library path: /tmp/RtmpfxDxfk/mCwwRqML/lib
#> Added R_LIBS_USER="/tmp/RtmpfxDxfk/mCwwRqML/lib"
#> R_BROWSER=${R_BROWSER-'/usr/bin/xdg-open'}
#> R_COMPLETION=TRUE
#> R_ENVIRON_USER="/tmp/RtmpfxDxfk/mCwwRqML/.Renviron"
#> R_PROFILE_USER="/tmp/RtmpfxDxfk/mCwwRqML/.Rprofile"
#> R_HISTFILE="/tmp/RtmpfxDxfk/mCwwRqML/.Rhistory"
#> GITHUB_PAT=123456 to /tmp/RtmpfxDxfk/mCwwRqML/.Renviron

For code coverage.

suppressMessages(
  term_renviron(
    overwrite = FALSE
  )
)
#> Warning in util_txt2file(text = output, dir = dir, fn = ".Renviron", msg = "Output file:", : /home/jek/.Renviron exists and will NOT be overwritten.
test_that(".Renviron", {
  expect_true(
    file.exists(fn_renviron)
  )
})
test_that("warning", {
  expect_warning(
    term_renviron(
      dir = tmp,
      overwrite = FALSE,
      GITHUB_PAT = "123456",
      libpath = file.path(tmp, "tmp")
    )
  )
})
unlink(
  c(
    fn_renviron,
    tmp,
    libpath
  ),
  recursive = TRUE
)