Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
infotroph committed Oct 3, 2024
1 parent 26515c9 commit 769e9e3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/all/R/pecan_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ print.pecan_version_report <- function(x, ...) {
}
dots$x <- xx
do.call("print", dots)

invisible(x)
}
34 changes: 34 additions & 0 deletions base/all/tests/testthat/test-pecan_version.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,37 @@ test_that("pecan_version without sessioninfo", {
# The approach that failed just before I wrote this note:
# No, the version of PEcAn.all (1.8.1.9000 today) is not reliably in sync with
# the PEcAn version last tagged as a release (1.7.2 today).


test_that("printing", {
ver <- structure(
data.frame(
package = "PEcAnFake",
v0.0 = package_version("1.2.3"),
installed = package_version("1.2.3.9000"),
build_hash = "01234567ab",
source = "13 characters"),
class = c("pecan_version_report", "data.frame")
)

long_ver <- ver
long_ver$build_hash = "01234567ab+mod"
long_ver$source = "twenty-two characters"

# hash truncated to fit "+mod" if present
expect_output(print(ver), "01234567ab", fixed = TRUE)
expect_output(print(long_ver), "012345+mod", fixed = TRUE)

# source truncated to total of 20 chars
expect_output(print(ver), "13 characters$")
expect_output(print(long_ver), "twenty-two charac...", fixed = TRUE)

# source truncation works on width not glyph count
long_ver$source <- gsub("tw", "\U{1F197}\U{1F192}", long_ver$source)
expect_output(print(long_ver), "\U{1F192}o ch...", fixed = TRUE)

# dots passed on
expect_output(print(ver), "\n PEcAnFake")
expect_output(print(ver, row.names = TRUE), "\n1 PEcAnFake", fixed = TRUE)
expect_output(print(ver, quote = TRUE), "\n \"PEcAnFake\"", fixed = TRUE)
})

0 comments on commit 769e9e3

Please sign in to comment.