From 5deda2be73b6e0361b6908b71921b205fdf9d57c Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 23 Aug 2024 15:28:57 -0500 Subject: [PATCH 1/6] Re-run tests on R 4.4 --- tests/testthat/_snaps/R4.4/snapshot-file/version.txt | 1 + tests/testthat/_snaps/R4.4/snapshot.md | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 tests/testthat/_snaps/R4.4/snapshot-file/version.txt create mode 100644 tests/testthat/_snaps/R4.4/snapshot.md 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" + From 33aaa9cd62d724cbecc0214385d4447832873d75 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 23 Aug 2024 15:30:24 -0500 Subject: [PATCH 2/6] `use_tidy_github_actions()` --- .github/workflows/R-CMD-check.yaml | 30 ++++++++++++---------------- .github/workflows/pkgdown.yaml | 10 +++++++--- .github/workflows/pr-commands.yaml | 12 ++++++++--- .github/workflows/test-coverage.yaml | 25 ++++++++++++++++------- README.Rmd | 8 ++++---- README.md | 2 +- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b87b56bc2..064677b49 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,32 +27,25 @@ 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 - # For file snapshot that uses png - - name: Install xquartz - if: runner.os == 'macOS' - run: brew install --cask xquartz - - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} @@ -65,3 +60,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/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 From 8b53f7af4f9ac16335a4815dcfa559efebbc3e89 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 23 Aug 2024 15:47:12 -0500 Subject: [PATCH 3/6] Install XQuartz for `png()` --- .github/workflows/R-CMD-check.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 064677b49..c580e0c7a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -46,6 +46,11 @@ jobs: - uses: r-lib/actions/setup-pandoc@v2 + # For file snapshot that uses png + - name: Install xquartz + if: runner.os == 'macOS' + run: brew install --cask xquartz + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} From 0c34b4e0ca5328f457ff6bd92ce7ad8a7845cbb3 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 23 Aug 2024 16:41:21 -0500 Subject: [PATCH 4/6] Freshen up crashing test --- tests/testthat/test-parallel-crash.R | 15 ++++----------- .../crash/tests/testthat/test-crash-3.R | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-parallel-crash.R b/tests/testthat/test-parallel-crash.R index cb3b0d7e7..967467387 100644 --- a/tests/testthat/test-parallel-crash.R +++ b/tests/testthat/test-parallel-crash.R @@ -1,22 +1,15 @@ 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() 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) }) From 02542084fba559e2c11fcea7e1f4ba88caee98e8 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 22 Oct 2024 17:10:37 -0500 Subject: [PATCH 5/6] Only seems to work on recent versions --- tests/testthat/test-parallel-crash.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-parallel-crash.R b/tests/testthat/test-parallel-crash.R index 967467387..d6a1f0268 100644 --- a/tests/testthat/test-parallel-crash.R +++ b/tests/testthat/test-parallel-crash.R @@ -1,6 +1,8 @@ test_that("crash", { skip_on_cran() skip_on_covr() + skip_if_not(getRversion() >= "4.4.0") + withr::local_envvar(TESTTHAT_PARALLEL = "TRUE") pkg <- test_path("test-parallel", "crash") From bb976b79511e2a9021650e64b423a1fb9f0d730a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 22 Oct 2024 17:22:04 -0500 Subject: [PATCH 6/6] Update snapshots/bump evaluate --- DESCRIPTION | 8 ++++---- tests/testthat/test-verify-conditions-lines.txt | 4 ++-- tests/testthat/test-verify-conditions.txt | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) 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/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)