From 2cf44957527108d15e75a05450ecaca7e3eeeed5 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 15 Apr 2024 16:59:01 -0700 Subject: [PATCH 1/3] cleanup after test to prevent dir already exists in later test file --- tests/testthat/test-document.R | 109 ++++++++++++++++----------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/tests/testthat/test-document.R b/tests/testthat/test-document.R index bf112a2..8ce4a24 100644 --- a/tests/testthat/test-document.R +++ b/tests/testthat/test-document.R @@ -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 + }) }) From f718cc7ecd0c7180955158e50257bd43c6bd3a67 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 15 Apr 2024 17:06:06 -0700 Subject: [PATCH 2/3] cleanup test directories so avoid test interdependence conflicts --- tests/testthat/test-r-processing.R | 119 +++++++++++++++-------------- 1 file changed, 63 insertions(+), 56 deletions(-) diff --git a/tests/testthat/test-r-processing.R b/tests/testthat/test-r-processing.R index 96e2e36..777f34d 100644 --- a/tests/testthat/test-r-processing.R +++ b/tests/testthat/test-r-processing.R @@ -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) + }) }) From f175b222233a3698c403c2e8461dd3015b09ed63 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 15 Apr 2024 17:26:53 -0700 Subject: [PATCH 3/3] catch warnings --- tests/testthat/test-updating-datapackager-version.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-updating-datapackager-version.R b/tests/testthat/test-updating-datapackager-version.R index 20171dc..d02d2b7 100644 --- a/tests/testthat/test-updating-datapackager-version.R +++ b/tests/testthat/test-updating-datapackager-version.R @@ -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?