Skip to content

Commit

Permalink
Fix crash when @description or @details are NULL
Browse files Browse the repository at this point in the history
Now they are ignored, except for `@description NULL` in
package level documentation, where it can be used to suppress the
auto-generated Description section

Closes #1008.
  • Loading branch information
gaborcsardi committed Mar 6, 2020
1 parent 32fd6ff commit 8ce5015
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* roxygen2 now keeps using Windows (CR LF) line endings for files that
already have CR LF line endings, and uses LF for new files (#989).

* roxygen2 now does not fail for `@description NULL` and `@details NULL`.
Instead, these tags are ignored, except for `@description NULL` in
package level documentation, where it can be used to suppress the
auto-generated Description section (#1008).

# roxygen2 7.0.2

* `\example{}` escaping has been improved (again!) so that special escapes
Expand Down
3 changes: 2 additions & 1 deletion R/rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ topics_add_default_description <- function(topics) {
next

# rexport manually generates a own description, so don't need to
if (!topic$has_section("reexport")) {
if (!topic$has_section("reexport") &&
!identical(topic$get_value("docType"), "package")) {
topic$add(rd_section("description", topic$get_value("title")))
}
}
Expand Down
1 change: 1 addition & 0 deletions R/topic.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ RoxyTopic <- R6::R6Class("RoxyTopic", public = list(
#' @param section [rd_section] object to add.

add_section = function(section, overwrite = FALSE) {
if (is.null(section)) return()
type <- section$type
if (self$has_section(type) && !overwrite) {
section <- merge(self$get_section(type), section)
Expand Down
79 changes: 79 additions & 0 deletions tests/testthat/test-rd.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,85 @@ test_that("documenting NA gives useful error message (#194)", {
)
})

test_that("@description NULL", {
# Just ignore in this case
out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
#' Title
#'
#' @description NULL
#' @format NULL
foobar <- 1:10
")
expect_identical(out[[1]]$get_value("description"), "Title")

# Still ignore
out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
#' Title
#' @description NULL
#' @description desc
#' @format NULL
foobar <- 1:10
")
expect_identical(out[[1]]$get_value("description"), "desc")

# Still ignore for objects as well
out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
#' Title
#' @description NULL
#' @format NULL
foobar <- 1:10
")
expect_identical(out[[1]]$get_value("description"), "Title")

# But drop for package docs
with_mock(
`roxygen2::read.description` = function(...)
list(Package = "roxygen_devtest",
Title = "Package Title",
Description = "Package description."),
out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
#' Title
#'
#' @docType package
#' @description NULL
#' @name pkg
'_PACKAGE'
")
)
expect_null(out[[1]]$get_value("description"))
})

test_that("@details NULL", {
# Just ignore in this case
out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
#' Title
#'
#' @details NULL
#' @format NULL
foobar <- 1:10
")
expect_null(out[[1]]$get_value("details"))

# Still ignore
out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
#' Title
#' @details NULL
#' @details desc
#' @format NULL
foobar <- 1:10
")
expect_identical(out[[1]]$get_value("details"), "desc")

# Still ignore for objects as well
out <- roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
#' Title
#' @details NULL
#' @format NULL
foobar <- 1:10
")
expect_null(out[[1]]$get_value("details"))
})

# UTF-8 -------------------------------------------------------------------

test_that("can generate nonASCII document", {
Expand Down

0 comments on commit 8ce5015

Please sign in to comment.