Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kellijohnson-NOAA committed May 17, 2023
1 parent 117a78f commit dde22a3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 36 deletions.
12 changes: 12 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -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")
}
70 changes: 36 additions & 34 deletions tests/testthat/test-acronyms.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
test_that("Acronyms compile with hyperlink", {
file_glossaries <- system.file(
"rmarkdown", "templates", "sa", "skeleton", "sa4ss_glossaries.tex",
package = "sa4ss"
)
dir_build <- file.path(tempdir(), "sa4ss")
file_doc <- file.path(dir_build, "sa4ss_doc.tex")
dir.create(dir_build, showWarnings = FALSE)
file.copy(
file_glossaries,
file.path(dir_build, basename(file_glossaries)),
overwrite = TRUE
)
writeLines(
text = c(
"\\documentclass{report}",
"\\usepackage{glossaries}",
"\\usepackage[colorlinks]{hyperref}",
"\\makeglossaries",
"\\loadglsentries{sa4ss_glossaries.tex}",
"\\begin{document}",
"Some test text \\glsentrytext{mlml}.",
"\\printglossaries",
"\\end{document}"
),
con = file_doc
)
old_wd <- getwd()
on.exit(setwd(old_wd))
on.exit(unlink(dir_build, recursive = TRUE), add = TRUE)
setwd(dir_build)
end <- system(
paste("lualatex", basename(file_doc))
)
expect_equal(end, 0)
skip_on_os("linux", arch = NULL)
file_glossaries <- system.file(
"rmarkdown", "templates", "sa", "skeleton", "sa4ss_glossaries.tex",
package = "sa4ss"
)
dir_build <- file.path(tempdir(), "sa4ss")
file_doc <- file.path(dir_build, "sa4ss_doc.tex")
dir.create(dir_build, showWarnings = FALSE)
file.copy(
file_glossaries,
file.path(dir_build, basename(file_glossaries)),
overwrite = TRUE
)
writeLines(
text = c(
"\\documentclass{report}",
"\\usepackage{glossaries}",
"\\usepackage[colorlinks]{hyperref}",
"\\makeglossaries",
"\\loadglsentries{sa4ss_glossaries.tex}",
"\\begin{document}",
"Some test text \\glsentrytext{mlml}.",
"\\printglossaries",
"\\end{document}"
),
con = file_doc
)
old_wd <- getwd()
on.exit(setwd(old_wd))
on.exit(unlink(dir_build, recursive = TRUE), add = TRUE)
setwd(dir_build)
end <- system2(
command = "lualatex",
args = paste(basename(file_doc))
)
expect_equal(end, 0)
})
7 changes: 6 additions & 1 deletion tests/testthat/test-get_affiliation.R
Original file line number Diff line number Diff line change
@@ -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")))
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-session.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("session_test is successful", {
test <- session_test()
test <- suppressWarnings(session_test())
expect_false(
inherits(test, "error")
)
Expand Down

0 comments on commit dde22a3

Please sign in to comment.