Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with repo roxy tests #925

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
^CITATION\.cff$
^CODE_OF_CONDUCT\.md$
^CONDUCT\.md$
^COPYING$
^CRAN-RELEASE$
^CRAN-SUBMISSION$
^LICENSE\.md$
Expand Down
54 changes: 54 additions & 0 deletions .dev/roxygen_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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)
old_files <- list.files(old_dir, pattern = "\\.Rd$")
new_dir <- "man"
.Last <- function() unlink(old_dir, recursive = TRUE)

# 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.
normalize_rd <- function(rd_file) as.character(parse_Rd(rd_file))

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

check_roxygenize_idempotent <- function(LOCALE) {
Sys.setlocale("LC_COLLATE", LOCALE)
roxygenize()

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))
}

for (file in new_files) {
old_file <- file.path(old_dir, file)
new_file <- file.path(new_dir, file)
if (rd_equal(old_file, new_file)) {
next
}
cat(sprintf("roxygenize() output differs from saved output for %s.\n", file))
cat("Here's the 'diff' comparison of the two files:\n")
cat(" [---]: saved output in man/ directory\n")
cat(" [+++]: roxygenize() output of R/ sources\n")
system2("diff", c("--unified", old_file, new_file))
stop("Failed in LOCALE=", LOCALE, ".", call. = FALSE)
}
}

# Run the check in a few locales to ensure there's no idempotency issues w.r.t. sorting, too
for (LOCALE in c("C", "en_US", "hu_HU", "ja_JP")) {
check_roxygenize_idempotent(LOCALE)
}

unlink(old_dir, recursive = TRUE)
32 changes: 32 additions & 0 deletions .github/workflows/repo-roxy-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: repo-roxy-tests

jobs:
repo-roxy-tests:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::roxygen2
needs: development

- name: Ensure roxygen content matches manual directory
run: |
callr::rscript(".dev/roxygen_test.R")
shell: Rscript {0}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Network Trash Folder
Temporary Items

# R Studio files
*.pdf
.RData
.Rhistory
.Rproj.user
Expand Down
20 changes: 20 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2018-2024, Indrajeet Patil

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ RoxygenNote: 7.3.1
Config/testthat/edition: 3
Config/testthat/parallel: true
Config/Needs/check: anthonynorth/roxyglobals
Config/Needs/development: roxyglobals, r-lib/pkgapi
Config/roxyglobals/unique: TRUE
Binary file removed Rplots.pdf
Binary file not shown.
Loading