Skip to content

Commit

Permalink
add --run-demo option for R CMD check
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87606 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
smeyer committed Jan 20, 2025
1 parent 18683f9 commit 31033df
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
3 changes: 3 additions & 0 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@
\command{bash} scripts and bashisms in components of
\command{autoconf}-generated \command{configure} scripts.
\item \command{R CMD check} gains option \option{--run-demo} to
check demo scripts like tests.
\item \code{R CMD build} now supports \option{--compression =
zstd} on platforms with sufficient support for \command{zstd}.
}
Expand Down
6 changes: 5 additions & 1 deletion doc/manual/R-exts.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,11 @@ The @file{data} subdirectory is for data files: @xref{Data in packages}.

The @file{demo} subdirectory is for @R{} scripts (for running @emph{via}
@code{demo()}) that demonstrate some of the functionality of the
package. Demos may be interactive and are not checked automatically, so
package. Demos may be interactive and are not checked
automatically@footnote{As from @R{} 4.5.0, @code{R CMD check} can be
invoked with option @option{--run-demo} to check demos like @file{tests},
including comparisons with optional reference outputs in
@file{.Rout.save} files.}, so
if testing is desired use code in the @file{tests} directory to achieve
this. The script files must start with a (lower or upper case) letter
and have one of the extensions @file{.R} or @file{.r}. If present, the
Expand Down
5 changes: 5 additions & 0 deletions doc/manual/R-ints.texi
Original file line number Diff line number Diff line change
Expand Up @@ -4261,6 +4261,11 @@ If set to a true value, also check the R code in common unit test
subdirectories of @file{tests} for undeclared package dependencies.
Default: false (but true for CRAN submission checks).

@item _R_CHECK_PACKAGES_USED_IN_DEMO_
Control whether R scripts in the @file{demo} directory should be checked
for packages used but not declared in the @file{DESCRIPTION} file.
Default: false unless command-line option @option{--run-demo} is specified.

@item _R_CHECK_SHLIB_OPENMP_FLAGS_
Check correct and portable use of @code{SHLIB_OPENMP_*FLAGS} in
@file{src/Makevars} (and similar).
Expand Down
39 changes: 30 additions & 9 deletions src/library/tools/R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ add_dummies <- function(dir, Log)
resultLog(Log, "SKIPPED")
}

## Run the demos if requested (traditionally part of tests, as in base)
if (dir.exists(file.path(pkgdir, "demo")))
run_tests("demo")

## Run the package-specific tests.
tests_dir <- file.path(pkgdir, test_dir)
if (test_dir != "tests" && !dir.exists(tests_dir)) {
Expand All @@ -740,7 +744,7 @@ add_dummies <- function(dir, Log)
}
if (dir.exists(tests_dir) && # trackObjs has only *.Rin
length(dir(tests_dir, pattern = "\\.(R|r|Rin)$")))
run_tests()
run_tests(test_dir)

## Check package vignettes.
setwd(pkgoutdir)
Expand Down Expand Up @@ -4637,30 +4641,41 @@ add_dummies <- function(dir, Log)
}
}

run_tests <- function()
## this is also used for --run-demo
run_tests <- function(test_dir = "tests")
{
if (!extra_arch && !is_base_pkg) {
is_demo <- test_dir == "demo"
check_packages_used <- !is_demo ||
config_val_to_logical(Sys.getenv("_R_CHECK_PACKAGES_USED_IN_DEMO_", do_demo))
if (check_packages_used && !extra_arch && !is_base_pkg) {
checkingLog(Log, "for unstated dependencies in ", sQuote(test_dir))
Rcmd <- paste(opW_shE_F_str,
sprintf("tools:::.check_packages_used_in_tests(\"%s\", \"%s\")\n", pkgdir, test_dir))

out <- R_runR2(Rcmd, "R_DEFAULT_PACKAGES=NULL")
if (length(out)) {
warningLog(Log)
if (is_demo) noteLog(Log) else warningLog(Log)
printLog0(Log, paste(c(out, ""), collapse = "\n"))
# wrapLog(msg_DESCRIPTION)
} else resultLog(Log, "OK")
}

if (test_dir == "tests")
checkingLog(Log, "tests")
else
checkingLog(Log, "tests in ", sQuote(test_dir))
if (is_demo) {
if (do_demo) {
checkingLog(Log, "demos")
do_tests <- TRUE
} else return()
} else {
if (test_dir == "tests")
checkingLog(Log, "tests")
else
checkingLog(Log, "tests in ", sQuote(test_dir))
}

run_one_arch <- function(arch = "")
{
testsrcdir <- file.path(pkgdir, test_dir)
testdir <- file.path(pkgoutdir, "tests")
testdir <- file.path(pkgoutdir, if (is_demo) "demo" else "tests")
if(nzchar(arch)) testdir <- paste(testdir, arch, sep = "_")
if(!dir.exists(testdir)) dir.create(testdir, mode = "0755")
if(!dir.exists(testdir)) {
Expand Down Expand Up @@ -6900,6 +6915,7 @@ add_dummies <- function(dir, Log)
" --no-vignettes do not run R code in vignettes nor build outputs",
" --no-build-vignettes do not build vignette outputs",
" --ignore-vignettes skip all tests on vignettes",
" --run-demo do run R scripts in 'demo' subdirectory",
" --run-dontrun do run \\dontrun sections in the Rd files",
" --run-donttest do run \\donttest sections in the Rd files",
" --use-gct use 'gctorture(TRUE)' when running examples/tests",
Expand Down Expand Up @@ -6992,6 +7008,7 @@ add_dummies <- function(dir, Log)
multiarch <- NA
force_multiarch <- FALSE
as_cran <- FALSE
do_demo <- FALSE
run_dontrun <- FALSE
run_donttest <- FALSE
stop_on_test_error <- TRUE
Expand Down Expand Up @@ -7053,6 +7070,8 @@ add_dummies <- function(dir, Log)
} else if (a == "--no-latex") {
stop("'--no-latex' is defunct: use '--no-manual' instead",
call. = FALSE, domain = NA)
} else if (a == "--run-demo") {
do_demo <- TRUE
} else if (a == "--run-dontrun") {
run_dontrun <- TRUE
} else if (a == "--run-donttest") {
Expand Down Expand Up @@ -7829,9 +7848,11 @@ add_dummies <- function(dir, Log)
"R_check_bin",
"build_vignettes.log",
"tests", "vign_test",
if (do_demo) "demo",
if(this_multiarch)
c(paste0("examples_", inst_archs),
paste0(pkgname, "-Ex_", inst_archs, ".Rout"),
if (do_demo) paste0("demo_", inst_archs),
paste0("tests_", inst_archs))
))
## Examples calling dev.new() give files Rplots*.pdf,
Expand Down

0 comments on commit 31033df

Please sign in to comment.