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

New meta-level test that roxygen2 has been run #2460

Merged
merged 15 commits into from
Dec 23, 2023
Merged

New meta-level test that roxygen2 has been run #2460

merged 15 commits into from
Dec 23, 2023

Conversation

MichaelChirico
Copy link
Collaborator

We've been bitten a number of times by some small change to the doc mark-up sneaking through to main without be roxygenize()'d, winding up included in some unrelated PR.

This simple workflow should prevent that issue from recurring.

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c4b8e34) 98.54% compared to head (4b8c9f7) 98.54%.

❗ Current head 4b8c9f7 differs from pull request most recent head 5cd9c07. Consider uploading reports for the commit 5cd9c07 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2460   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         126      126           
  Lines        5721     5721           
=======================================
  Hits         5638     5638           
  Misses         83       83           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MichaelChirico
Copy link
Collaborator Author

Confirmed WAI:

image

@AshesITR
Copy link
Collaborator

Hmm this might be a problem for OS dependent Rd.
E.g. I can't generate the current man page for default_undesirable_functions without changing sort order.

@MichaelChirico
Copy link
Collaborator Author

even after #2455?

@AshesITR
Copy link
Collaborator

Should be fixed by that but a similar problem could occur in the future.
So if we put it in place, it should run at least on linux + windows + linux with non-standard locale to catch any potentially problematic markup ahead of time.

@MichaelChirico
Copy link
Collaborator Author

Should be fixed by that but a similar problem could occur in the future. So if we put it in place, it should run at least on linux + windows + linux with non-standard locale to catch any potentially problematic markup ahead of time.

IMO that will catch some rare (but annoying!) issues, but the current script will catch most issues. Not sure it's worth extra compute resources for the rest.

@AshesITR
Copy link
Collaborator

How much resources does it cost to run?
Maybe run it twice in the same process with different locales as a compromise?

I'm willing to give it a try (it won't be blocking anyway, so might just be a minor annoyance if encountered).

Perhaps output a git diff of old vs. new for changed files to ease debugging?

@MichaelChirico
Copy link
Collaborator Author

How much resources does it cost to run? Maybe run it twice in the same process with different locales as a compromise?

different locales is a good idea, that'll have low overhead. setting up different containers/OS was my issue.

Perhaps output a git diff of old vs. new for changed files to ease debugging?

I pondered this but figured it'd be pretty clear why it fails (oops, I forgot to document). let me add a one liner anyway.

@AshesITR
Copy link
Collaborator

Perhaps output a git diff of old vs. new for changed files to ease debugging?

I pondered this but figured it'd be pretty clear why it fails (oops, I forgot to document). let me add a one liner anyway.

Usually, yes. But if and when devtools::document() won't fix the run, it will be very frustrating to debug.

}
cat(sprintf("roxygenize() output differs from saved output for %s.\n", file))
cat("Here's the Rd2txt() output for what's saved:\n")
Rd2txt(old_file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this show macros etc.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the help, the default is the "render" stage which expands macros:

https://rdrr.io/r/tools/Rd2HTML.html

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the raw contents of the Rd file are more helpful since those are the files that are checked in.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tools::Rdiff() will compare the raw contents and show the diff, here's the output when I changed <- to = in assignment_linter.Rd:

34c34
< code_lines <- "1 -> x\n2 ->> y"
---
> code_lines = "1 -> x\n2 ->> y"

.dev/roxygen_test.R Outdated Show resolved Hide resolved
cat("Here's the Rd2txt() output for roxygenize():\n")
Rd2txt(new_file)
cat("Here's the tools::Rdiff() comparison of the two files:\n")
tools::Rdiff(old_file, new_file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmp1 <- withr::local_tempfile(lines = c("a", "b"))
tmp2 <- withr::local_tempfile(lines = c("a", "b", "c"))
tools::Rdiff(tmp1, tmp2)
#> files differ in number of lines

Created on 2023-12-19 with reprex v2.0.2

That's not very helpful, either...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's annoying, thanks for checking. Maybe we should use testthat::expect_identical() to handle giving a summarized diff instead?

Copy link
Collaborator

@AshesITR AshesITR Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

tmp1 <- withr::local_tempfile(lines = c("a", "b"))
tmp2 <- withr::local_tempfile(lines = c("a", "b", "c"))
cat(capture.output(system2("diff", c("--unified", normalizePath(tmp1), normalizePath(tmp2)))), sep = "\n")

Created on 2023-12-19 with reprex v2.0.2

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmp1 <- withr::local_tempfile(lines = c("a", "b"))
tmp2 <- withr::local_tempfile(lines = c("a", "b", "c"))
tools::Rdiff(tmp1, tmp2)
#> files differ in number of lines

Created on 2023-12-19 with reprex v2.0.2

That's not very helpful, either...

Hmm, this truncated the output:

files differ in number of lines:
2a3
> c

Note that tools::Rdiff() is calling diff under the hood, just with different options (-bw vs. your --unified):

https://github.com/r-devel/r-svn/blob/c786526c27271c4bb04b621d2bde5cdd93033bc0/src/library/tools/R/testing.R#L290-L293

Vs. testthat:

testthat::expect_identical(readLines(tmp1), readLines(tmp2))
> Error: readLines(tmp1) (`actual`) not identical to readLines(tmp2) (`expected`).

`actual`:   "a" "b"    
`expected`: "a" "b" "c"

(with color if we enable it)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, weird. I don't get the output from Rdiff in either my IDE or reprex.
I prefer --unified because that's basically git diff, which we're very used to reading.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try it by forcing a failure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed plain Rdiff() output is junk:

image

Trying with Log=TRUE now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, --unified looks like the way to go. One last small bit is to try and make this part comprehensible:

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't worry too much about that, unless there is a very simple option for diff to fake this path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more importantly we need to make clear which output comes from which source. handled already at current commit.

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB cli is available if we want prettier messages.

.dev/roxygen_test.R Outdated Show resolved Hide resolved
.dev/roxygen_test.R Show resolved Hide resolved
@AshesITR AshesITR merged commit acbfd77 into main Dec 23, 2023
20 checks passed
@MichaelChirico MichaelChirico deleted the roxy-action branch December 27, 2023 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants