Last active
September 18, 2016 19:32
-
-
Save cannin/b77c366d2a94592cd67e to your computer and use it in GitHub Desktop.
Generate testthat TAP results compatible with the Jenkins continuous integration TAP plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setRepositories(ind=1:6) | |
options(repos="http://cran.rstudio.com/") | |
if(!require(devtools)) install.packages("devtools") | |
if(!require(testthat)) install.packages("testthat") | |
if(Sys.getenv("TEST_DIR") != "") { | |
testDir <- Sys.getenv("TEST_DIR") | |
} else { | |
testDir <- "inst/tests" | |
} | |
# DEBUG | |
#install.packages("RCurl", repos="http://cran.rstudio.com/") | |
as.vector(installed.packages()[,"Package"]) | |
.libPaths() | |
#pkg <- as.package(".") | |
#deps <- parse_deps(pkg$depends) | |
#lapply(deps$name, require, character.only = TRUE) | |
#library(RCurl) | |
library(devtools) | |
install_deps(".", dependencies=TRUE) | |
library(testthat) | |
#Source all scripts in R | |
load_all() | |
tmpFile <- tempfile() | |
sink(tmpFile) | |
test_dir(testDir, reporter="tap") | |
sink() | |
processTap <- function(inputFile) { | |
con <- file(inputFile) | |
open(con) | |
lines <- NULL | |
startTap <- FALSE | |
while (length(line <- readLines(con, n = 1, warn = FALSE)) > 0) { | |
if(grepl("1\\.\\.", line)) { | |
startTap <- TRUE | |
line <- gsub(".+(1\\.\\.\\d+)$", "\\1", line) | |
cat("LINE: ", line, "\n") | |
} | |
if(startTap) { | |
lines <- c(lines, line) | |
} | |
} | |
close(con) | |
con <- file(inputFile) | |
writeLines(paste(lines, collapse="\n"), con) | |
close(con) | |
return(lines) | |
} | |
processTap(tmpFile) | |
con <- file(tmpFile, "r") | |
outFile <- file("outputFile", "w") | |
tmp <- "" | |
startTap <- FALSE | |
while(length(line <- readLines(con, n=1)) > 0) { | |
# Check for the start of the TAP file | |
if(grepl("^\\d\\.\\.\\d", line)) { | |
startTap <- TRUE | |
} | |
if(startTap) { | |
# Remove any existing colon that corrupts YAML format | |
line <- gsub(":", "..", line) | |
# Remove any quotes | |
line <- gsub("\"", "'", line) | |
# Output line | |
tmp <- paste0(tmp, line, "\n") | |
#writeLines(line, con=outFile) | |
#cat(line) | |
} | |
} | |
cat(tmp, file="jenkins_results.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment