File: test-system.R

package info (click to toggle)
r-base 4.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,924 kB
  • sloc: ansic: 291,338; fortran: 111,889; javascript: 14,798; yacc: 6,154; sh: 5,689; makefile: 5,239; tcl: 4,562; perl: 963; objc: 791; f90: 758; asm: 258; java: 31; sed: 1
file content (89 lines) | stat: -rw-r--r-- 3,252 bytes parent folder | download | duplicates (5)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
## tests of options in system() and system2.

options(warn = 1)

opts <- list("", NULL, FALSE, TRUE, "o1.txt", "o2.txt")
outs <- c("o1.txt", "o2.txt")
tos <- c(0, 10)

process <- function(res)
{
    unlink(outs)
    if(is.character(res)) {
        cat("value:\n")
        writeLines(res)
    }
    for(f in outs)
        if(file.exists(f)) {
            cat(f, ":\n", sep = "")
            writeLines(readLines(f))
        }
}

for(to in tos)
    for(out in opts)
        for(err in opts) {
            ## skip this for the sake of Unix-alikes
            if(identical(err, TRUE) && !identical(out,TRUE)) next
            cat(sprintf("\ntesting stdout = %s, stderr = %s\n",
                deparse(out), deparse(err)))
            process(system2("test-system2", stdout = out, stderr = err,
                            timeout = to))
        }

for(to in tos) {
    # timeout 0 uses different implementations from timeout 10
    # the outputs should be identical

    process(system("test-system2", timeout = to))
    process(system("test-system2", ignore.stdout = TRUE, timeout = to))
    process(system("test-system2", ignore.stderr = TRUE, timeout = to))
    process(system("test-system2", ignore.stdout = TRUE, ignore.stderr = TRUE,
                   timeout = to))

    process(system("test-system2", TRUE, timeout = to))
    process(system("test-system2", TRUE, ignore.stdout = TRUE, timeout = to))
    process(system("test-system2", TRUE, ignore.stdout = TRUE,
                   ignore.stderr = TRUE, timeout = to))

    process(system2("test-system2", "1", input=letters[1:4], timeout = to))
    process(system2("test-system2", "1", input=letters[1:4], stdout = TRUE,
                    timeout = to))

    process(system("test-system2 1", input=letters[1:4], timeout = to))
    process(system("test-system2 1", input=letters[1:4], intern = TRUE,
                   timeout = to))

    tmp <- tempfile()
    writeLines(letters[5:7], tmp)
    process(system2("test-system2", "1", stdin = tmp, timeout = to))
    process(system2("test-system2", "1", stdin = tmp, stdout = TRUE,
                    timeout = to))
    process(system2("test-system2", "1", stdin = tmp, stdout = TRUE,
                    stderr = TRUE, timeout = to))
    process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt",
                    stderr = "o1.txt", timeout = to))
    process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt",
                    stderr = "o2.txt", timeout = to))

    unlink(c(tmp, outs))

    print(system("test-system2 5", timeout = to))
    system("test-system2 6", intern = TRUE, timeout = to)
    print(system2("test-system2", "7", timeout = to))
    system2("test-system2", "8", stdout=TRUE, timeout = to)
}

# tests that time out
#   (each runs for a second)

system("./test-system2 sleep 10", timeout = 1)
system("./test-system2 infinite_loop", timeout = 1)
system("./test-system2 sleep 10", timeout = 1, intern = T)
system("./test-system2 infinite_loop", timeout = 1, intern = T)

## test results with timeout set

stopifnot(identical(system("./test-system2 2", timeout = 1), 2L))
stopifnot(identical(system("./test-system2 2", timeout = 1, intern = T),
                    structure("stdout 1", status = 2L)))