Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ Authors@R: c(
)
RoxygenNote: 6.1.1
VignetteBuilder: knitr
Encoding: UTF-8
8 changes: 6 additions & 2 deletions R/test-exercise.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ test_exercise <- function(sct,
#' Run SCT until it fails
#'
#' @param code the SCT script to run as an expression
#' @param envir environment in which to execute the SCT script
#'
#' @export
run_until_fail <- function(code) {
run_until_fail <- function(code, envir = NULL) {
tryCatch({
if (is.null(envir)) {
envir <- tw$get("state")$get("test_env")
}
# Run the SCT
eval(code, envir = tw$get("state")$get("test_env"))
eval(code, envir = envir)
# If it got here, the SCT passed
return(list(correct = TRUE, message = tw$get("success_msg")))
}, sct_failure = function(e) {
Expand Down
16 changes: 9 additions & 7 deletions R/utils-learnr.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @param envir_result The R environment after the execution of the chunk.
#' @param evaluate_result The return value from the \code{evaluate::evaluate}
#' function.
#' @param envir_prep A copy of the R environment before the execution of the exercise
#' @param ... Unused (include for compatibility with parameters to be added in
#' the future)
#'
Expand All @@ -33,9 +34,10 @@ testwhat_learnr <- function(label = NULL,
check_code = NULL,
envir_result = NULL,
evaluate_result = NULL,
envir_prep = NULL,
...) {
######### START COPY FROM grade_learnr ##################

######### START COPY FROM gradethis ##################
# Sometimes no user code is provided, but
# that means there is nothing to check. Also,
# you do not want to parse NULL
Expand All @@ -47,7 +49,7 @@ testwhat_learnr <- function(label = NULL,
location = "append"
))
}

# Sometimes no solution is provided, but that
# means there is nothing to check against. Also,
# you do not want to parse NULL
Expand All @@ -59,15 +61,15 @@ testwhat_learnr <- function(label = NULL,
location = "append"
))
}
######### END COPY FROM grade_learnr ##################
######### END COPY FROM gradethis ##################

setup_state(sol_code = solution_code,
stu_code = user_code,
sol_env = NULL,
stu_env = envir_result,
stu_result = evaluate_result)
res <- run_until_fail(parse(text = check_code))

res <- run_until_fail(parse(text = check_code), envir = envir_prep)
return(list(message = res$message,
correct = res$correct,
location = "append",
Expand Down
19 changes: 16 additions & 3 deletions man/check_function.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/check_logic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/run_until_fail.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/testwhat_learnr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.