-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathtest-system.R
60 lines (48 loc) · 1.95 KB
/
test-system.R
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
## 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")
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(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))
}
process(system("test-system2"))
process(system("test-system2", ignore.stdout = TRUE))
process(system("test-system2", ignore.stderr = TRUE))
process(system("test-system2", ignore.stdout = TRUE, ignore.stderr = TRUE))
process(system("test-system2", TRUE))
process(system("test-system2", TRUE, ignore.stdout = TRUE))
process(system("test-system2", TRUE, ignore.stdout = TRUE, ignore.stderr = TRUE))
process(system2("test-system2", "1", input=letters[1:4]))
process(system2("test-system2", "1", input=letters[1:4], stdout = TRUE))
process(system("test-system2 1", input=letters[1:4]))
process(system("test-system2 1", input=letters[1:4], intern = TRUE))
tmp <- tempfile()
writeLines(letters[5:7], tmp)
process(system2("test-system2", "1", stdin = tmp))
process(system2("test-system2", "1", stdin = tmp, stdout = TRUE))
process(system2("test-system2", "1", stdin = tmp, stdout = TRUE, stderr = TRUE))
process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt", stderr = "o1.txt"))
process(system2("test-system2", "1", stdin = tmp, stdout = "o1.txt", stderr = "o2.txt"))
unlink(c(tmp, outs))
print(system("test-system2 5"))
system("test-system2 6", intern = TRUE)
print(system2("test-system2", "7"))
system2("test-system2", "8", stdout=TRUE)