tests/testthat/test-skeletor-clean.R

context("Skeletor with no configuration")

options(skeletor.name=NULL, skeletor.email=NULL, skeletor.github=NULL)

public({
    tmpd <- tempdir()
    pkgdir <- tempfile(tmpdir="")
    pkgdir <- substr(pkgdir, 2, nchar(pkgdir)) ## Remove the leading /. We'll need that later
    dest <- file.path(tmpd, pkgdir)
    test_that("Creating a package skeleton", {
        skeletor("testskeletor", dest)
        expect_dir_exists(dest)
    })
    test_that("The right dirs exist", {
        expect_dir_exists(file.path(dest, "tests"))
        expect_dir_exists(file.path(dest, "man"))
        expect_dir_exists(file.path(dest, "vignettes"))
        # But not this api one
        expect_false(dir.exists(file.path(dest, "tests", "testthat", "example.com")))
    })
    test_that("The right files exist", {
        expect_file_exists(file.path(dest, "DESCRIPTION"))
        expect_file_exists(file.path(dest, ".Rbuildignore"))
        expect_file_exists(file.path(dest, "Makefile"))
        expect_file_exists(file.path(dest, ".gitignore"))
        expect_file_exists(file.path(dest, "R", "testskeletor.R"))
        # But not this one
        expect_false(file.exists(file.path(dest, "tests", "testthat", "test-api.R")))
    })

    desc <- readLines(file.path(dest, "DESCRIPTION"))
    tests <- readLines(file.path(dest, "tests", "testthat.R"))
    git <- readLines(file.path(dest, ".gitignore"))
    lisc <- readLines(file.path(dest, "LICENSE"))
    onattach <- readLines(file.path(dest, "R", "testskeletor.R"))

    test_that("The package name appears in the contents", {
        expect_identical(desc[1], "Package: testskeletor")
        expect_identical(tests[2], 'test_check("testskeletor")')
        expect_identical(git[4], 'testskeletor*.tar.gz')
    })

    test_that("skeletor.name is empty, so it doesn't get overwritten", {
        expect_identical(lisc[2], "COPYRIGHT HOLDER: yourname")
        expect_true(any(grepl('person\\("your", "name"', desc)))
    })
    test_that("skeletor.github is empty, so it doesn't get overwritten", {
        expect_true("URL: https://github.com/yourgithub/testskeletor" %in% desc)
    })
    test_that("skeletor.email is empty, so it doesn't get overwritten", {
        expect_true(any(grepl("youremail@example.com", desc)))
    })
    test_that("The .onAttach function in the R file points to testskeletor", {
        expect_true('.onLoad <- function (lib, pkgname="testskeletor") {' %in% onattach)
    })

    if (!no.check) {
        setwd(tmpd)
        test_that("The skeleton package can be built", {
            Rcmd(paste("build", pkgdir))
            expect_file_exists("testskeletor_0.1.0.tar.gz")
        })
        test_that("The built package passes R CMD CHECK", {
            skip_on_appveyor() ## It apparently can't find pdflatex to build the manual
            skip_on_cran() ## In case it is slow
            status <- Rcmd("check testskeletor_0.1.0.tar.gz")
            expect_equal(status, 0)
        })
    }
})
nealrichardson/skeletor documentation built on April 7, 2023, 2:17 p.m.