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

preserve the order the option were defined in the generated doc #7

Merged
merged 2 commits into from
Nov 28, 2023
Merged
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
2 changes: 1 addition & 1 deletion R/options_roxygen.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ as_roxygen_docs <- function(
"@seealso options getOption Sys.setenv Sys.getenv",
"@section Options:",
"\\describe{",
vapply(setdiff(names(optenv), CONST_OPTIONS_META), function(n) {
vapply(setdiff(names(details), CONST_OPTIONS_META), function(n) {
sprintf(
"\\item{%s}{\\describe{%s}}\n", n,
paste0(
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-output.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,22 @@ test_that("options objects pretty print", {
expect_match(out, " default")
Sys.unsetenv("OPT_A")
})

test_that("options objects prints options in definition order", {
e <- new.env(parent = baseenv())

expect_silent(with(e, options::define_option(
"B",
default = 2,
envvar_name = "OPT_B"
)))

expect_silent(with(e, options::define_option(
"A",
default = 1,
envvar_name = "OPT_A"
)))

expect_silent(out <- paste0(capture.output(e$.options), collapse = "\n"))
expect_match(out, "OPT_B.*OPT_A")
})
9 changes: 9 additions & 0 deletions tests/testthat/test-roxygen2.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ test_that("roxygen2-style block is generated from options env object", {
expect_match(block, "\\{envvar: \\}\\{OPT_A")
})

test_that("roxygen2 options documentation is in definition order", {
e <- test_env()
expect_silent(with(e, options::define_option("B")))
expect_silent(with(e, options::define_option("A")))

expect_silent(block <- paste0(as_roxygen_docs(env = e), collapse = "\n"))
expect_match(block, "\\\\item\\{B\\}.*\\\\item\\{A\\}")
})

test_that("roxygen2-style params block is generated from as_params", {
e <- test_env()

Expand Down
Loading