tests/testthat/test_getExamplePath.R

# Author: TW
#require(testthat)
context("getExamplePath")

# TRUE during testthat::check()
isNotOnCRAN <- identical(Sys.getenv("NOT_CRAN"), "true")

test_that("NOT_CRAN true",{
  skip_on_cran()
  formerEnv <- Sys.getenv("NOT_CRAN")
  tryCatch({
    Sys.setenv(NOT_CRAN = "true")
    exDir <- getREddyProcExampleDir()
    # dirname on a directory returns the parent directory
    expect_equal( file.path(dirname(tempdir()),"REddyProcExamples"), exDir)
    fName <- "readme.txt"
    fPath <- file.path(exDir,fName)
    # first make sure example is not there
    unlink(fPath)
    # get path without trying to download
    exPath <- getExamplePath( fName, FALSE )
    expect_equal( exPath, character(0))
    # get path with trying to download
    exPath <- getExamplePath( fName, TRUE )
    expect_equal( exPath, fPath)
  }
  , finally = Sys.setenv(NOT_CRAN = formerEnv) )
})

test_that("NOT_CRAN undefined",{
  skip_on_cran()
  formerEnv <- Sys.getenv("NOT_CRAN")
  tryCatch({
    Sys.setenv(NOT_CRAN = "")
    exDir <- getREddyProcExampleDir()
    expect_equal( file.path(tempdir(),"REddyProcExamples"), exDir)
    fName <- "readme.txt"
    fPath <- file.path(exDir,fName)
    # first make sure example is not there
    unlink(fPath)
    # get path without trying to download
    exPath <- getExamplePath( fName, FALSE )
    expect_equal( exPath, character(0))
    # get path with trying to download
    exPath <- getExamplePath( fName, TRUE )
    expect_equal( exPath, fPath)
  }
  , finally = Sys.setenv(NOT_CRAN = formerEnv) )
})
bgctw/REddyProc documentation built on March 26, 2024, 11:35 p.m.