Browse code

add structure for unit tests (currently empty)

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/crlmm@52982 bc3139a8-67e5-0310-9ffc-ced21a209358

Rob Scharp authored on 18/02/2011 19:17:55
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,48 @@
1
+.test <- function(dir, pattern = "^test_.*\\.R$")
2
+{
3
+    .failure_details <- function(result) {
4
+        res <- result[[1L]]
5
+        if (res$nFail > 0 || res$nErr > 0) {
6
+            Filter(function(x) length(x) > 0,
7
+                   lapply(res$sourceFileResults,
8
+                          function(fileRes) {
9
+                              names(Filter(function(x) x$kind != "success",
10
+                                           fileRes))
11
+                          }))
12
+        } else list()
13
+    }
14
+
15
+    if (missing(dir)) {
16
+        dir <- system.file("unitTests", package="crlmm")
17
+        if (!length(dir)) {
18
+            dir <- system.file("UnitTests", package="crlmm")
19
+            if (!length(dir))
20
+                stop("unable to find unit tests, no 'unitTests' dir")
21
+        }
22
+    }
23
+    require("RUnit", quietly=TRUE) || stop("RUnit package not found")
24
+    RUnit_opts <- getOption("RUnit", list())
25
+    RUnit_opts$verbose <- 0L
26
+    RUnit_opts$silent <- TRUE
27
+    RUnit_opts$verbose_fail_msg <- TRUE
28
+    options(RUnit = RUnit_opts)
29
+    suite <- defineTestSuite(name="crlmm RUnit Tests", dirs=dir,
30
+                             testFileRegexp=pattern,
31
+                             rngKind="default",
32
+                             rngNormalKind="default")
33
+    result <- runTestSuite(suite)
34
+    cat("\n\n")
35
+    printTextProtocol(result, showDetails=FALSE)
36
+    if (length(details <- .failure_details(result)) >0) {
37
+        cat("\nTest files with failing tests\n")
38
+        for (i in seq_along(details)) {
39
+            cat("\n  ", basename(names(details)[[i]]), "\n")
40
+            for (j in seq_along(details[[i]])) {
41
+                cat("    ", details[[i]][[j]], "\n")
42
+            }
43
+        }
44
+        cat("\n\n")
45
+        stop("unit tests failed for package crlmm")
46
+    }
47
+    result
48
+}