File: argcargvtest_runme.R

package info (click to toggle)
swig 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 46,232 kB
  • sloc: cpp: 54,631; ansic: 29,122; java: 17,530; python: 12,505; cs: 10,369; ruby: 7,232; yacc: 6,477; makefile: 5,965; javascript: 5,520; sh: 5,415; perl: 4,187; php: 3,693; ml: 2,187; lisp: 2,056; tcl: 1,991; xml: 115
file content (49 lines) | stat: -rw-r--r-- 1,370 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
clargs <- commandArgs(trailing=TRUE)
source(file.path(clargs[1], "unittest.R"))
dyn.load(paste("argcargvtest", .Platform$dynlib.ext, sep=""))
source("argcargvtest.R")
cacheMetaData(1)

largs = c("hi", "hola", "hello")
unittest(3, mainc(largs))

targs = c("hi", "hola")
unittest("hi", mainv(targs, 0))
unittest("hola", mainv(targs, 1))
unittest("<<NULL>>", mainv(targs, 2))

# R convert the string to a string vector with a single string.
# So instead of exception we simply get null
unittest(NULL, mainv("hello", 1))

tryCatch({
    mainv(c(1, 2, 3), 1)
    # force an error if the previous line doesn't raise an exception
    stop("Test Failure A")
}, error = function(e) {
    if (e$message == "Test Failure A") {
      # Raise the error again to cause a failed test
      stop(e)
    }
    message("PASS")
})

initializeApp(largs)
initializeApp(largs, TRUE)

# Check that an empty array works.
empty_args = c()
unittest(0, mainc(empty_args))
unittest("<<NULL>>", mainv(empty_args, 0))

# check dispatcher with empty array.
initializeApp(empty_args)
initializeApp(empty_args, FALSE, TRUE)

# Check that empty strings are handled.
empty_string = c("hello", "", "world")
unittest(3, mainc(empty_string))
unittest("hello", mainv(empty_string, 0))
unittest("", mainv(empty_string, 1))
unittest("world", mainv(empty_string, 2))
unittest("<<NULL>>", mainv(empty_string, 3))