Created
February 8, 2012 00:42
-
-
Save wch/1763592 to your computer and use it in GitHub Desktop.
bisect test scale_x_continuous
This file contains hidden or 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 | |
# To run this script: | |
# git bisect reset | |
# git bisect start fd6b67 remotes/origin/ggplot-0.8.9 | |
# git bisect run test_scale_x_crash.r | |
# When finished: | |
# git bisect reset | |
# ==================================================== | |
# bisect utility functions here | |
# ==================================================== | |
bisect_runtest <- function(fun, on_error = NA, msg = "Running test...") { | |
# Check that fun is a function -- easy to accidentally pass myfun() | |
# instead of myfun. | |
if (!is.function(fun)) { | |
stop("'fun' is not a function. Make sure to pass 'myfunction' and not 'myfunction()'") | |
} | |
message(msg) | |
if (is.na(on_error)) { | |
error_fun <- function(e) { | |
print(e) | |
message("Error encountered in test.") | |
return(NA) | |
} | |
} else if (on_error == TRUE) { | |
error_fun <- function(e) { | |
print(e) | |
message("Error encountered in test.") | |
return(TRUE) | |
} | |
} else if (on_error == FALSE) { | |
error_fun <- function(e) { | |
print(e) | |
message("Error encountered in test.") | |
return(FALSE) | |
} | |
} | |
status <- tryCatch(fun(), error = error_fun) | |
if (is.null(status)) { | |
# Return NULL, but don't print | |
invisible(NULL) | |
} else if (is.na(status)) { | |
mark_commit_skip() | |
} else if (status == TRUE) { | |
mark_commit_good() | |
} else if (status == FALSE) { | |
mark_commit_bad() | |
} | |
} | |
bisect_load_all <- function(pkgdir = ".", on_error = NA) { | |
bisect_runtest(function() { | |
load_all(pkgdir) | |
}, | |
on_error = on_error, | |
msg = paste("Loading package in directory", pkgdir)) | |
} | |
bisect_return_interactive <- function () { | |
while (1) { | |
message("Mark this commit [g]ood, [b]ad, or [s]kip? ", appendLF = FALSE) | |
# Need to use "stdin" to get user input in a script -- stdin() doesn't work | |
response <- scan("stdin", what = character(), n = 1, quiet = TRUE) | |
if (identical(tolower(response), "g")) { | |
return(TRUE) | |
} else if (identical(tolower(response), "b")) { | |
return(FALSE) | |
} else if (identical(tolower(response), "s")) { | |
return(NA) | |
} else { | |
message(paste("Unknown response:", response)) | |
} | |
} | |
} | |
bisect_load_and_test <- function(fun, pkgdir = ".", on_load_error = NA, on_run_error = NA) { | |
bisect_load_all(pkgdir = pkgdir, on_error = on_load_error) | |
bisect_runtest(fun = fun, on_error = on_run_error) | |
} | |
# =========================================================== | |
# Functions to quit with return code for marking commits | |
mark_commit_good <- function() { | |
message("Returning code: good (0)\n") | |
quit(status = 0) | |
} | |
mark_commit_bad <- function() { | |
message("Returning code: bad (1)\n") | |
quit(status = 1) | |
} | |
mark_commit_skip <- function() { | |
message("Returning code: skip (125)\n") | |
quit(status = 125) | |
} | |
# ==================================================== | |
# Test code here | |
# ==================================================== | |
cat("\n===== Running test script ======\n") | |
library(devtools) | |
# A fully automated test | |
testRun <- function() { | |
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 GOOD | |
return(TRUE) | |
} | |
# If error, mark BAD | |
bisect_load_and_test(testRun, pkgdir=".", on_run_error = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a fully automated test. It must be run from a terminal shell, and, in R, it uses x11() to open new graphing windows. This may need to be modified depending on your system.
The test criteria are:
Download the script to your ggplot2 directory. The know bad commit is fd6b67 (although this typically would be master), and the known good commit was the 0.8.9 release.
Then:
When finished: