~ubuntu-branches/ubuntu/raring/r-cran-stabledist/raring-proposed

« back to all changes in this revision

Viewing changes to inst/unitTests/runTests.R

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2011-03-18 08:33:40 UTC
  • Revision ID: james.westby@ubuntu.com-20110318083340-u3amutr8bf808yav
Tags: upstream-0.6-0
ImportĀ upstreamĀ versionĀ 0.6-0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
pkg <- "stabledist"
 
2
 
 
3
if(require("RUnit", quietly = TRUE))
 
4
{
 
5
 
 
6
    library(package=pkg, character.only = TRUE)
 
7
    if(!(exists("path") && file.exists(path)))
 
8
        path <- system.file("unitTests", package = pkg)
 
9
 
 
10
    ## --- Testing ---
 
11
 
 
12
    ## Define tests
 
13
    testSuite <- defineTestSuite(name = paste(pkg, "unit testing"),
 
14
                                 dirs = path)
 
15
 
 
16
    if(interactive()) {
 
17
        cat("Now have RUnit Test Suite 'testSuite' for package '",
 
18
            pkg, "' :\n", sep='')
 
19
        str(testSuite)
 
20
        cat('', "Consider doing",
 
21
            "\t  tests <- runTestSuite(testSuite)", "\nand later",
 
22
            "\t  printTextProtocol(tests)", '', sep = "\n")
 
23
    } else {
 
24
        ## run from shell / Rscript / R CMD Batch / ...
 
25
        ## Run
 
26
        tests <- runTestSuite(testSuite)
 
27
 
 
28
        if(file.access(path, 02) != 0) {
 
29
            ## cannot write to path -> use writable one
 
30
            tdir <- tempfile(paste(pkg, "unitTests", sep="_"))
 
31
            dir.create(tdir)
 
32
            pathReport <- file.path(tdir, "report")
 
33
            cat("RUnit reports are written into ", tdir, "/report.(txt|html)",
 
34
                sep = "")
 
35
        } else {
 
36
            pathReport <- file.path(path, "report")
 
37
        }
 
38
 
 
39
        ## Print Results:
 
40
        printTextProtocol(tests, showDetails = FALSE)
 
41
        printTextProtocol(tests, showDetails = FALSE,
 
42
                          fileName = paste(pathReport, "Summary.txt", sep = ""))
 
43
        printTextProtocol(tests, showDetails = TRUE,
 
44
                          fileName = paste(pathReport, ".txt", sep = ""))
 
45
 
 
46
        ## Print HTML Version to a File:
 
47
        ## printHTMLProtocol has problems on Mac OS X
 
48
        if (Sys.info()["sysname"] != "Darwin")
 
49
        printHTMLProtocol(tests,
 
50
                          fileName = paste(pathReport, ".html", sep = ""))
 
51
 
 
52
        ## stop() if there are any failures i.e. FALSE to unit test.
 
53
        ## This will cause R CMD check to return error and stop
 
54
        tmp <- getErrors(tests)
 
55
        if(tmp$nFail > 0 | tmp$nErr > 0) {
 
56
            stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
 
57
                       ", R errors: ",  tmp$nErr, ")\n\n", sep=""))
 
58
        }
 
59
    }
 
60
} else {
 
61
    cat("R package 'RUnit' cannot be loaded -- no unit tests run\n",
 
62
        "for package", pkg,"\n")
 
63
}
 
64
 
 
65
 
 
66
################################################################################