diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b87b56bc2..c580e0c7a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -10,7 +10,9 @@ on: pull_request: branches: [main, master] -name: R-CMD-check +name: R-CMD-check.yaml + +permissions: read-all jobs: R-CMD-check: @@ -25,24 +27,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'} + # 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'} + - {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 @@ -65,3 +65,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 087f0b05f..4bbce7508 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -9,7 +9,9 @@ on: types: [published] workflow_dispatch: -name: pkgdown +name: pkgdown.yaml + +permissions: read-all jobs: pkgdown: @@ -19,8 +21,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 +43,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/pr-commands.yaml b/.github/workflows/pr-commands.yaml index 71f335b3e..2edd93f27 100644 --- a/.github/workflows/pr-commands.yaml +++ b/.github/workflows/pr-commands.yaml @@ -4,7 +4,9 @@ on: issue_comment: types: [created] -name: Commands +name: pr-commands.yaml + +permissions: read-all jobs: document: @@ -13,8 +15,10 @@ jobs: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/pr-fetch@v2 with: @@ -50,8 +54,10 @@ jobs: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/pr-fetch@v2 with: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb5029..988226098 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -6,7 +6,9 @@ on: pull_request: branches: [main, master] -name: test-coverage +name: test-coverage.yaml + +permissions: read-all jobs: test-coverage: @@ -15,7 +17,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 +25,37 @@ 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") ) + covr::to_cobertura(cov) shell: Rscript {0} + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} + file: ./cobertura.xml + plugin: 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 0d38b02d9..e8e7b9307 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,7 +14,7 @@ Description: Software testing is important, but, in part because it is License: MIT + file LICENSE URL: https://testthat.r-lib.org, https://github.com/r-lib/testthat BugReports: https://github.com/r-lib/testthat/issues -Depends: +Depends: R (>= 3.6.0) Imports: brio (>= 1.1.3), @@ -22,7 +22,7 @@ Imports: cli (>= 3.6.1), desc (>= 1.4.2), digest (>= 0.6.33), - evaluate (>= 0.21), + evaluate (>= 1.0.1), jsonlite (>= 1.8.7), lifecycle (>= 1.0.3), magrittr (>= 2.0.3), @@ -36,7 +36,7 @@ Imports: utils, waldo (>= 0.5.1), withr (>= 2.5.0) -Suggests: +Suggests: covr, curl (>= 0.9.5), diffviewer (>= 0.1.0), @@ -47,7 +47,7 @@ Suggests: usethis, vctrs (>= 0.1.0), xml2 -VignetteBuilder: +VignetteBuilder: knitr Config/Needs/website: tidyverse/tidytemplate Config/testthat/edition: 3 diff --git a/README.Rmd b/README.Rmd index 5ea73b1a0..7e8f1ad3a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,7 +17,7 @@ knitr::opts_chunk$set( [![CRAN status](https://www.r-pkg.org/badges/version/testthat)](https://cran.r-project.org/package=testthat) [![R-CMD-check](https://github.com/r-lib/testthat/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/testthat/actions/workflows/R-CMD-check.yaml) -[![Codecov test coverage](https://codecov.io/gh/r-lib/testthat/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/testthat?branch=main) +[![Codecov test coverage](https://codecov.io/gh/r-lib/testthat/graph/badge.svg)](https://app.codecov.io/gh/r-lib/testthat) ## Overview @@ -31,12 +31,12 @@ Testing your code can be painful and tedious, but it greatly increases the quali on the command line, building test suites, or using R CMD check. * Displays test progress visually, showing a pass, fail, or error for every - expectation. If you're using the terminal or a recent version of RStudio, + expectation. If you're using the terminal or a recent version of RStudio, it'll even colour the output. -testthat draws inspiration from the xUnit family of testing packages, as well as from many of the innovative ruby testing libraries, like [rspec](https://rspec.info/), [testy](https://github.com/ahoward/testy), [bacon](https://github.com/leahneukirchen/bacon) and [cucumber](https://cucumber.io). +testthat draws inspiration from the xUnit family of testing packages, as well as from many of the innovative ruby testing libraries, like [rspec](https://rspec.info/), [testy](https://github.com/ahoward/testy), [bacon](https://github.com/leahneukirchen/bacon) and [cucumber](https://cucumber.io). -testthat is the most popular unit testing package for R and is used by thousands of CRAN packages. +testthat is the most popular unit testing package for R and is used by thousands of CRAN packages. If you're not familiar with testthat, the [testing chapter](https://r-pkgs.org/testing-basics.html) in [R packages](https://r-pkgs.org) gives a good overview, along with workflow advice and concrete examples. diff --git a/README.md b/README.md index 902cfb811..e451fe99e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ status](https://www.r-pkg.org/badges/version/testthat)](https://cran.r-project.org/package=testthat) [![R-CMD-check](https://github.com/r-lib/testthat/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/testthat/actions/workflows/R-CMD-check.yaml) [![Codecov test -coverage](https://codecov.io/gh/r-lib/testthat/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/testthat?branch=main) +coverage](https://codecov.io/gh/r-lib/testthat/graph/badge.svg)](https://app.codecov.io/gh/r-lib/testthat) ## Overview diff --git a/tests/testthat/_snaps/R4.4/snapshot-file/version.txt b/tests/testthat/_snaps/R4.4/snapshot-file/version.txt new file mode 100644 index 000000000..f00f1da0d --- /dev/null +++ b/tests/testthat/_snaps/R4.4/snapshot-file/version.txt @@ -0,0 +1 @@ +R4.4 diff --git a/tests/testthat/_snaps/R4.4/snapshot.md b/tests/testthat/_snaps/R4.4/snapshot.md new file mode 100644 index 000000000..d9fc8be05 --- /dev/null +++ b/tests/testthat/_snaps/R4.4/snapshot.md @@ -0,0 +1,7 @@ +# variants save different values + + Code + r_version() + Output + [1] "R4.4" + diff --git a/tests/testthat/test-parallel-crash.R b/tests/testthat/test-parallel-crash.R index cb3b0d7e7..d6a1f0268 100644 --- a/tests/testthat/test-parallel-crash.R +++ b/tests/testthat/test-parallel-crash.R @@ -1,22 +1,17 @@ test_that("crash", { - # https://github.com/r-lib/rlang/commit/c84d52b6 - skip_if_not_installed("rlang", "1.0.1.9000") - skip_on_cran() skip_on_covr() + skip_if_not(getRversion() >= "4.4.0") + withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") - do <- function() { - err <- NULL + pkg <- test_path("test-parallel", "crash") + err <- callr::r(function() { tryCatch( testthat::test_local(".", reporter = "summary", stop_on_failure = FALSE), - error = function(e) err <<- e + error = function(e) e ) - err - } - - pkg <- test_path("test-parallel", "crash") - err <- callr::r(do, wd = pkg) + }, wd = pkg) expect_s3_class(err, "testthat_process_error") expect_equal(err$test_file, "test-crash-3.R") }) diff --git a/tests/testthat/test-parallel/crash/tests/testthat/test-crash-3.R b/tests/testthat/test-parallel/crash/tests/testthat/test-crash-3.R index 76ee60409..94d7b54a5 100644 --- a/tests/testthat/test-parallel/crash/tests/testthat/test-crash-3.R +++ b/tests/testthat/test-parallel/crash/tests/testthat/test-crash-3.R @@ -1,5 +1,5 @@ test_that("this crashes", { expect_true(TRUE) expect_true(FALSE) - asNamespace("callr")$crash() + rlang::node_car(0) }) diff --git a/tests/testthat/test-verify-conditions-lines.txt b/tests/testthat/test-verify-conditions-lines.txt index 8e10f218e..fa8a1881d 100644 --- a/tests/testthat/test-verify-conditions-lines.txt +++ b/tests/testthat/test-verify-conditions-lines.txt @@ -3,10 +3,10 @@ Message: First. Second. > warning("First.\nSecond.") -Warning in eval(expr, envir, enclos): First. +Warning: First. Second. > stop("First.\nSecond.") -Error in eval(expr, envir, enclos): First. +Error: First. Second. diff --git a/tests/testthat/test-verify-conditions.txt b/tests/testthat/test-verify-conditions.txt index 0d659b6c0..63fdf0eb4 100644 --- a/tests/testthat/test-verify-conditions.txt +++ b/tests/testthat/test-verify-conditions.txt @@ -3,10 +3,10 @@ Message: Message > # With calls > warning("Warning") -Warning in eval(expr, envir, enclos): Warning +Warning: Warning > stop("Error") -Error in eval(expr, envir, enclos): Error +Error: Error > # Without calls > warning("Warning", call. = FALSE)