From 85cf12c8e1f235ef4a67218edb38d6e7cadcd35c Mon Sep 17 00:00:00 2001 From: kellijohnson-NOAA Date: Wed, 17 May 2023 14:06:34 -0700 Subject: [PATCH] fix: tests * test-get_affiliation * test-acronyms The mix of warning and return value was causing a warning in the test rather than a pass status. Also, latex was not installed so the acronyms could not be tested. Codecoverage needs all tests to be passing. --- tests/testthat/setup.R | 12 ++++++++++++ tests/testthat/test-acronyms.R | 5 +++-- tests/testthat/test-get_affiliation.R | 7 ++++++- tests/testthat/test-session.R | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/testthat/setup.R diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 0000000..578c4df --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1,12 @@ +# Setup for the unit tests + +# Check for lualatex +if (!requireNamespace("tinytex", quietly = TRUE)) { + install.packages("tinytex") +} +if (any(tinytex:::which_bin(c("tlmgr", "pdftex", "xetex", "luatex")) == "")) { + tinytex::install_tinytex(bundle = "TinyTex") +} +if (!tinytex::check_installed("glossaries")) { + tinytex::tlmgr_install("glossaries") +} diff --git a/tests/testthat/test-acronyms.R b/tests/testthat/test-acronyms.R index beb740b..58e6c07 100644 --- a/tests/testthat/test-acronyms.R +++ b/tests/testthat/test-acronyms.R @@ -29,8 +29,9 @@ test_that("Acronyms compile with hyperlink", { on.exit(setwd(old_wd)) on.exit(unlink(dir_build, recursive = TRUE), add = TRUE) setwd(dir_build) - end <- system( - paste("lualatex", basename(file_doc)) + end <- system2( + command = "lualatex", + args = paste(basename(file_doc)) ) expect_equal(end, 0) }) diff --git a/tests/testthat/test-get_affiliation.R b/tests/testthat/test-get_affiliation.R index db46f4b..adbddd3 100644 --- a/tests/testthat/test-get_affiliation.R +++ b/tests/testthat/test-get_affiliation.R @@ -1,3 +1,8 @@ test_that("Unknown author returns NA", { - expect_true(is.na(get_affiliation("Kelli Johnson"))) + expect_warning( + is.na(get_affiliation("Kelli Johnson")) + ) + expect_true( + suppressWarnings(is.na(get_affiliation("Kelli Johnson"))) + ) }) diff --git a/tests/testthat/test-session.R b/tests/testthat/test-session.R index ac91aff..f89497c 100644 --- a/tests/testthat/test-session.R +++ b/tests/testthat/test-session.R @@ -1,5 +1,5 @@ test_that("session_test is successful", { - test <- session_test() + test <- suppressWarnings(session_test()) expect_false( inherits(test, "error") )