diff --git a/DESCRIPTION b/DESCRIPTION index 680f801..4087b44 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,5 +39,5 @@ Remotes: r-lib/cli Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1.9001 +RoxygenNote: 7.1.2 Config/testthat/edition: 3 diff --git a/R/background.R b/R/background.R index 6c68cd2..8661acc 100644 --- a/R/background.R +++ b/R/background.R @@ -74,24 +74,12 @@ rcmdcheck_process <- R6Class( l }, - read_error_lines = function(...) { - l <- super$read_error_lines(...) - private$cstderr <- c(private$cstderr, paste0(l, "\n")) - l - }, - read_output = function(...) { l <- super$read_output(...) private$cstdout <- c(private$cstdout, l) l }, - read_error = function(...) { - l <- super$read_error(...) - private$cstderr <- c(private$cstderr, l) - l - }, - kill = function(...) { private$killed <- TRUE super$kill(...) @@ -132,9 +120,7 @@ rcc_init <- function(self, private, super, path, args, build_args, # Add pandoc to the PATH for R CMD build. # The updated PATH is also inherited in the subprocess below. - if (!nzchar(Sys.which("pandoc")) && nzchar(Sys.getenv("RSTUDIO_PANDOC"))) { - local_path(Sys.getenv("RSTUDIO_PANDOC")) - } + if (should_use_rs_pandoc()) local_path(Sys.getenv("RSTUDIO_PANDOC")) pkgbuild::local_build_tools() diff --git a/R/callback.R b/R/callback.R index 20f4498..9beb804 100644 --- a/R/callback.R +++ b/R/callback.R @@ -220,51 +220,20 @@ block_callback <- function(top_line = TRUE, sys_time = NULL) { } } -to_status <- function(x) { - notes <- warnings <- errors <- 0 - if (grepl("ERROR", x)) { - errors <- as.numeric(sub("^.* ([0-9]+) ERROR.*$", "\\1", x)) - } - if (grepl("WARNING", x)) { - warnings <- as.numeric(sub("^.* ([0-9]+) WARNING.*$", "\\1", x)) - } - if (grepl("NOTE", x)) { - notes <- as.numeric(sub("^.* ([0-9]+) NOTE.*$", "\\1", x)) - } - structure( - list( - notes = rep("", notes), - warnings = rep("", warnings), - errors = rep("", errors) - ), - class = "rcmdcheck" - ) -} - is_new_check <- function(x) { grepl("^\\*\\*? ", x) } -simple_callback <- function(top_line = TRUE) { +simple_callback <- function(top_line = TRUE, sys_time = NULL) { function(x) cat(gsub("[\r\n]+", "\n", x, useBytes = TRUE)) } -detect_callback <- function() { - if (is_dynamic_tty2()) block_callback() else simple_callback() -} - #' @importFrom cli is_dynamic_tty -is_dynamic_tty2 <- function() { - ## This is to work around a cli bug: - ## https://github.com/r-lib/cli/issues/70 - if ((x <- Sys.getenv("R_CLI_DYNAMIC", "")) != "") { - isTRUE(x) - } else { - is_dynamic_tty() - } +detect_callback <- function() { + if (cli::is_dynamic_tty()) block_callback() else simple_callback() } should_add_spinner <- function() { - is_dynamic_tty2() + is_dynamic_tty() } diff --git a/R/options.R b/R/options.R index c3ab8f0..336b2a7 100644 --- a/R/options.R +++ b/R/options.R @@ -43,9 +43,17 @@ #' fractional. Defaults to 1/3 of a second. The corresponding option is #' `rcmdcheck.timestamp_limit`. #' +#' * `RCMDCHECK_USE_RSTUDIO_PANDOC`: Flag (`true` or `false`). If `true`, +#' then rcmdcheck _always_ puts RStudio's pandoc (if available) on the +#' path. If `false`, then it _never_ does that. If not set, or set to a +#' different value, then pandoc is put on the path only if it is not +#' already available. RStudio's pandoc is detected via an `RSTUDIO_PANDOC` +#' environment variable. +#' #' * `RSTUDIO_PANDOC`: if set, rcmdcheck adds this environment variable #' to the PATH if pandoc is not on the PATH already. It is usually set -#' in RStudio. +#' in RStudio. See also the `RCMDCHECK_USE_RSTUDIO_PANDOC` environment +#' variable. #' #' # Options #' diff --git a/R/package.R b/R/package.R index eeccb75..3d6a628 100644 --- a/R/package.R +++ b/R/package.R @@ -76,9 +76,7 @@ rcmdcheck <- function(path = ".", quiet = FALSE, args = character(), } # Add pandoc to the PATH, for R CMD build and R CMD check - if (!nzchar(Sys.which("pandoc")) && nzchar(Sys.getenv("RSTUDIO_PANDOC"))) { - local_path(Sys.getenv("RSTUDIO_PANDOC")) - } + if (should_use_rs_pandoc()) local_path(Sys.getenv("RSTUDIO_PANDOC")) pkgbuild::local_build_tools() diff --git a/R/utils.R b/R/utils.R index e522d7f..8ea389b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -184,3 +184,17 @@ as_flag <- function(x, default = FALSE, name = "") { no_timing <- function(x) { gsub("\\[[0-9]+s(/[0-9]+s)?\\] ([A-Z]+)", "\\2", x, useBytes = TRUE) } + +should_use_rs_pandoc <- function() { + ev <- Sys.getenv("RCMDCHECK_USE_RSTUDIO_PANDOC", "") + + if (tolower(ev) == "true") { + TRUE + + } else if (tolower(ev) == "false") { + FALSE + + } else { + !nzchar(Sys.which("pandoc")) && nzchar(Sys.getenv("RSTUDIO_PANDOC")) + } +} diff --git a/man/rcmdcheck-config.Rd b/man/rcmdcheck-config.Rd index 1aabf5a..fe93a2a 100644 --- a/man/rcmdcheck-config.Rd +++ b/man/rcmdcheck-config.Rd @@ -39,9 +39,16 @@ option is \code{rcmdcheck.num_colors}. rcmdcheck adds time stamps to the individual check steps. It may be fractional. Defaults to 1/3 of a second. The corresponding option is \code{rcmdcheck.timestamp_limit}. +\item \code{RCMDCHECK_USE_RSTUDIO_PANDOC}: Flag (\code{true} or \code{false}). If \code{true}, +then rcmdcheck \emph{always} puts RStudio's pandoc (if available) on the +path. If \code{false}, then it \emph{never} does that. If not set, or set to a +different value, then pandoc is put on the path only if it is not +already available. RStudio's pandoc is detected via an \code{RSTUDIO_PANDOC} +environment variable. \item \code{RSTUDIO_PANDOC}: if set, rcmdcheck adds this environment variable to the PATH if pandoc is not on the PATH already. It is usually set -in RStudio. +in RStudio. See also the \code{RCMDCHECK_USE_RSTUDIO_PANDOC} environment +variable. } } diff --git a/tests/testthat/_snaps/callback.md b/tests/testthat/_snaps/callback.md index ff0c8d1..978ac7c 100644 --- a/tests/testthat/_snaps/callback.md +++ b/tests/testthat/_snaps/callback.md @@ -331,3 +331,204 @@ [7] "\r \rv checking package vignettes in ‘inst/doc’" [8] "\r" +# multi-arch test cases + + Code + out + Output + [1] " \r- using log directory 'C:/Users/csard/works/ps.Rcheck'" + [2] "\r \r- using R version 4.1.1 (2021-08-10)" + [3] "\r \r- using platform: x86_64-w64-mingw32 (64-bit)" + [4] "\r \r- using session charset: ISO8859-1" + [5] "\r \rv checking for file 'ps/DESCRIPTION'" + [6] "\r \r- this is package 'ps' version '1.3.2.9000'" + [7] "\r \rv checking for unstated dependencies in 'tests'" + [8] "\r \r- checking tests" + [9] "\r \r-- running tests for arch 'i386' " + [10] "\r \r\r \rv Running 'testthat.R'" + [11] "\r \r-- running tests for arch 'x64' " + [12] "\r \r\r \rv Running 'testthat.R'" + [13] "\r \rv checking PDF version of manual" + [14] "\r \r\r" + +# failed test case + + Code + out + Output + [1] " \rv checking for unstated dependencies in ‘tests’" + [2] "\r \r- checking tests" + [3] "\r \r\r \rE Running ‘testthat.R’" + [4] "\r \r Running the tests in ‘tests/testthat.R’ failed." + [5] "\r \r Last 13 lines of output:" + [6] "\r \r ⠏ | 0 | windows " + [7] "\r \r ⠏ | 0 | winver " + [8] "\r \r ⠏ | 0 | winver " + [9] "\r \r ✔ | 6 | winver" + [10] "\r \r " + [11] "\r \r ══ Results ═════════════════════════════════════════════════════════════════════" + [12] "\r \r Duration: 13.5 s" + [13] "\r \r " + [14] "\r \r ── Skipped tests ──────────────────────────────────────────────────────────────" + [15] "\r \r • Needs working IPv6 connection (2)" + [16] "\r \r • On CRAN (13)" + [17] "\r \r " + [18] "\r \r [ FAIL 1 | WARN 0 | SKIP 15 | PASS 367 ]" + [19] "\r \r Error: Test failures" + [20] "\r \r Execution halted" + [21] "\r \rv checking PDF version of manual" + [22] "\r \r\r" + +# comparing test output + + Code + out + Output + [1] " \rv checking for unstated dependencies in ‘tests’" + [2] "\r \r- checking tests" + [3] "\r \r\r \rv Running ‘first_edition.R’" + [4] "\r \rv Running ‘second_edition.R’" + [5] "\r \rv Running ‘spelling.R’" + [6] "X Comparing ‘spelling.Rout’ to ‘spelling.Rout.save’" + [7] " 6,8d5" + [8] "\r \r < Potential spelling errors:" + [9] "\r \r < WORD FOUND IN" + [10] "\r \r < programatically NEWS.md:14" + [11] "\r \r\r \rv checking for unstated dependencies in vignettes" + [12] "\r \rv checking package vignettes in ‘inst/doc’" + [13] "\r" + +# partial comparing line + + Code + out + Output + [1] " \r- checking tests" + [2] "\r \r\r \rv Running ‘test-1.R’" + [3] " Comparing ‘test-1.Rout’ to \r \rv Comparing ‘test-1.Rout’ to ‘test-1.Rout.save’" + [4] "\r \r\r \rv Running ‘test-2.R’" + [5] "v Comparing ‘test-2.Rout’ to ‘test-2.Rout.save’" + [6] "\r \r\r \rv checking PDF version of manual" + [7] "\r \r\r" + +# multiple comparing blocks + + Code + out + Output + [1] " \rv checking examples" + [2] "\r \rv checking for unstated dependencies in ‘tests’" + [3] "\r \r- checking tests" + [4] "\r \r\r \rv Running ‘test-1.R’" + [5] "v Comparing ‘test-1.Rout’ to ‘test-1.Rout.save’" + [6] "\r \r\r \rv Running ‘test-2.R’" + [7] "v Comparing ‘test-2.Rout’ to ‘test-2.Rout.save’" + [8] "\r \r\r \rv Running ‘test.R’" + [9] "X Comparing ‘test.Rout’ to ‘test.Rout.save’" + [10] " 1,4d0" + [11] "\r \r <" + [12] "\r \r <" + [13] "\r \r < >" + [14] "\r \r < > cat(\"This is the output.\\n\")" + [15] "\r \r 6d1" + [16] "\r \r < >" + [17] "\r \r\r \r " + [18] "\r \rE" + [19] "\r \r Running the tests in ‘tests/testthat.R’ failed." + [20] "\r \r Last 13 lines of output:" + [21] "\r \r + ## ps does not support this platform" + [22] "\r \r + reporter <- \"progress\"" + [23] "\r \r + }" + [24] "\r \r >" + [25] "\r \r > if (ps_is_supported()) test_check(\"ps\", reporter = reporter)" + [26] "\r \r cleanup-reporter:" + [27] "\r \r cleanup testthat reporter: ......................................................................................................................................" + [28] "\r \r common:" + [29] "\r \r common: ...................................................................................................................................................." + [30] "\r \r connections:" + [31] "\r \r connections: ................................................................S............S............" + [32] "\r \r finished:" + [33] "\r \r process finished: ..................................................................................." + [34] "\r \r kill-tree:" + [35] "\r \r kill-tree: ..............................................." + [36] "\r \rv checking PDF version of manual" + [37] "\r" + +# simple_callback + + Code + out + Output + [1] "* using log directory ‘/private/tmp/readr.Rcheck’" + [2] "* using R version 4.1.0 (2021-05-18)" + [3] "* using platform: x86_64-apple-darwin17.0 (64-bit)" + [4] "* using session charset: UTF-8" + [5] "* checking for file ‘readr/DESCRIPTION’ ... OK" + [6] "* this is package ‘readr’ version ‘2.0.1.9000’" + [7] "* package encoding: UTF-8" + [8] "* checking package namespace information ... OK" + [9] "* checking package dependencies ... OK" + [10] "* checking if this is a source package ... OK" + [11] "* checking if there is a namespace ... OK" + [12] "* checking for executable files ... OK" + [13] "* checking for hidden files and directories ... OK" + [14] "* checking for portable file names ... OK" + [15] "* checking for sufficient/correct file permissions ... OK" + [16] "* checking whether package ‘readr’ can be installed ... OK" + [17] "* checking installed package size ... OK" + [18] "* checking package directory ... OK" + [19] "* checking ‘build’ directory ... OK" + [20] "* checking DESCRIPTION meta-information ... OK" + [21] "* checking top-level files ... OK" + [22] "* checking for left-over files ... OK" + [23] "* checking index information ... OK" + [24] "* checking package subdirectories ... OK" + [25] "* checking R files for non-ASCII characters ... OK" + [26] "* checking R files for syntax errors ... OK" + [27] "* checking whether the package can be loaded ... OK" + [28] "* checking whether the package can be loaded with stated dependencies ... OK" + [29] "* checking whether the package can be unloaded cleanly ... OK" + [30] "* checking whether the namespace can be loaded with stated dependencies ... OK" + [31] "* checking whether the namespace can be unloaded cleanly ... OK" + [32] "* checking loading without being on the library search path ... OK" + [33] "* checking dependencies in R code ... OK" + [34] "* checking S3 generic/method consistency ... OK" + [35] "* checking replacement functions ... OK" + [36] "* checking foreign function calls ... OK" + [37] "* checking R code for possible problems ... OK" + [38] "* checking Rd files ... OK" + [39] "* checking Rd metadata ... OK" + [40] "* checking Rd cross-references ... OK" + [41] "* checking for missing documentation entries ... OK" + [42] "* checking for code/documentation mismatches ... OK" + [43] "* checking Rd \\usage sections ... OK" + [44] "* checking Rd contents ... OK" + [45] "* checking for unstated dependencies in examples ... OK" + [46] "* checking R/sysdata.rda ... OK" + [47] "* checking line endings in C/C++/Fortran sources/headers ... OK" + [48] "* checking compiled code ... OK" + [49] "* checking installed files from ‘inst/doc’ ... OK" + [50] "* checking files in ‘vignettes’ ... OK" + [51] "* checking examples ... OK" + [52] "* checking for unstated dependencies in ‘tests’ ... OK" + [53] "* checking tests ..." + [54] " Running ‘first_edition.R’" + [55] " Running ‘second_edition.R’" + [56] " Running ‘spelling.R’" + [57] " Comparing ‘spelling.Rout’ to ‘spelling.Rout.save’ ...6,8d5" + [58] "< Potential spelling errors:" + [59] "< WORD FOUND IN" + [60] "< programatically NEWS.md:14" + [61] " OK" + [62] "* checking for unstated dependencies in vignettes ... OK" + [63] "* checking package vignettes in ‘inst/doc’ ... OK" + [64] "* checking running R code from vignettes ..." + [65] " ‘locales.Rmd’ using ‘UTF-8’... OK" + [66] " ‘readr.Rmd’ using ‘UTF-8’... OK" + [67] " NONE" + [68] "* checking re-building of vignette outputs ... OK" + [69] "* checking PDF version of manual ... OK" + [70] "* DONE" + [71] "" + [72] "Status: OK" + diff --git a/tests/testthat/fixtures/checks/comparing.txt b/tests/testthat/fixtures/checks/comparing.txt new file mode 100644 index 0000000..2e21c12 --- /dev/null +++ b/tests/testthat/fixtures/checks/comparing.txt @@ -0,0 +1,72 @@ +* using log directory ‘/private/tmp/readr.Rcheck’ +* using R version 4.1.0 (2021-05-18) +* using platform: x86_64-apple-darwin17.0 (64-bit) +* using session charset: UTF-8 +* checking for file ‘readr/DESCRIPTION’ ... OK +* this is package ‘readr’ version ‘2.0.1.9000’ +* package encoding: UTF-8 +* checking package namespace information ... OK +* checking package dependencies ... OK +* checking if this is a source package ... OK +* checking if there is a namespace ... OK +* checking for executable files ... OK +* checking for hidden files and directories ... OK +* checking for portable file names ... OK +* checking for sufficient/correct file permissions ... OK +* checking whether package ‘readr’ can be installed ... OK +* checking installed package size ... OK +* checking package directory ... OK +* checking ‘build’ directory ... OK +* checking DESCRIPTION meta-information ... OK +* checking top-level files ... OK +* checking for left-over files ... OK +* checking index information ... OK +* checking package subdirectories ... OK +* checking R files for non-ASCII characters ... OK +* checking R files for syntax errors ... OK +* checking whether the package can be loaded ... OK +* checking whether the package can be loaded with stated dependencies ... OK +* checking whether the package can be unloaded cleanly ... OK +* checking whether the namespace can be loaded with stated dependencies ... OK +* checking whether the namespace can be unloaded cleanly ... OK +* checking loading without being on the library search path ... OK +* checking dependencies in R code ... OK +* checking S3 generic/method consistency ... OK +* checking replacement functions ... OK +* checking foreign function calls ... OK +* checking R code for possible problems ... OK +* checking Rd files ... OK +* checking Rd metadata ... OK +* checking Rd cross-references ... OK +* checking for missing documentation entries ... OK +* checking for code/documentation mismatches ... OK +* checking Rd \usage sections ... OK +* checking Rd contents ... OK +* checking for unstated dependencies in examples ... OK +* checking R/sysdata.rda ... OK +* checking line endings in C/C++/Fortran sources/headers ... OK +* checking compiled code ... OK +* checking installed files from ‘inst/doc’ ... OK +* checking files in ‘vignettes’ ... OK +* checking examples ... OK +* checking for unstated dependencies in ‘tests’ ... OK +* checking tests ... + Running ‘first_edition.R’ + Running ‘second_edition.R’ + Running ‘spelling.R’ + Comparing ‘spelling.Rout’ to ‘spelling.Rout.save’ ...6,8d5 +< Potential spelling errors: +< WORD FOUND IN +< programatically NEWS.md:14 + OK +* checking for unstated dependencies in vignettes ... OK +* checking package vignettes in ‘inst/doc’ ... OK +* checking running R code from vignettes ... + ‘locales.Rmd’ using ‘UTF-8’... OK + ‘readr.Rmd’ using ‘UTF-8’... OK + NONE +* checking re-building of vignette outputs ... OK +* checking PDF version of manual ... OK +* DONE + +Status: OK diff --git a/tests/testthat/fixtures/checks/comparing2.txt b/tests/testthat/fixtures/checks/comparing2.txt new file mode 100644 index 0000000..21ff978 --- /dev/null +++ b/tests/testthat/fixtures/checks/comparing2.txt @@ -0,0 +1,94 @@ +* using log directory ‘/Users/gaborcsardi/works/ps.Rcheck’ +* using R version 4.1.0 (2021-05-18) +* using platform: x86_64-apple-darwin17.0 (64-bit) +* using session charset: UTF-8 +* checking for file ‘ps/DESCRIPTION’ ... OK +* this is package ‘ps’ version ‘1.6.0.9000’ +* package encoding: UTF-8 +* checking package namespace information ... OK +* checking package dependencies ... OK +* checking if this is a source package ... OK +* checking if there is a namespace ... OK +* checking for executable files ... OK +* checking for hidden files and directories ... OK +* checking for portable file names ... OK +* checking for sufficient/correct file permissions ... OK +* checking whether package ‘ps’ can be installed ... OK +* checking installed package size ... OK +* checking package directory ... OK +* checking DESCRIPTION meta-information ... OK +* checking top-level files ... OK +* checking for left-over files ... OK +* checking index information ... OK +* checking package subdirectories ... OK +* checking R files for non-ASCII characters ... OK +* checking R files for syntax errors ... OK +* checking whether the package can be loaded ... OK +* checking whether the package can be loaded with stated dependencies ... OK +* checking whether the package can be unloaded cleanly ... OK +* checking whether the namespace can be loaded with stated dependencies ... OK +* checking whether the namespace can be unloaded cleanly ... OK +* checking loading without being on the library search path ... OK +* checking dependencies in R code ... OK +* checking S3 generic/method consistency ... OK +* checking replacement functions ... OK +* checking foreign function calls ... OK +* checking R code for possible problems ... OK +* checking Rd files ... OK +* checking Rd metadata ... OK +* checking Rd cross-references ... OK +* checking for missing documentation entries ... OK +* checking for code/documentation mismatches ... OK +* checking Rd \usage sections ... OK +* checking Rd contents ... OK +* checking for unstated dependencies in examples ... OK +* checking line endings in shell scripts ... OK +* checking line endings in C/C++/Fortran sources/headers ... OK +* checking line endings in Makefiles ... OK +* checking compilation flags in Makevars ... OK +* checking for GNU extensions in Makefiles ... OK +* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK +* checking use of PKG_*FLAGS in Makefiles ... OK +* checking compiled code ... OK +* checking examples ... OK +* checking for unstated dependencies in ‘tests’ ... OK +* checking tests ... + Running ‘test-1.R’ + Comparing ‘test-1.Rout’ to ‘test-1.Rout.save’ ... OK + Running ‘test-2.R’ + Comparing ‘test-2.Rout’ to ‘test-2.Rout.save’ ... OK + Running ‘test.R’ + Comparing ‘test.Rout’ to ‘test.Rout.save’ ...1,4d0 +< +< +< > +< > cat("This is the output.\n") +6d1 +< > + Running ‘testthat.R’/Library/Frameworks/R.framework/Versions/4.1/Resources/bin/BATCH: line 60: 84659 Abort trap: 6 ${R_HOME}/bin/R -f ${in} ${opts} ${R_BATCH_OPTIONS} > ${out} 2>&1 + + ERROR +Running the tests in ‘tests/testthat.R’ failed. +Last 13 lines of output: + + ## ps does not support this platform + + reporter <- "progress" + + } + > + > if (ps_is_supported()) test_check("ps", reporter = reporter) + cleanup-reporter: + cleanup testthat reporter: ...................................................................................................................................... + common: + common: .................................................................................................................................................... + connections: + connections: ................................................................S............S............ + finished: + process finished: ................................................................................... + kill-tree: + kill-tree: ............................................... +* checking PDF version of manual ... OK +* DONE + +Status: 1 ERROR +See + ‘/Users/gaborcsardi/works/ps.Rcheck/00check.log’ +for details. diff --git a/tests/testthat/fixtures/checks/test-error.txt b/tests/testthat/fixtures/checks/test-error.txt new file mode 100644 index 0000000..e6745e3 --- /dev/null +++ b/tests/testthat/fixtures/checks/test-error.txt @@ -0,0 +1,82 @@ +* using log directory ‘/Users/gaborcsardi/works/ps.Rcheck’ +* using R version 4.1.0 (2021-05-18) +* using platform: x86_64-apple-darwin17.0 (64-bit) +* using session charset: UTF-8 +* checking for file ‘ps/DESCRIPTION’ ... OK +* this is package ‘ps’ version ‘1.6.0.9000’ +* package encoding: UTF-8 +* checking package namespace information ... OK +* checking package dependencies ... OK +* checking if this is a source package ... OK +* checking if there is a namespace ... OK +* checking for executable files ... OK +* checking for hidden files and directories ... OK +* checking for portable file names ... OK +* checking for sufficient/correct file permissions ... OK +* checking whether package ‘ps’ can be installed ... OK +* checking installed package size ... OK +* checking package directory ... OK +* checking DESCRIPTION meta-information ... OK +* checking top-level files ... OK +* checking for left-over files ... OK +* checking index information ... OK +* checking package subdirectories ... OK +* checking R files for non-ASCII characters ... OK +* checking R files for syntax errors ... OK +* checking whether the package can be loaded ... OK +* checking whether the package can be loaded with stated dependencies ... OK +* checking whether the package can be unloaded cleanly ... OK +* checking whether the namespace can be loaded with stated dependencies ... OK +* checking whether the namespace can be unloaded cleanly ... OK +* checking loading without being on the library search path ... OK +* checking dependencies in R code ... OK +* checking S3 generic/method consistency ... OK +* checking replacement functions ... OK +* checking foreign function calls ... OK +* checking R code for possible problems ... OK +* checking Rd files ... OK +* checking Rd metadata ... OK +* checking Rd cross-references ... OK +* checking for missing documentation entries ... OK +* checking for code/documentation mismatches ... OK +* checking Rd \usage sections ... OK +* checking Rd contents ... OK +* checking for unstated dependencies in examples ... OK +* checking line endings in shell scripts ... OK +* checking line endings in C/C++/Fortran sources/headers ... OK +* checking line endings in Makefiles ... OK +* checking compilation flags in Makevars ... OK +* checking for GNU extensions in Makefiles ... OK +* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK +* checking use of PKG_*FLAGS in Makefiles ... OK +* checking compiled code ... OK +* checking examples ... OK +* checking for unstated dependencies in ‘tests’ ... OK +* checking tests ... + Running ‘testthat.R’ + ERROR +Running the tests in ‘tests/testthat.R’ failed. +Last 13 lines of output: + ⠏ | 0 | windows + ⠏ | 0 | winver + ⠏ | 0 | winver + ✔ | 6 | winver + + ══ Results ═════════════════════════════════════════════════════════════════════ + Duration: 13.5 s + + ── Skipped tests ────────────────────────────────────────────────────────────── + • Needs working IPv6 connection (2) + • On CRAN (13) + + [ FAIL 1 | WARN 0 | SKIP 15 | PASS 367 ] + Error: Test failures + Execution halted +* checking PDF version of manual ... OK +* DONE + +Status: 1 ERROR +See + ‘/Users/gaborcsardi/works/ps.Rcheck/00check.log’ +for details. + diff --git a/tests/testthat/helpers.R b/tests/testthat/helpers.R index 4a1b659..6556363 100644 --- a/tests/testthat/helpers.R +++ b/tests/testthat/helpers.R @@ -29,3 +29,16 @@ cran_app <- function() { app } + +replay <- function(frames, callback = NULL) { + callback <- callback %||% block_callback + time <- Sys.time() + timer <- function() time + cb <- callback(sys_time = timer) + for (frame in frames) { + cb(frame[[1]]) + if (frame[[2]] > 0) { + time <- time + frame[[2]] + } + } +} diff --git a/tests/testthat/test-callback.R b/tests/testthat/test-callback.R index 13c2731..0ff01d6 100644 --- a/tests/testthat/test-callback.R +++ b/tests/testthat/test-callback.R @@ -1,5 +1,5 @@ -test_that("block_callback by line", { + test_that("block_callback by line", { withr::local_options(rcmdcheck.timestamp_limit = 1000) chk <- readLines(test_path("fixtures", "test-error.txt")) cb <- block_callback() @@ -121,18 +121,93 @@ test_that("multiple test file run times are measured properly", { list("* checking package vignettes in ‘inst/doc’ ... OK\n", 0) ) - replay <- function(frames) { - time <- Sys.time() - timer <- function() time - cb <- block_callback(sys_time = timer) - for (frame in frames) { - cb(frame[[1]]) - if (frame[[2]] > 0) { - time <- time + frame[[2]] - } - } - } + out <- capture.output(replay(txt)) + expect_snapshot(out) +}) + +test_that("multi-arch test cases", { + txt <- list( + list("* using log directory 'C:/Users/csard/works/ps.Rcheck'\n", 0.01), + list("* using R version 4.1.1 (2021-08-10)\n", 0.01), + list("* using platform: x86_64-w64-mingw32 (64-bit)\n", 0.01), + list("* using session charset: ISO8859-1\n", 0.01), + list("* checking for file 'ps/DESCRIPTION' ... OK\n", 0.01), + list("* this is package 'ps' version '1.3.2.9000'\n", 0.01), + list("* checking for unstated dependencies in 'tests' ... OK\n", 0.01), + list("* checking tests ...\n", 0.01), + list("** running tests for arch 'i386' ...\n", 0.01), + list(" Running 'testthat.R'\n", 0.01), + list(" OK\n", 0.01), + list("** running tests for arch 'x64' ...\n", 0.01), + list(" Running 'testthat.R'\n", 0.01), + list(" OK\n", 0.01), + list("* checking PDF version of manual ... OK\n", 0.01), + list("* DONE\n", 0.01) + ) out <- capture.output(replay(txt)) expect_snapshot(out) }) + +test_that("failed test case", { + txt <- readLines(test_path("fixtures", "checks", "test-error.txt"))[54:76] + lines <- lapply(txt, function(x) list(paste0(x, "\n"), 0.001)) + out <- capture.output(replay(lines)) + expect_snapshot(out) +}) + +test_that("comparing test output", { + txt <- readLines(test_path("fixtures", "checks", "comparing.txt"))[52:63] + lines <- lapply(txt, function(x) list(paste0(x, "\n"), 0.001)) + out <- capture.output(replay(lines)) + expect_snapshot(out) +}) + +test_that("partial comparing line", { + lines <- list( + list("* checking tests ...\n", 0), + list(" Running ‘test-1.R’\n", 0), + list(" Comparing ‘test-1.Rout’ to ", 0), + list("‘test-1.Rout.save’ ... OK\n", 0), + list(" Running ‘test-2.R’\n", 0), + list(" Comparing ‘test-2.Rout’ to ‘test-2.Rout.save’ ... OK\n", 0), + list(" OK\n", 0.01), + list("* checking PDF version of manual ... OK\n", 0.01), + list("* DONE\n", 0.01) + ) + + out <- capture.output(replay(lines)) + expect_snapshot(out) +}) + +test_that("multiple comparing blocks", { + txt <- readLines(test_path("fixtures", "checks", "comparing2.txt"))[53:88] + lines <- lapply(txt, function(x) list(paste0(x, "\n"), 0.001)) + out <- capture.output(replay(lines)) + expect_snapshot(out) +}) + +test_that("simple_callback", { + txt <- readLines(test_path("fixtures", "checks", "comparing.txt")) + lines <- lapply(txt, function(x) list(paste0(x, "\n"), 0.001)) + out <- capture.output(replay(lines, simple_callback)) + expect_snapshot(out) +}) + +test_that("detect_callback", { + mockery::stub(detect_callback, "block_callback", "block") + mockery::stub(detect_callback, "simple_callback", "simple") + + withr::local_options(cli.dynamic = TRUE) + expect_equal(detect_callback(), "block") + + withr::local_options(cli.dynamic = FALSE) + expect_equal(detect_callback(), "simple") +}) + +test_that("should_add_spinner", { + withr::local_options(cli.dynamic = TRUE) + expect_true(should_add_spinner()) + withr::local_options(cli.dynamic = FALSE) + expect_false(should_add_spinner()) +}) diff --git a/tests/testthat/test-rcmdcheck.R b/tests/testthat/test-rcmdcheck.R index 5ffaf97..0461786 100644 --- a/tests/testthat/test-rcmdcheck.R +++ b/tests/testthat/test-rcmdcheck.R @@ -91,7 +91,11 @@ test_that("background gives same results", { test_path("bad1"), libpath = c(tmp_lib, .libPaths())) # If we read out the output, it'll still save it internally + bad1$read_output() bad1$read_all_output_lines() + # No separate stderr by default + expect_error(bad1$read_error()) + expect_error(bad1$read_all_error_lines()) res <- bad1$parse_results() expect_match(res$warnings[1], "Non-standard license specification") diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 04b260d..2a99d7d 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -28,3 +28,23 @@ test_that("as_flag", { as_flag("boo", TRUE, "thisthat") ) }) + +test_that("should_use_rs_pandoc", { + withr::local_envvar(RCMDCHECK_USE_RSTUDIO_PANDOC = "false") + expect_false(should_use_rs_pandoc()) + + withr::local_envvar(RCMDCHECK_USE_RSTUDIO_PANDOC = "true") + expect_true(should_use_rs_pandoc()) + + withr::local_envvar(RCMDCHECK_USE_RSTUDIO_PANDOC = NA_character_) + mockery::stub(should_use_rs_pandoc, "Sys.which", "") + withr::local_envvar(RSTUDIO_PANDOC = "yes") + expect_true(should_use_rs_pandoc()) + + withr::local_envvar(RSTUDIO_PANDOC = NA_character_) + expect_false(should_use_rs_pandoc()) + + mockery::stub(should_use_rs_pandoc, "Sys.which", "pandoc") + withr::local_envvar(RSTUDIO_PANDOC = "yes") + expect_false(should_use_rs_pandoc()) +})