-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement test_lesson and test_lesson_by_name
- Loading branch information
1 parent
66a0101
commit e6dbffa
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,3 +440,45 @@ rule <- function(title = "") { | |
width <- getOption("width") - nchar(title) - 1 | ||
message("\n", title, paste(rep("-", width, collapse = "")), "\n") | ||
} | ||
|
||
#' Test all cmd questions of current lesson. | ||
#' | ||
#' @export | ||
test_lesson <- function(){ | ||
test_lesson_by_name(getOption("swirlify_lesson_dir_name")) | ||
} | ||
|
||
#' Test all cmd questions of any lesson of current course. | ||
#' | ||
#' @param lesson_dir_name | ||
#' @importFrom yaml yaml.load_file | ||
test_lesson_by_name <- function(lesson_dir_name){ | ||
|
||
print(paste("####Begin testing:", lesson_dir_name)) | ||
.e <- environment(swirl:::any_of_exprs) | ||
attach(.e) | ||
on.exit(detach(.e)) | ||
e <- new.env() | ||
|
||
course_dir_path <- getOption("swirlify_course_dir_path") | ||
lesson_dir_path <- file.path(course_dir_path, lesson_dir_name) | ||
les <- yaml.load_file(file.path(lesson_dir_path, "lesson.yaml")) | ||
|
||
for (R_file in c("customTests.R", "initLesson.R")){ | ||
R_file_path <- file.path(lesson_dir_path, R_file) | ||
if(file.exists(R_file_path)) source(R_file_path,local = e) | ||
} | ||
|
||
for (question in les){ | ||
if(!is.null(question$CorrectAnswer) && question$Class == "cmd_question"){ | ||
print(paste(">", question$CorrectAnswer)) | ||
suppressWarnings({ | ||
eval(parse(text=question$CorrectAnswer), envir = e) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
e$expr <- parse(text = question$CorrectAnswer)[[1]] | ||
stopifnot(eval(parse(text=question$AnswerTests), envir = e)) | ||
}) | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
wush978
|
||
} | ||
|
||
print(paste("-----Testing", lesson_dir_name, "Done")) | ||
} |
This comment has been minimized.
Sorry, something went wrong.
wush978Oct 3, 2015