From 4456eac1fdcea6bd8f55479e7597adf4dd908143 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Mon, 22 Aug 2016 21:04:19 -0500 Subject: [PATCH] Make staticdocs tests work in R CMD check --- tests/testthat/test-staticdocs.R | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-staticdocs.R b/tests/testthat/test-staticdocs.R index 79fba7598d..e735ecc4e0 100644 --- a/tests/testthat/test-staticdocs.R +++ b/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