Last active
January 6, 2017 18:44
-
-
Save cannin/3a31bd3b91a7e610a733 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
# PARAMETERS | |
#cfg <- '{"url":"https://devbotcc:[email protected]/mil2041/netboxr.git", "quick":true, "dependencies":true}' | |
#pkg <- "netboxr" | |
#url <- Sys.getenv("URL") | |
pkg <- Sys.getenv("PKG") | |
cfg <- Sys.getenv("CFG") | |
# FUNCTIONS | |
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) | |
} | |
# SETUP | |
setRepositories(ind=1:6) | |
options(repos="http://cran.rstudio.com/") | |
if(!require(devtools)) install.packages("devtools") | |
if(!require(testthat)) install.packages("testthat") | |
if(!require(roxygen2)) install.packages("roxygen2") | |
if(!require(jsonlite)) install.packages("jsonlite") | |
# 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) | |
# START | |
library(devtools) | |
library(testthat) | |
library(jsonlite) | |
# Make sure files can be downloaded | |
cfg <- jsonlite::fromJSON(cfg) | |
do.call(install_git, cfg) | |
# Test package | |
tmpFile <- "/tmpResults.txt" | |
sink(tmpFile) | |
test_package(pkg, reporter="tap") | |
sink() | |
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