Skip to content

Commit

Permalink
Merge pull request #720 from rundel/issue#689
Browse files Browse the repository at this point in the history
Handle malformed version information from INSIDE_EMACS
  • Loading branch information
gaborcsardi authored Aug 28, 2024
2 parents 175c746 + b635a92 commit 69150b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# cli (development version)

* `num_ansi_colors()` now does not warn in Emacs if the `INSIDE_EMACS`
environment variable is not a proper version number (@rundel, #689).

* `ansi_collapse()` and inline collapsing now uses `last` as the separator
(without the serial comma) for two-element vectors if `sep2` is not
given (@rundel, #681).
Expand Down
3 changes: 2 additions & 1 deletion R/num-ansi-colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,10 @@ emacs_version <- function() {
if (ver == "") return(NA_integer_)

ver <- gsub("'", "", ver)

ver <- strsplit(ver, ",", fixed = TRUE)[[1]]
ver <- strsplit(ver, ".", fixed = TRUE)[[1]]
as.numeric(ver)
suppressWarnings(as.numeric(ver))
}

win10_build <- function() {
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-num-ansi-colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,19 @@ test_that("ESS_BACKGROUND_MODE", {
withr::local_envvar(ESS_BACKGROUND_MODE = "dark")
expect_true(detect_dark_theme("auto"))
})

test_that("emacs_version", {
withr::local_envvar(INSIDE_EMACS = "")
expect_true(is.na(emacs_version()))
withr::local_envvar(INSIDE_EMACS = "foobar")
expect_true(is.na(emacs_version()))

withr::local_envvar(INSIDE_EMACS = "23.2.3")
expect_equal(emacs_version(), c(23, 2, 3))
withr::local_envvar(INSIDE_EMACS = "23.2.3,foobar")
expect_equal(emacs_version(), c(23, 2, 3))
withr::local_envvar(INSIDE_EMACS = "'23.2.3'")
expect_equal(emacs_version(), c(23, 2, 3))
withr::local_envvar(INSIDE_EMACS = "'23.2.3',foobar")
expect_equal(emacs_version(), c(23, 2, 3))
})

0 comments on commit 69150b1

Please sign in to comment.