Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R CMD check tweaks. Fix and fully automate tests. #229

Merged
merged 17 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,23 @@ Description: Automate the steps necessary to create a validation ready package
situations to provide documentation for validation.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.3.1
Suggests:
covr,
XML,
pdftools,
bookdown,
here,
xml2,
rvest
rvest,
fs
Imports:
desc,
devtools,
R6,
roxygen2,
lubridate,
fs,
rlang,
yaml,
whoami,
Expand All @@ -69,7 +68,8 @@ Imports:
knitr,
kableExtra,
testthat,
tidyselect
tidyselect,
rstudioapi
VignetteBuilder: knitr
SystemRequirements:
lua
8 changes: 4 additions & 4 deletions man/val_init.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions man/vt_dynamic_referencer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#' Create vt test package silently and non-interactively
make_vt_test_package <- function(){
withr::with_options(
list(
usethis.quiet = TRUE
),
{
vt_create_package(rstudio = FALSE, open = FALSE)
})
}
4 changes: 2 additions & 2 deletions tests/testthat/test-add_file.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test_that("validation file path finds files within the validation infrastructure, throws error otherwise", {
withr::with_tempdir({

vt_use_validation()
vt_use_req("example_req.md",username = "sample")
make_vt_test_package()
vt_use_req("example_req.md", username = "sample", open = FALSE)

fp <- validation_file_path(
file = "example_req.md",
Expand Down
25 changes: 9 additions & 16 deletions tests/testthat/test-change_log_handlers.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
test_that("create change log from template", {
withr::with_tempdir({

captured_output <- capture.output(vt_create_package("myTestPkg", open = FALSE))
setwd("myTestPkg")

vt_use_change_log(date = "2021-01-01")
make_vt_test_package()
vt_use_change_log(date = "2021-01-01", open = FALSE)

expect_true(file.exists("vignettes/validation/change_log.md"))
expect_equal(readLines("vignettes/validation/change_log.md")[1],
Expand All @@ -13,9 +11,8 @@ test_that("create change log from template", {
})

withr::with_tempdir({
captured_output <- capture.output(vt_create_package("myTestPkg", open = FALSE))
setwd("myTestPkg")
vt_use_change_log()
make_vt_test_package()
vt_use_change_log(open = FALSE)
expect_true(file.exists("vignettes/validation/change_log.md"))
expect_equal(readLines("vignettes/validation/change_log.md")[1],
paste("# 0.0.0.9000",format(Sys.Date(), "%Y-%m-%d")))
Expand All @@ -27,10 +24,9 @@ test_that("change log not in a package", {

withr::with_tempdir({

file.create(".here")
vt_use_validation()
make_vt_test_package()

vt_use_change_log(date = "2021-01-01", version = "0.0.0.9000")
vt_use_change_log(date = "2021-01-01", version = "0.0.0.9000", open = FALSE)

expect_equal(
vt_scrape_change_log(),
Expand All @@ -43,10 +39,8 @@ test_that("change log not in a package", {

withr::with_tempdir({

file.create(".here")
vt_use_validation()

vt_use_change_log()
make_vt_test_package()
vt_use_change_log(open = FALSE, version = "1.0")
expect_equal(
vt_scrape_change_log(),
data.frame(version = "1.0",
Expand All @@ -62,8 +56,7 @@ test_that("Throw informative error when change log does not exist", {

withr::with_tempdir({

file.create(".here")
vt_use_validation()
make_vt_test_package()

expect_error(
vt_scrape_change_log(),
Expand Down
15 changes: 8 additions & 7 deletions tests/testthat/test-child_files.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("child files in pkg", {
withr::with_tempdir({
capture_output <- capture.output({vt_create_package(open = FALSE)})
make_vt_test_package()

vt_use_req("req1", username = "a user", open = FALSE)
vt_use_test_case("testcase1", username = "a user", open = FALSE)
Expand Down Expand Up @@ -42,7 +42,7 @@ test_that("child files in pkg", {

test_that("child files outside pkg", {
withr::with_tempdir({
vt_use_validation()
make_vt_test_package()
vt_use_test_case("testcase1", username = "a user", open = FALSE)
vt_use_req("req1", username = "a user", open = FALSE)
vt_use_test_code("testcode1", username = "another user", open = FALSE)
Expand All @@ -63,7 +63,7 @@ test_that("child files outside pkg", {

test_that("incomplete set", {
withr::with_tempdir({
vt_use_validation()
make_vt_test_package()
vt_use_test_case("testcase1", username = "a user", open = FALSE)
vt_use_test_case("testcase2", username = "a user", open = FALSE)
vt_use_req("req1", username = "a user", open = FALSE)
Expand All @@ -87,7 +87,7 @@ test_that("incomplete set", {

test_that("compatibility between vt_get_child_files and vt_files", {
withr::with_tempdir({
captured_output <- capture.output({vt_create_package(open = FALSE)})
make_vt_test_package()
vt_use_test_case("testcase1", username = "a user", open = FALSE)
vt_use_test_case("testcase2", username = "a user", open = FALSE)
vt_use_req("req1", username = "a user", open = FALSE)
Expand All @@ -97,11 +97,12 @@ test_that("compatibility between vt_get_child_files and vt_files", {
setwd(file.path("vignettes", "validation"))

knitr::opts_knit$set("output.dir"= ".")

rmd_asis <- capture.output({vt_file(child_files)})
testthat::expect_equal(rmd_asis[9],
"+ Setup: DOCUMENT ANY SETUP THAT NEEDS TO BE DONE FOR TESTING")
testthat::expect_in("+ Setup: DOCUMENT ANY SETUP THAT NEEDS TO BE DONE FOR TESTING",
rmd_asis)

suppressWarnings(testthat::expect_error(vt_file(basename(child_files))))
testthat::expect_error(suppressWarnings(vt_file(basename(child_files))))

})
})
8 changes: 4 additions & 4 deletions tests/testthat/test-create_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test_that("vt_use_ family works nicely with simple item creation", {
withr::with_tempdir({

# set up validation infrastructure
vt_use_validation()
make_vt_test_package()

## create items
spec_path <- create_item(
Expand All @@ -84,13 +84,13 @@ test_that("vt_use_ family works nicely with simple item creation", {
type = "test_code")

expect_true(
file.exists("validation/requirements/new_dir/new_specification")
file.exists("vignettes/validation/requirements/new_dir/new_specification")
)
expect_true(
file.exists("validation/test_cases/new_dir/new_test_case")
file.exists("vignettes/validation/test_cases/new_dir/new_test_case")
)
expect_true(
file.exists("validation/test_code/new_dir/new_test_code")
file.exists("vignettes/validation/test_code/new_dir/new_test_code")
)
})

Expand Down
29 changes: 12 additions & 17 deletions tests/testthat/test-evaluate_test_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,29 +375,24 @@ test_that("vt_kable_test_code_results returns formatted kable object",{
),position = "center"), latex_options = "hold_position")
)

output_empty <- vt_kable_test_code_results(data.frame(
output_empty_df <- data.frame(
Test = character(),
Results = character(),
Pass_Fail = character(),
stringsAsFactors = FALSE
))

expect_equal(
output_empty,
kable_styling(
kable_styling(
kable(
data.frame(
Test = character(),
Results = character(),
Pass_Fail = character(),
stringsAsFactors = FALSE
),
escape = FALSE,
col.names = c("Test", "Results", "Pass/Fail")
),position = "center"), latex_options = "hold_position")
)

output_empty <- vt_kable_test_code_results(output_empty_df)

output_empty_df2 <- output_empty_df
names(output_empty_df2) <- c('Test', 'Results', 'Pass/Fail')
output_empty2 <- output_empty_df2 %>%
kable(format = 'html') %>%
kable_styling(position = "center") %>%
kable_styling(latex_options = "hold_position")

expect_equal(output_empty, output_empty2)


skip_on_cran()
withr::with_tempfile(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-lua_dynamic_referencing.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ test_that("lua numbering for html", {
pattern = "Later\\sreference\\sto\\s\\((\\d)\\)\\s-\\s(\\d)",
replacement = "\\1")))
expect_equal(c(1, 1, 2, 2, 1, 3, 2),
as.numeric(unlist(lapply(strsplit(list_rendered, ": "), FUN = function(x){x[2]}))))
as.integer(sub(".*(\\d{1})$", "\\1", list_rendered)))

})

Expand Down
Loading
Loading