diff --git a/.Rbuildignore b/.Rbuildignore index 7219301..84326b2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,4 +1,4 @@ -\.github +^\.github$ codecov\.yml LICENSE\.md pkgdown diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index ee65ccb..69cfc6a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -8,9 +8,10 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] -name: R-CMD-check +name: R-CMD-check.yaml + +permissions: read-all jobs: R-CMD-check: @@ -25,24 +26,22 @@ jobs: - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - # Use 3.6 to trigger usage of RTools35 - - {os: windows-latest, r: '3.6'} - # use 4.1 to check with rtools40's older compiler - - {os: windows-latest, r: '4.1'} - - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - - {os: ubuntu-latest, r: 'release'} - - {os: ubuntu-latest, r: 'oldrel-1'} - - {os: ubuntu-latest, r: 'oldrel-2'} - - {os: ubuntu-latest, r: 'oldrel-3'} - - {os: ubuntu-latest, r: 'oldrel-4'} + # use 4.0 or 4.1 to check with rtools40's older compiler + - {os: windows-latest, r: 'oldrel-4'} + + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + - {os: ubuntu-latest, r: 'oldrel-2'} + - {os: ubuntu-latest, r: 'oldrel-3'} + - {os: ubuntu-latest, r: 'oldrel-4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -60,3 +59,4 @@ jobs: - uses: r-lib/actions/check-r-package@v2 with: upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 087f0b0..bfc9f4d 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -4,12 +4,13 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] release: types: [published] workflow_dispatch: -name: pkgdown +name: pkgdown.yaml + +permissions: read-all jobs: pkgdown: @@ -19,8 +20,10 @@ jobs: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -39,7 +42,7 @@ jobs: - name: Deploy to GitHub pages 🚀 if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@v4.4.1 + uses: JamesIves/github-pages-deploy-action@v4.5.0 with: clean: false branch: gh-pages diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb50..0ab748d 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -4,9 +4,10 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] -name: test-coverage +name: test-coverage.yaml + +permissions: read-all jobs: test-coverage: @@ -15,7 +16,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 with: @@ -23,28 +24,39 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::covr + extra-packages: any::covr, any::xml2 needs: coverage - name: Test coverage run: | - covr::codecov( + cov <- covr::package_coverage( quiet = FALSE, clean = FALSE, - install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") ) + print(cov) + covr::to_cobertura(cov) shell: Rscript {0} + - uses: codecov/codecov-action@v5 + with: + # Fail if error if not on PR, or if on PR and token is given + fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} + files: ./cobertura.xml + plugins: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + - name: Show testthat output if: always() run: | ## -------------------------------------------------------------------- - find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true shell: bash - name: Upload test results if: failure() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: coverage-test-failures path: ${{ runner.temp }}/package diff --git a/DESCRIPTION b/DESCRIPTION index 35815af..67b491b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: testex Title: Add Tests to Examples -Version: 0.2.0.9000 +Version: 0.2.0.9001 Authors@R: c( person( @@ -30,6 +30,6 @@ Suggests: rmarkdown Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Language: en-US VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index b519cd0..a127f95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,11 @@ > in documentation files may fail if interface changes. > +# testex 0.2.1 + +* Updated internals to be compatible with the next version of `testthat` + following `v3.2.3`. (@dgkf #12) + # testex 0.2.0 ## Breaking Changes diff --git a/R/testthat.R b/R/testthat.R index 29801be..9caad36 100644 --- a/R/testthat.R +++ b/R/testthat.R @@ -23,7 +23,6 @@ NULL - #' Raise `testthat` Expectations With A Known Source Reference #' #' Retroactively assigns a source file and location to a expectation. This @@ -55,7 +54,6 @@ with_srcref <- function(src, expr, envir = parent.frame()) { } - #' Expect no Error #' #' @note This is a stop-gap implementation, and will only be used for legacy @@ -102,7 +100,6 @@ expect_no_error_call <- function() { } - #' Execute examples from Rd files as `testthat` tests #' #' Reads examples from Rd files and constructs `testthat`-style tests. @@ -150,14 +147,15 @@ expect_no_error_call <- function() { #' #' @export test_examples_as_testthat <- function( - package, - path, - ..., - test_dir = file.path(tempdir(), "testex-tests"), - clean = TRUE, - overwrite = TRUE, - roxygenize = !is_r_cmd_check() && uses_roxygen2(path), - reporter = testthat::get_reporter()) { + package, + path, + ..., + test_dir = file.path(tempdir(), "testex-tests"), + clean = TRUE, + overwrite = TRUE, + roxygenize = !is_r_cmd_check() && uses_roxygen2(path), + reporter = testthat::get_reporter() +) { requireNamespace("testthat") testthat_envvar_val <- Sys.getenv("TESTTHAT") Sys.setenv(TESTTHAT = "true") @@ -167,7 +165,9 @@ test_examples_as_testthat <- function( path <- find_package_root(testthat::test_path()) } - if (isTRUE(roxygenize)) roxygenize <- list() + if (isTRUE(roxygenize)) { + roxygenize <- list() + } if (is.list(roxygenize) && requireNamespace("roxygen2", quietly = TRUE)) { args <- roxygenize args$package.dir <- path @@ -187,15 +187,15 @@ test_examples_as_testthat <- function( } if (test_dir_exists && !overwrite) { - test_files <- list.files(test_dir, full.names = TRUE) + test_file_paths <- list.files(test_dir, full.names = TRUE) context <- cliless("{.pkg testex} testing examples") - test_files(test_files, context, chdir = FALSE) + test_files(test_file_paths, context, reporter = reporter, chdir = FALSE) return() } # find example sections and convert them to tests rd_examples <- Filter(Negate(is.null), lapply(rds, rd_extract_examples)) - test_files <- lapply(seq_along(rd_examples), function(i) { + test_file_paths <- lapply(seq_along(rd_examples), function(i) { rd_filename <- names(rd_examples[i]) rd_example <- rd_examples[[i]] @@ -217,26 +217,36 @@ test_examples_as_testthat <- function( }) context <- cliless("{.pkg testex} testing examples") - test_files(test_files, context, chdir = FALSE) + test_files(test_file_paths, context, reporter = reporter, chdir = FALSE) } - #' Test a list of files #' #' @param files A collection of file paths to test #' @param context An optional context message to display in `testthat` reporters +#' @param reporter A reporter to use when running each test file #' @param ... Additional arguments passed to `testhat::source_file` #' #' @return The result of [testthat::source_file()], after iterating over #' generated test files. #' #' @keywords internal -test_files <- function(files, context, ...) { +test_files <- function(files, context, reporter, ...) { testthat::context_start_file(context) - for (file in files) testthat::source_file(file, ...) -} + for (file in files) { + if (!is.null(reporter)) { + reporter$start_file(file) + } + + testthat::source_file(file, ...) + if (!is.null(reporter)) { + reporter$end_context_if_started() + reporter$end_file() + } + } +} #' Wraps an example expression in a `testthat` expectation to not error @@ -262,7 +272,6 @@ wrap_expect_no_error <- function(expr, value) { } - #' Determine which symbol to use by default when testing examples #' #' @return The value of the last test expression diff --git a/inst/WORDLIST b/inst/WORDLIST new file mode 100644 index 0000000..c00365a --- /dev/null +++ b/inst/WORDLIST @@ -0,0 +1,2 @@ +roxygen +testthat diff --git a/inst/pkg.example/DESCRIPTION b/inst/pkg.example/DESCRIPTION index e68d928..0db2590 100644 --- a/inst/pkg.example/DESCRIPTION +++ b/inst/pkg.example/DESCRIPTION @@ -13,4 +13,4 @@ Roxygen: list(markdown = TRUE, packages = "testex") RoxygenNote: 7.3.1 License: MIT + file LICENSE Config/testthat/edition: 3 -Config/testex/options: list(check = TRUE, version = "0.2.0.9000") +Config/testex/options: list(check = TRUE, version = "0.2.0.9001") diff --git a/man/test_files.Rd b/man/test_files.Rd index a46091d..33ae195 100644 --- a/man/test_files.Rd +++ b/man/test_files.Rd @@ -4,13 +4,15 @@ \alias{test_files} \title{Test a list of files} \usage{ -test_files(files, context, ...) +test_files(files, context, reporter, ...) } \arguments{ \item{files}{A collection of file paths to test} \item{context}{An optional context message to display in \code{testthat} reporters} +\item{reporter}{A reporter to use when running each test file} + \item{...}{Additional arguments passed to \code{testhat::source_file}} } \value{