Skip to content

Commit

Permalink
Make staticdocs tests work in R CMD check
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Aug 23, 2016
1 parent ba3f8f4 commit 4456eac
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions tests/testthat/test-staticdocs.R
@@ -1,23 +1,38 @@
context("staticdocs")

test_that("All man pages have an entry in staticdocs/index.r", {
if (!all(file.exists(c('../../inst/staticdocs', '../../man')))) {
# This test works only when run against a package directory
if (all(file.exists(c('../../inst/staticdocs', '../../man')))) {
# We're running tests on a source tree
mode <- "source"
} else if (all(file.exists(c('../../shiny/staticdocs', '../../shiny/html')))) {
# We're testing an installed package, possibly for R CMD check
mode <- "bundle"
} else {
cat("Unknown testing environment for test-staticdocs.R.\n", file = stderr())
return()
}

# Known not to be indexed
known_unindexed <- c("shiny-package", "stacktrace", "knitr_methods", "knitr_methods_htmltools")

indexed_topics <- local({
# Read in topics from a staticdocs/index.r file
get_indexed_topics <- function(index_path) {
result <- character(0)
sd_section <- function(dummy1, dummy2, section_topics) {
result <<- c(result, section_topics)
}
source("../../inst/staticdocs/index.r", local = TRUE)
source(index_path, local = TRUE)
result
})
}

all_topics <- sub("\\.Rd", "", list.files("../../man", pattern = "*.Rd"))
if (mode == "source") {
indexed_topics <- get_indexed_topics("../../inst/staticdocs/index.r")
all_topics <- sub("\\.Rd", "", list.files("../../man", pattern = "*.Rd"))

} else if (mode == "bundle") {
indexed_topics <- get_indexed_topics("../../shiny/staticdocs/index.r")
all_topics <- unique(unname(readRDS("../../shiny/help/aliases.rds")))
}

# This test ensures that every documented topic is included in
# staticdocs/index.r, unless explicitly waived by specifying it
Expand Down

0 comments on commit 4456eac

Please sign in to comment.