Skip to content

Commit

Permalink
Merge pull request #104 from nash-delcamp-slp/session-info-accept-mul…
Browse files Browse the repository at this point in the history
…tiple-info

Fix bug where `session_info()` fails when `info` argument has length > 1
  • Loading branch information
gaborcsardi authored Aug 28, 2024
2 parents f42531b + 852901a commit 442a686
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# sessioninfo (development version)

* `session_info()` no longer produces an error when `info` has length > 1 (@nash-delcamp-slp, #96).

* Update pkgdown url to sessioninfo.r-lib.org

* `session_diff()` now accepts the URL to a GitHub Actions log as the source for
Expand Down
5 changes: 2 additions & 3 deletions R/session-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ session_info <- function(

if (missing(info)) info <- "auto"
choices <- c("platform", "packages", "python", "external")
if (info != "auto" && info != "all") {
info <- match.arg(info, choices, several.ok = TRUE)
}
if ("all" %in% info) {
info <- choices
} else if ("auto" %in% info) {
Expand All @@ -69,6 +66,8 @@ session_info <- function(
"packages",
if (should_show_python(pkgs)) "python"
)
} else {
info <- match.arg(info, choices, several.ok = TRUE)
}

stopifnot(is_flag(to_file) || is_string(to_file))
Expand Down
36 changes: 36 additions & 0 deletions tests/testthat/test-session-info.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,39 @@ test_that("print.session_info", {
expect_output(print(si), "setting[ ]+value")
expect_output(print(si), "package[ ]+\\* version[ ]+date[ ][(]UTC[)][ ]+lib[ ]+source")
})

test_that("`info` can include one or multiple values", {
choices <- c("platform", "packages", "python", "external")

# including "all" results in all info being selected
expect_named(
session_info(info = "all"),
choices,
ignore.order = TRUE
)
# even when other items are included
expect_named(
session_info(info = c("all", "platform")),
choices,
ignore.order = TRUE
)

# including "auto" (and not "all") results in auto info being included
expect_gte(
length(names(session_info(info = "auto"))),
2
)
# even when other items are included
expect_gte(
length(names(session_info(info = c("auto", "platform")))),
2
)

# with neither "all" or "auto", valid items are included
expect_named(
session_info(info = c("platform", "python", "external", "nonvalid-info")),
c("platform", "python", "external"),
ignore.order = TRUE
)

})

0 comments on commit 442a686

Please # to comment.