The R Project SVN R

Rev

Rev 53611 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 53611 Rev 72823
Line 2... Line 2...
2
 
2
 
3
options(warn = 1)
3
options(warn = 1)
4
 
4
 
5
opts <- list("", NULL, FALSE, TRUE, "o1.txt", "o2.txt")
5
opts <- list("", NULL, FALSE, TRUE, "o1.txt", "o2.txt")
6
outs <- c("o1.txt", "o2.txt")
6
outs <- c("o1.txt", "o2.txt")
-
 
7
tos <- c(0, 10)
7
 
8
 
8
process <- function(res)
9
process <- function(res)
9
{
10
{
10
    unlink(outs)
11
    unlink(outs)
11
    if(is.character(res)) {
12
    if(is.character(res)) {
Line 17... Line 18...
17
            cat(f, ":\n", sep = "")
18
            cat(f, ":\n", sep = "")
18
            writeLines(readLines(f))
19
            writeLines(readLines(f))
19
        }
20
        }
20
}
21
}
21
 
22
 
-
 
23
for(to in tos)
22
for(out in opts)
24
    for(out in opts)
23
    for(err in opts) {
25
        for(err in opts) {
24
        ## skip this for the sake of Unix-alikes
26
            ## skip this for the sake of Unix-alikes
25
        if(identical(err, TRUE) && !identical(out,TRUE)) next
27
            if(identical(err, TRUE) && !identical(out,TRUE)) next
26
        cat(sprintf("\ntesting stdout = %s, stderr = %s\n",
28
            cat(sprintf("\ntesting stdout = %s, stderr = %s\n",
27
            deparse(out), deparse(err)))
29
                deparse(out), deparse(err)))
28
        process(system2("test-system2", stdout = out, stderr = err))
30
            process(system2("test-system2", stdout = out, stderr = err,
-
 
31
                            timeout = to))
29
    }
32
        }
-
 
33
 
-
 
34
for(to in tos) {
-
 
35
    # timeout 0 uses different implementations from timeout 10
-
 
36
    # the outputs should be identical
-
 
37
 
-
 
38
    process(system("test-system2", timeout = to))
-
 
39
    process(system("test-system2", ignore.stdout = TRUE, timeout = to))
-
 
40
    process(system("test-system2", ignore.stderr = TRUE, timeout = to))
-
 
41
    process(system("test-system2", ignore.stdout = TRUE, ignore.stderr = TRUE,
-
 
42
                   timeout = to))
-
 
43
 
-
 
44
    process(system("test-system2", TRUE, timeout = to))
-
 
45
    process(system("test-system2", TRUE, ignore.stdout = TRUE, timeout = to))
-
 
46
    process(system("test-system2", TRUE, ignore.stdout = TRUE,
-
 
47
                   ignore.stderr = TRUE, timeout = to))
-
 
48
 
-
 
49
    process(system2("test-system2", "1", input=letters[1:4], timeout = to))
-
 
50
    process(system2("test-system2", "1", input=letters[1:4], stdout = TRUE,
-
 
51
                    timeout = to))
-
 
52
 
-
 
53
    process(system("test-system2 1", input=letters[1:4], timeout = to))
-
 
54
    process(system("test-system2 1", input=letters[1:4], intern = TRUE,
-
 
55
                   timeout = to))
-
 
56
 
-
 
57
    tmp <- tempfile()
-
 
58
    writeLines(letters[5:7], tmp)
-
 
59
    process(system2("test-system2", "1", stdin = tmp, timeout = to))
-
 
60
    process(system2("test-system2", "1", stdin = tmp, stdout = TRUE,
-
 
61
                    timeout = to))
-
 
62
    process(system2("test-system2", "1", stdin = tmp, stdout = TRUE,
-
 
63
                    stderr = TRUE, timeout = to))
-
 
64
    process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt",
-
 
65
                    stderr = "o1.txt", timeout = to))
-
 
66
    process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt",
-
 
67
                    stderr = "o2.txt", timeout = to))
-
 
68
 
-
 
69
    unlink(c(tmp, outs))
-
 
70
 
-
 
71
    print(system("test-system2 5", timeout = to))
-
 
72
    system("test-system2 6", intern = TRUE, timeout = to)
-
 
73
    print(system2("test-system2", "7", timeout = to))
-
 
74
    system2("test-system2", "8", stdout=TRUE, timeout = to)
-
 
75
}
30
 
76
 
-
 
77
# tests that time out
-
 
78
#   (each runs for a second)
31
 
79
 
32
process(system("test-system2"))
-
 
33
process(system("test-system2", ignore.stdout = TRUE))
80
system("./test-system2 sleep 10", timeout = 1)
34
process(system("test-system2", ignore.stderr = TRUE))
81
system("./test-system2 infinite_loop", timeout = 1)
35
process(system("test-system2", ignore.stdout = TRUE, ignore.stderr = TRUE))
82
system("./test-system2 sleep 10", timeout = 1, intern = T)
36
 
-
 
37
process(system("test-system2", TRUE))
-
 
38
process(system("test-system2", TRUE, ignore.stdout = TRUE))
-
 
39
process(system("test-system2", TRUE, ignore.stdout = TRUE, ignore.stderr = TRUE))
83
system("./test-system2 infinite_loop", timeout = 1, intern = T)
40
 
84
 
41
process(system2("test-system2", "1", input=letters[1:4]))
85
## test results with timeout set
42
process(system2("test-system2", "1", input=letters[1:4], stdout = TRUE))
-
 
43
 
86
 
44
process(system("test-system2 1", input=letters[1:4]))
87
stopifnot(identical(system("./test-system2 2", timeout = 1), 2L))
45
process(system("test-system2 1", input=letters[1:4], intern = TRUE))
88
stopifnot(identical(system("./test-system2 2", timeout = 1, intern = T),
46
 
-
 
47
tmp <- tempfile()
-
 
48
writeLines(letters[5:7], tmp)
-
 
49
process(system2("test-system2", "1", stdin = tmp))
89
                    structure("stdout 1", status = 2L)))
50
process(system2("test-system2", "1", stdin = tmp, stdout = TRUE))
-
 
51
process(system2("test-system2", "1", stdin = tmp, stdout = TRUE, stderr = TRUE))
-
 
52
process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt", stderr = "o1.txt"))
-
 
53
process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt", stderr = "o2.txt"))
-
 
54
 
-
 
55
unlink(c(tmp, outs))
-
 
56
 
-
 
57
print(system("test-system2 5"))
-
 
58
system("test-system2 6", intern = TRUE)
-
 
59
print(system2("test-system2", "7"))
-
 
60
system2("test-system2", "8", stdout=TRUE)
-