Skip to content

Instantly share code, notes, and snippets.

@wch
Created February 1, 2012 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wch/1715140 to your computer and use it in GitHub Desktop.
Save wch/1715140 to your computer and use it in GitHub Desktop.
Automatic R testing script for git bisect
#!/usr/bin/Rscript
cat("\n===== Running test script ======\n")
# =========================================
# Functions for marking commit good/bad/skip
# =========================================
markCommitGood <- function() {
cat("Returning code: good (0)\n\n")
quit(status = 0)
}
markCommitBad <- function() {
cat("Returning code: bad (1)\n\n")
quit(status = 1)
}
markCommitSkip <- function() {
cat("Returning code: skip (125)\n\n")
quit(status = 125)
}
markCommitInteractive <- function () {
while (1) {
cat("Mark this commit [g]ood, [b]ad, or [s]kip? ")
response <- scan("stdin", what = character(), n = 1, quiet = TRUE)
if (identical(tolower(response), "g")) {
markCommitGood()
} else if (identical(tolower(response), "b")) {
markCommitBad()
} else if (identical(tolower(response), "s")) {
markCommitSkip()
} else {
cat(sprintf("Unknown response: '%s'\n", response))
}
}
}
# =========================================
# Tests go here
# =========================================
cat("\n Loading libraries...\n")
# If error caught here, skip this commit
tryCatch({
library(devtools)
dev_mode(TRUE)
library(reshape2)
load_all('.')
}, error = function(e) {
print(e)
cat("Error loading libraries\n")
# If error thrown, skip this commit
markCommitSkip()
})
cat("\n Running test...\n")
# Run the actual test code
# If error here, skip this commit
tryCatch({
dat <- data.frame(x=1:3, y=1:3)
# Bad: Throws error when breaks=NA
p <- ggplot(dat, aes(x=x, y=y)) + geom_point() +
scale_x_continuous(breaks=NA)
x11()
print(p)
# If it reaches this point, then it successfully printed. Mark as Good
markCommitGood()
}, error = function(e) {
print(e)
cat("Error running test\n")
# If error thrown, mark this commit bad
markCommitBad()
})
# =========================================
# If automatic report didn't happen, get interactive response
# =========================================
markCommitInteractive()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment