-
Notifications
You must be signed in to change notification settings - Fork 7
/
testcase.R
42 lines (40 loc) · 1.52 KB
/
testcase.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
testcase <- function(description = NULL, tests={}) {
get_reporter()$start_testcase(description)
do_exit <- TRUE
on.exit({
if(do_exit) {
get_reporter()$end_testcase()
}
})
tryCatch({ eval(tests) }, error = function(e) {
get_reporter()$add_message(paste("Error while evaluating testcase: ", conditionMessage(e), sep = ''))
get_reporter()$escalate("runtime error")
get_reporter()$end_testcase(accepted = FALSE)
do_exit <<- FALSE
})
}
testcaseAssert <- function(description, checker) {
get_reporter()$start_testcase(description)
tryCatch(
withCallingHandlers(
{
capture.output(checker_val <- checker(test_env$clean_env))
if (!checker_val) {
get_reporter()$escalate("wrong")
}
get_reporter()$end_testcase(accepted = checker_val)
},
warning = function(w) {
get_reporter()$add_message(paste("Warning while evaluating assert: ", conditionMessage(w), sep = ''))
},
message = function(m) {
get_reporter()$add_message(paste("Message while evaluating assert: ", conditionMessage(m), sep = ''))
}
),
error = function(e) {
get_reporter()$add_message(paste("Error while evaluating assert: ", conditionMessage(e), sep = ''))
get_reporter()$escalate("runtime error")
get_reporter()$end_testcase(accepted = FALSE)
}
)
}