knitr::opts_chunk$set(
  error = TRUE,
  collapse = TRUE,
  comment = "#>",
  out.width = "100%"
)
library(testthat)
library(jeksterslabRterm)
library(jeksterslabRutils)
context("Test term_bash.")

Set test parameters

tmp <- file.path(
  tempdir(),
  util_rand_str()
)
dir.create(tmp)
on.exit(
  unlink(
    tmp,
    recursive = TRUE
  )
)
fn_bashrc <- file.path(
  tmp,
  ".bashrc"
)
fn_bash_aliases <- file.path(
  tmp,
  ".bash_aliases"
)
fn_bash_profile <- file.path(
  tmp,
  ".bash_profile"
)
fn_bash_logout <- file.path(
  tmp,
  ".bash_logout"
)
os <- util_os()

Run test

if (os != "windows") {
  term_bash(
    dir = tmp,
    overwrite = TRUE,
    vars = c(GITHUB_PAT = "123456", TRAVIS_TOKEN = "123456")
  )
}
if (os != "windows") {
  test_that(".bashrc", {
    expect_true(
      file.exists(fn_bashrc)
    )
  })
}
if (os != "windows") {
  test_that(".bash_aliases", {
    expect_true(
      file.exists(fn_bash_aliases)
    )
  })
}
if (os != "windows") {
  test_that(".bash_profile", {
    expect_true(
      file.exists(fn_bash_profile)
    )
  })
}
if (os != "windows") {
  test_that(".bash_logout", {
    expect_true(
      file.exists(fn_bash_logout)
    )
  })
}
if (os != "windows") {
  test_that("warning", {
    expect_warning(
      term_bash(
        dir = tmp,
        overwrite = FALSE,
        vars = c(GITHUB_PAT = "123456", TRAVIS_TOKEN = "123456")
      )
    )
  })
}
if (os == "windows") {
  test_that("windows", {
    expect_error(
      term_bash(
        dir = tmp,
        overwrite = FALSE,
        vars = c(GITHUB_PAT = "123456", TRAVIS_TOKEN = "123456")
      )
    )
  })
}
unlink(
  c(
    fn_bashrc,
    fn_bash_aliases,
    fn_bash_profile,
    fn_bash_logout,
    tmp
  ),
  recursive = TRUE
)


jeksterslabds/jeksterslabRterm documentation built on July 13, 2020, 11:43 p.m.