Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\.github
^\.github$
codecov\.yml
LICENSE\.md
pkgdown
Expand Down
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
28 changes: 14 additions & 14 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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")'
11 changes: 7 additions & 4 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand Down
28 changes: 20 additions & 8 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -15,36 +16,47 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- 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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 30 additions & 21 deletions R/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
NULL



#' Raise `testthat` Expectations With A Known Source Reference
#'
#' Retroactively assigns a source file and location to a expectation. This
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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]]

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
roxygen
testthat
2 changes: 1 addition & 1 deletion inst/pkg.example/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 3 additions & 1 deletion man/test_files.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.