Skip to content

Commit

Permalink
[188815240]: bring back junit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gergness committed Jan 27, 2025
1 parent de5f95e commit 8376341
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test-ci: compress-fixtures |
R --slave -e 'library(covr); install_dir <- tempfile(); test_run <- try(to_cobertura(package_coverage(quiet=FALSE, install_path=install_dir, clean=FALSE))); for (file in list.files(install_dir, pattern = "\\.Rout(\\.fail)?$$", recursive=TRUE, full.names=TRUE)) { cat(readLines(file), sep = "\n"); cat("\n") }; if (inherits(test_run, "try-error")) stop("Test failed!\n", attr(test_run, "condition")[["message"]], "\n", format(attr(test_run, "condition")[["call"]]))'

test-ci-partial: compress-fixtures |
cd tests/ && R --slave -e 'library(devtools); library(testthat); test(filter="${file_regex}", reporter = MultiReporter$$new(list(SummaryReporter$$new(), JunitReporter$$new(file = file.path(Sys.getenv("WORKSPACE"), "rcrunch.xml"))))); cat("\n---\nPRINTING JUNIT FILE at ", file.path(Sys.getenv("WORKSPACE"), "rcrunch.xml"), "\n---\n", paste0(readLines(file.path(Sys.getenv("WORKSPACE"), "rcrunch.xml"))), "\n---\n")'
cd tests/ && R --slave -e 'library(devtools); source("../inst/junit_fix.R"); library(testthat); test(filter="${file_regex}", reporter = MultiReporter$$new(list(SummaryReporter$$new(), JunitReporterFix$$new(file = file.path(Sys.getenv("WORKSPACE"), "rcrunch.xml")))));'

clean:
R --slave -e 'library(crunch); set_crunch_opts(crunch.api=envOrOption("test.api"), crunch.api.key=envOrOption("crunch.test.api.key")); lapply(urls(datasets()), crDELETE)'
Expand Down
24 changes: 24 additions & 0 deletions inst/junit_fix.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
tt_read_lines <- function(path, n = -1L, encoding = "UTF-8") {
base::readLines(path, n = n, encoding = encoding, warn = FALSE)
}

tt_write_lines <- function(text, path) {
base::writeLines(enc2utf8(text), path, useBytes = TRUE)
}

# trick to get around :: from depends CRAN check
R6Class <- get("R6Class", asNamespace("R6"))

JunitReporterFix <- R6Class(
"JunitReporterFix",
inherit = JunitReporter,
public = list(
end_reporter = function() {
super$end_reporter()
tt_write_lines(
crayon::strip_style(tt_read_lines(self$out)),
self$out
)
}
)
)

0 comments on commit 8376341

Please sign in to comment.