@@ -8,7 +8,14 @@ stopifnot(file.copy("man", tempdir(), recursive = TRUE))
88old_files <- list.files(old_dir , pattern = " \\ .Rd$" )
99new_dir <- " man"
1010
11- .Last <- function () unlink(old_dir , recursive = TRUE )
11+ .Last <- function () {
12+ if (! dir.exists(old_dir )) {
13+ return (invisible ())
14+ }
15+ unlink(new_dir , recursive = TRUE )
16+ file.copy(old_dir , " ." , recursive = TRUE )
17+ unlink(old_dir , recursive = TRUE )
18+ }
1219
1320# Rd2txt() prints to its out= argument, so we'd have to compare file contents;
1421# plain parse_Rd() keeps srcref info that encodes the file path, which as.character() strips.
@@ -17,37 +24,66 @@ normalize_rd <- function(rd_file) as.character(parse_Rd(rd_file))
1724rd_equal <- function (f1 , f2 ) isTRUE(all.equal(normalize_rd(f1 ), normalize_rd(f2 )))
1825
1926check_roxygenize_idempotent <- function (LOCALE ) {
20- tryCatch(Sys.setlocale(" LC_COLLATE" , LOCALE ), warning = stop )
27+ set_locale_res <- tryCatch(Sys.setlocale(" LC_COLLATE" , LOCALE ), warning = identity , error = identity )
28+ if (inherits(set_locale_res , " condition" )) {
29+ message(sprintf(
30+ " Skipping LOCALE=%s because it is not supported: %s" ,
31+ LOCALE , conditionMessage(set_locale_res )
32+ ))
33+ return (TRUE )
34+ }
35+
36+ # Ensure man/ is in its original state before running roxygenize()
37+ unlink(new_dir , recursive = TRUE )
38+ stopifnot(file.copy(old_dir , " ." , recursive = TRUE ))
39+
2140 suppressMessages(roxygenize()) # 'loading lintr'
2241
2342 new_files <- list.files(new_dir , pattern = " \\ .Rd$" )
2443
2544 old_not_new <- setdiff(old_files , new_files )
2645 if (length(old_not_new ) > 0L ) {
27- stop(" Found saved .Rd files gone from a fresh run of roxygenize(): " , toString(old_not_new ))
46+ cat(sprintf(
47+ " Found saved .Rd files gone from a fresh run of roxygenize() in LOCALE=%s: %s\n " ,
48+ LOCALE , toString(old_not_new )
49+ ))
50+ return (FALSE )
2851 }
2952
3053 new_not_old <- setdiff(new_files , old_files )
3154 if (length(new_not_old ) > 0L ) {
32- stop(" Found new .Rd files from a fresh run of roxygenize(): " , toString(new_not_old ))
55+ cat(sprintf(
56+ " Found new .Rd files from a fresh run of roxygenize() in LOCALE=%s: %s\n " ,
57+ LOCALE , toString(new_not_old )
58+ ))
59+ return (FALSE )
3360 }
3461
62+ ok <- TRUE
3563 for (file in new_files ) {
3664 old_file <- file.path(old_dir , file )
3765 new_file <- file.path(new_dir , file )
3866 if (rd_equal(old_file , new_file )) {
3967 next
4068 }
41- cat(sprintf(" roxygenize() output differs from saved output for %s.\n " , file ))
69+ cat(sprintf(" roxygenize() output differs from saved output for %s in LOCALE=%s .\n " , file , LOCALE ))
4270 cat(" Here's the 'diff' comparison of the two files:\n " )
4371 cat(" [---]: saved output in man/ directory\n " )
4472 cat(" [+++]: roxygenize() output of R/ sources\n " )
4573 system2(" diff" , c(" --unified" , old_file , new_file ))
46- stop( " Failed in LOCALE= " , LOCALE , " . " , call. = FALSE )
74+ ok <- FALSE
4775 }
76+
77+ ok
4878}
4979
5080# Run the check in a few locales to ensure there's no idempotency issues w.r.t. sorting, too
81+ any_failed_locale <- FALSE
5182for (LOCALE in c(" C" , " en_US.utf8" , " hu_HU.utf8" , " ja_JP.utf8" )) {
52- check_roxygenize_idempotent(LOCALE )
83+ any_failed_locale <- any_failed_locale || ! check_roxygenize_idempotent(LOCALE )
84+ }
85+
86+ if (any_failed_locale ) {
87+ message(" roxygenize() check failed." )
88+ q(status = 1 )
5389}
0 commit comments