Skip to content

Commit

Permalink
new meta-level test that roxygen2 has been run
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Dec 17, 2023
1 parent 847d789 commit 85ed38a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
39 changes: 39 additions & 0 deletions .dev/roxygen_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Test to ensure roxygenize() has been run on the current PR
library(tools)
library(roxygen2)

old_dir <- file.path(tempdir(), "man")
if (dir.exists(old_dir)) unlink(old_dir, recursive = TRUE)
file.copy("man", tempdir(), recursive = TRUE)
new_dir <- "man"
.Last <- function() unlink(old_dir, recursive = TRUE)

roxygenize()

old_files <- list.files(old_dir, pattern = "\\.Rd$")
new_files <- list.files(new_dir, pattern = "\\.Rd$")

old_not_new <- setdiff(old_files, new_files)
if (length(old_not_new) > 0L) {
stop("Found saved .Rd files gone from a fresh run of roxygenize(): ", toString(old_not_new))
}

new_not_old <- setdiff(new_files, old_files)
if (length(new_not_old) > 0L) {
stop("Found new .Rd files from a fresh run of roxygenize(): ", toString(new_not_old))
}

# Rd2txt() prints to its out= argument, so we'd have to compare file contents;
# plain parse_Rd() keeps srcref info that encodes the file path, which as.character() strips.
comparable_rd <- function(rd_file) as.character(parse_Rd(rd_file))

rd_equal <- function(f1, f2) isTRUE(all.equal(comparable_rd(f1), comparable_rd(f2)))

for (file in new_files) {
if (rd_equal(file.path(old_dir, file), file.path(new_dir, file))) {
next
}
stop("roxygenize() output differs from saved output for ", file, ".")
}

unlink(old_dir, recursive = TRUE)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Ensure lint metadata is tested
# Various repo-level tests for code quality
on:
push:
branches: [main]
pull_request:
branches: [main]

name: ensure-metadata-tests
name: repo-meta-tests

jobs:
ensure-metadata-tests:
repo-meta-tests:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -28,3 +28,8 @@ jobs:
options(crayon.enabled = TRUE)
callr::rscript(".dev/lint_metadata_test.R")
shell: Rscript {0}

- name: Ensure roxygen content matches man directory
run: |
callr::rscript(".dev/roxygen_test.R")
shell: Rscript {0}
1 change: 1 addition & 0 deletions R/any_is_na_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' Therefore, it should be used in all situations instead of the latter.
#'
#' @examples
#' # new comment
#' # will produce lints
#' lint(
#' text = "any(is.na(x), na.rm = TRUE)",
Expand Down

0 comments on commit 85ed38a

Please sign in to comment.