File: doSvUnit.R

package info (click to toggle)
r-cran-distr 2.9.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,344 kB
  • sloc: ansic: 199; sh: 13; makefile: 2
file content (73 lines) | stat: -rw-r--r-- 2,615 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
# we only run the tests, if svUnit is available
if (require(svUnit, quietly=TRUE)) {
  pkg <- "distr"
  require("distr")
  
  # we must investigate whether R CMD check is running or not
  #   and if the check is running, whether a time limit exists
  RCMDCHECK <- FALSE
  RCMDCHECKCRAN <- FALSE
  
  for (actual.name in names(Sys.getenv())) {
    if (substr(actual.name, 1, 9) == "_R_CHECK_") {
      RCMDCHECK <- TRUE
      
      if (actual.name == "_R_CHECK_TIMINGS_") {
        RCMDCHECKCRAN <- (as.numeric(Sys.getenv("_R_CHECK_TIMINGS_")) > 0)
      }
    }
  }
  
  # we must determine the path for tests in the installation and outside installation
  if (RCMDCHECK) {
    ## Path to unit tests for R CMD check
    ## PKG.Rcheck/tests/../PKG/unitTests
    ## PKG.Rcheck/tests/unitTests
    
    # we determine the two paths
    pathTestsInInstallation <- system.file(package=pkg, "unitTests")
    pathTestsOutsideInstallation <- file.path(getwd(), "unitTests")
  } else {
    ## Path to unit tests for standalone running as script with "PKG/tests" as working directory
    ## PKG/tests/../inst/unitTests
    ## PKG/tests/unitTests
    
    # we determine the two paths
    pathTestsInInstallation <- file.path(getwd(), "..", "inst", "unitTests")
    pathTestsOutsideInstallation <- file.path(getwd(), "unitTests")
  }
  
  print(pathTestsInInstallation)
  print(pathTestsOutsideInstallation)
  
  # it depends whether we want to skip the long running tests or not
  if (RCMDCHECKCRAN) {
    mypkgSuite <- svSuiteList(packages=pkg, dirs=pathTestsInInstallation)
  } else {
    mypkgSuite <- svSuiteList(packages=pkg, dirs=c(pathTestsInInstallation, pathTestsOutsideInstallation))
  }
  
  unlink("report.txt")  # Make sure we generate a new report
  
  print(svSuiteList(packages=FALSE, dirs=c(pathTestsInInstallation, pathTestsOutsideInstallation)))
  
  runTest(mypkgSuite, name = pkg)  # Run them...
  
  ## makeTestListFromExamples is in svUnit 0.7.8 or more
  #doRunExamples <- TRUE
  #svUnitVersion = as.integer(strsplit(installed.packages()[which(installed.packages()[, 'Package'] == "svUnit"), "Version"], "[\\.-]")[[1]])
  #if (svUnitVersion[1] == 0) {
  #  if (svUnitVersion[2] < 7) {
  #    doRunExamples <- FALSE
  #  } else {
  #    if (svUnitVersion[2] == 7)
  #      doRunExamples <- svUnitVersion[3] >= 8
  #  }
  #}
  #if(doRunExamples)
  #  runTest(tryCatch(makeTestListFromExamples(pkg, "../../pkg/man/"), error=function(e) NULL))
  
  
  protocol(Log(), type = "text", file = "report.txt")  # ... and write report
}