-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathtest_lesson.R
42 lines (34 loc) · 1.28 KB
/
test_lesson.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(methods)
library(yaml)
library(swirl)
test_lesson = function(lesson_dir){
print(paste("####Begin testing", lesson_dir))
.e <- environment(swirl:::any_of_exprs)
attach(.e)
on.exit(detach(.e))
e = new.env()
# Since the initLesson might change working directory, load lesson yaml first before that happens.
lesson = yaml.load_file(paste0(lesson_dir,"/lesson.yaml"))
for(R_file in c("/customTests.R", "/initLesson.R")){
R_file_path = paste0(lesson_dir, R_file)
if(file.exists(R_file_path)) source(R_file_path,local = e)
}
for(question in lesson){
if(!is.null(question$CorrectAnswer) && question$Class=="cmd_question"){
print(paste(">", question$CorrectAnswer))
suppressWarnings({
eval(parse(text=question$CorrectAnswer), envir = e)
e$expr <- parse(text = question$CorrectAnswer)[[1]]
stopifnot(eval(parse(text=question$AnswerTests), envir = e))
})
}
}
print(paste("-----Testing", lesson_dir, "Done"))
}
course_list <- list.dirs(".", recursive = FALSE)
course_list <- substring(course_list, 3, nchar(course_list))
course_list <- grep("^[^\\.]", course_list, value = TRUE)
course_list <- setdiff(course_list, c("RBasic-Motivation", "RBasic-00-Motivation"))
for(course in course_list) {
test_lesson(course)
}