tests/testthat/test-basicfunctionality.R

context("basic project functionality")

proj_name <- "test_tidyproject"

cleanup <- function(proj_name) {
    if (file.exists(proj_name)) 
        unlink(proj_name, recursive = TRUE, force = TRUE)
    base_proj_name <- paste0(proj_name, ".git")
    if (file.exists(base_proj_name)) 
        unlink(base_proj_name, recursive = TRUE, force = TRUE)
}

test_that("Project has basic functionality", {

    currentwd <- getwd()
    make_project(proj_name)
    on.exit({
        setwd(currentwd)
        cleanup(proj_name)
    })
    
    wait_for(TRUE)
    
    setwd(proj_name)
    
    expect_true(file.exists("ProjectLibrary"))
    new_script("test.R", open_file = FALSE)
    expect_true(file.exists(file.path(getOption("scripts.dir"), "test.R")))
    
    res <- recursive_lib_find(quote({
      library(libname1)
      library(libname2);require(libname3)
      notalibname
      notalibname+2
      libname4::fname + libname5::fname + libname6:::fname
    }))
    expect_true(identical(res,paste0("libname",1:6)))

    environment_info()
    res <- check_session(check_rstudio = FALSE)
    expect_true(is.data.frame(res))

    if(!exists(".rs.getProjectDirectory")) expect_error(resetwd(),"not.*rstudio")
    if(exists(".rs.getProjectDirectory")) expect_error(resetwd(),NA)
})

test_that("R session stamp", {

    currentwd <- getwd()
    on.exit({
      setwd(currentwd)
      cleanup(proj_name)
    })
    
    make_project(proj_name)
    
    setwd(proj_name)
    
    write(c("## Description: abc", "## Depends on: ", "library(tidyproject)", "require(tidyproject)", 
        "tidyproject::make_project"), file = file.path(getOption("scripts.dir"), "test.R"))
    
    environment_info()
    
    files <- list.files(pattern = "environment_info.*txt")
    
    expect_true(length(files) > 0)
    
})
tsahota/TidyProject documentation built on April 19, 2021, 9:14 p.m.