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
Showing3 changed files

... ...
@@ -1,4 +1,4 @@
1
-test*
1
+test/*
2 2
 myCrlmmGT2.Rnw
3 3
 ffobjs*
4 4
 auto*
... ...
@@ -19,3 +19,8 @@ copynumber.log
19 19
 *.png
20 20
 *~
21 21
 relocating*
22
+push
23
+pull
24
+copynumber.R
25
+runcopynumber.R
26
+runillumina.R
22 27
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
+}
0 49
new file mode 100644
... ...
@@ -0,0 +1,2 @@
1
+require("crlmm") || stop("unable to load crlmm package")
2
+crlmm:::.test()