Skip to content

Commit

Permalink
test: test all examples in the check
Browse files Browse the repository at this point in the history
Refs #14
  • Loading branch information
Dorchies David committed Feb 13, 2023
1 parent 8a2174c commit fb3794f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/testthat/test-run_all_examples.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
skip_on_cran()
package <- "hubeau"

with_warnings <- c("get_hydrometrie_obs_elab")

db <- tools::Rd_db(package)

lapply(db, function(Rd_fun) {
tags <- tools:::RdTags(Rd_fun)
which_ex <- which(tags=="\\examples")
name <- unlist(Rd_fun[tags == "\\name"])
if (length(which_ex) > 0) {
ex <- unlist(Rd_fun[which_ex])
ex <- gsub("\n", "", ex)
ex <- c("interactive <- function() TRUE", ex)
file <- file.path(tempdir(), paste0(name, ".R"))
writeLines(ex, file)
test_that(paste("Examples", name, "run without error"), {
if (name %in% with_warnings) {
suppressWarnings(source(file))
} else {
source(file)
}
expect_equal(TRUE, TRUE)
})
}
})


0 comments on commit fb3794f

Please sign in to comment.