Created
February 1, 2012 06:22
-
-
Save wch/1715469 to your computer and use it in GitHub Desktop.
Test for stat_sum
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
#!/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) | |
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({ | |
set.seed(101) | |
d <- data.frame(x=sample(1:5,size=500,replace=TRUE), | |
y=sample(1:5,size=500,replace=TRUE), | |
g=sample(c("a","b"),size=500,replace=TRUE)) | |
p <- ggplot(d,aes(x,y,colour=g))+ | |
stat_sum()+facet_wrap(~g) | |
x11() | |
print(p) | |
}, error = function(e) { | |
print(e) | |
cat("Error running test\n") | |
# If error thrown, mark this commit skip | |
markCommitSkip() | |
}) | |
# ========================================= | |
# 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