-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_tests.R
More file actions
executable file
·64 lines (60 loc) · 2.45 KB
/
Copy pathrun_tests.R
File metadata and controls
executable file
·64 lines (60 loc) · 2.45 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env Rscript
help_message <-
"Initial testing routine for nCompiler"
argv <- commandArgs(trailingOnly = TRUE)
## This is a bare-bones implementation that can be expanded similar to
## nimble's system later.
##
## ./run-tests.R # Default to all tests with files that do not have "not working" in the first line
## ./run-tests.R test1 [test2] [...] # Run test-test1.R, test-test2.R, etc.
require(nCompiler)
NCpath <- path.package("nCompiler")
testpath <- file.path(NCpath,'tests','testthat')
if (length(grep('^-', argv, invert = TRUE))) {
# Run only tests specified on commmand line.
allTests <- paste0('test-', argv[!grepl('^-', argv)], '.R')
specificTests <- TRUE
} else {
allTests <- list.files(testpath)
specificTests <- FALSE
}
if(length(allTests) == 0) {
stop(paste0("There are no tests.\n Be sure installation included ",
"tests.\n (R CMD INSTALL <...> --install-tests)"),
call.=FALSE)
}
allTests <- allTests[grepl('test-.*\\.R', allTests)]
if(!specificTests) {
notWorking <- unlist(lapply(allTests,
function(testfile) {
firstLine <-
readLines(file.path(testpath, testfile),
n = 1)
firstLine <- toupper(firstLine)
any(grepl("NOT WORKING", firstLine))
}
)
)
allTests <- allTests[!notWorking]
cat('Running nCompiler tests.\nInclude "not working" (not case sensitive) in the first line of a test file if it should not be run.\n')
} else {
cat('Running nCompiler tests.\nIgnoring "not working" because specific tests were requested.\n')
}
for(test in allTests) {
cat('TESTING', test, '\n')
name <- gsub('test-(.*)\\.R', '\\1', test)
reporter <- '"summary"'
script <- paste0('library(methods);',
'library(testthat);',
'library(nCompiler);',
'tryCatch(test_package("nCompiler", "^', name, '$",',
' reporter = ', reporter, '),',
' error = function(e) quit(status = 1))'
)
if (system2("Rscript", c("-e", shQuote(script)))) {
stop(paste('\x1b[31mFAILED\x1b[0m', test))
} else {
cat('\x1b[32mPASSED\x1b[0m', test, '\n')
}
}
cat('\x1b[32mALL TESTS PASSED\x1b[0m', '\n')