Skip to content

Commit

Permalink
Merge pull request #118 from ropensci/tests
Browse files Browse the repository at this point in the history
More test cleanup
  • Loading branch information
slager committed Apr 16, 2024
2 parents 4f79b00 + f175b22 commit 3852150
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 112 deletions.
109 changes: 54 additions & 55 deletions tests/testthat/test-document.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,59 @@ test_that("documentation is built via document()", {
file <- system.file("extdata", "tests", "subsetCars.Rmd",
package = "DataPackageR"
)
datapackage_skeleton(
name = "subsetCars",
path = tempdir(),
code_files = c(file),
force = TRUE,
r_object_names = "cars_over_20"
)

temp_libpath <- file.path(tempdir(), "lib")
dir.create(temp_libpath)

package_build(file.path(tempdir(), "subsetCars"))

expect_true(document(file.path(tempdir(), "subsetCars"), lib = temp_libpath))
docfile <- readLines(file.path(
tempdir(),
"subsetCars", "data-raw", "documentation.R"
))
connection <- file(file.path(
tempdir(),
"subsetCars", "data-raw", "documentation.R"
),
open = "w+"
)
writeLines(
text =
c(docfile, "
#' Use roxygen to document a package.
#'
#' This is dummy documentation used to test markdown documentation
#' for [roxygen2::roxygenize()] in the `subsetCars`` test package.
#'
#' @name testmarkdownroxygen
#' @param none there are no parameters
#' this is a link to a function: [document()]
#' @seealso [DataPackageR::document()], `browseVignettes(\"subsetCars\")`
#' @md
NULL
"),
con = connection
)
flush(connection)
close(connection)
expect_true(
document(file.path(tempdir(), "subsetCars"),
lib = temp_libpath)
)

v <- vignette(package = "subsetCars", lib.loc = temp_libpath)
expect_equal(v$results[, "Item"], "subsetCars")
unlink(file.path(tempdir(), "subsetCars"),
recursive = TRUE,
force = TRUE
)
try(usethis::proj_set(NULL),silent = TRUE) #wrap in try for usethis 1.4 vs 1.5
local({
tempdir <- withr::local_tempdir()
datapackage_skeleton(
name = "subsetCars",
path = tempdir,
code_files = c(file),
force = TRUE,
r_object_names = "cars_over_20"
)
temp_libpath <- file.path(tempdir, "lib")
dir.create(temp_libpath)
package_build(file.path(tempdir, "subsetCars"))
expect_true(document(file.path(tempdir, "subsetCars"), lib = temp_libpath))
docfile <- readLines(file.path(
tempdir,
"subsetCars", "data-raw", "documentation.R"
))
connection <- file(file.path(
tempdir,
"subsetCars", "data-raw", "documentation.R"
),
open = "w+"
)
writeLines(
text =
c(docfile, "
#' Use roxygen to document a package.
#'
#' This is dummy documentation used to test markdown documentation
#' for [roxygen2::roxygenize()] in the `subsetCars`` test package.
#'
#' @name testmarkdownroxygen
#' @param none there are no parameters
#' this is a link to a function: [document()]
#' @seealso [DataPackageR::document()], `browseVignettes(\"subsetCars\")`
#' @md
NULL
"),
con = connection
)
flush(connection)
close(connection)
expect_true(
document(file.path(tempdir, "subsetCars"),
lib = temp_libpath)
)
v <- vignette(package = "subsetCars", lib.loc = temp_libpath)
expect_equal(v$results[, "Item"], "subsetCars")
unlink(file.path(tempdir, "subsetCars"),
recursive = TRUE,
force = TRUE
)
try(usethis::proj_set(NULL),silent = TRUE) #wrap in try for usethis 1.4 vs 1.5
})
})

119 changes: 63 additions & 56 deletions tests/testthat/test-r-processing.R
Original file line number Diff line number Diff line change
@@ -1,66 +1,73 @@
context("R file script processing to vignette")
test_that("R file processing works and creates vignettes", {

file <- system.file("extdata", "tests", "rfileTest.R",
package = "DataPackageR"
)
local({
tempdir <- withr::local_tempdir()
datapackage_skeleton(
name = "rfiletest",
path = tempdir,
code_files = c(file),
force = TRUE,
r_object_names = "data"
)

datapackage_skeleton(
name = "rfiletest",
path = tempdir(),
code_files = c(file),
force = TRUE,
r_object_names = "data"
)

temp_libpath <- file.path(tempdir(),"lib")
dir.create(temp_libpath)

expect_equal(
basename(package_build(
file.path(tempdir(), "rfiletest"),
install = TRUE,
lib = temp_libpath
)),
"rfiletest_1.0.tar.gz"
)

v <- vignette(package = "rfiletest", lib.loc = temp_libpath)

expect_equal(v$results[, "Item"], "rfileTest")
expect_true(file_test("-f", file.path(tempdir(),"rfiletest","inst","doc","rfileTest.pdf")))
unlink(file.path(tempdir(), "rfiletest"),
recursive = TRUE,
force = TRUE
)
remove.packages("rfiletest", lib = temp_libpath)
file <- system.file("extdata", "tests", "rfileTest_noheader.R",
package = "DataPackageR"
)
datapackage_skeleton(
name = "rfiletest",
path = tempdir(),
code_files = c(file),
force = TRUE,
r_object_names = "data"
)
dir.create(temp_libpath)
expect_equal(
basename(
package_build(
file.path(tempdir(), "rfiletest"),
temp_libpath <- file.path(tempdir,"lib")
dir.create(temp_libpath)

expect_equal(
basename(package_build(
file.path(tempdir, "rfiletest"),
install = TRUE,
lib = temp_libpath
)
),
"rfiletest_1.0.tar.gz"
)
v <- vignette(package = "rfiletest", lib.loc = temp_libpath)
expect_equal(v$results[, "Item"], "rfileTest_noheader")
unlink(file.path(tempdir(), "rfiletest"),
recursive = TRUE,
force = TRUE
)),
"rfiletest_1.0.tar.gz"
)

v <- vignette(package = "rfiletest", lib.loc = temp_libpath)

expect_equal(v$results[, "Item"], "rfileTest")
expect_true(file_test("-f", file.path(tempdir,"rfiletest","inst","doc","rfileTest.pdf")))
unlink(file.path(tempdir, "rfiletest"),
recursive = TRUE,
force = TRUE
)
remove.packages("rfiletest", lib = temp_libpath)
})

file <- system.file("extdata", "tests", "rfileTest_noheader.R",
package = "DataPackageR"
)
try(usethis::proj_set(NULL),silent = TRUE) #wrap in try for usethis 1.4 vs 1.5
remove.packages("rfiletest",lib = temp_libpath)
local({
tempdir <- withr::local_tempdir()
datapackage_skeleton(
name = "rfiletest",
path = tempdir,
code_files = c(file),
force = TRUE,
r_object_names = "data"
)
temp_libpath <- file.path(tempdir,"lib")
dir.create(temp_libpath)
expect_equal(
basename(
package_build(
file.path(tempdir, "rfiletest"),
install = TRUE,
lib = temp_libpath
)
),
"rfiletest_1.0.tar.gz"
)
v <- vignette(package = "rfiletest", lib.loc = temp_libpath)
expect_equal(v$results[, "Item"], "rfileTest_noheader")
unlink(file.path(tempdir, "rfiletest"),
recursive = TRUE,
force = TRUE
)
try(usethis::proj_set(NULL),silent = TRUE) #wrap in try for usethis 1.4 vs 1.5
remove.packages("rfiletest",lib = temp_libpath)
})
})
5 changes: 4 additions & 1 deletion tests/testthat/test-updating-datapackager-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ test_that("can update", {
oldDigest$cars_over_20<-"123456789"
DataPackageR:::.save_digest(oldDigest,file.path(tempdir(),"subsetCars"))

suppressWarnings({
expect_warning(build_res <- package_build(file.path(tempdir(), "subsetCars")))
})
expect_identical(
try(package_build(file.path(tempdir(), "subsetCars"))),
build_res,
normalizePath(file.path(tempdir(),"subsetCars_1.0.tar.gz"),winslash = "/")
)#if it passes, it returns the path to the tar file?

Expand Down

0 comments on commit 3852150

Please sign in to comment.