-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.carp
More file actions
107 lines (89 loc) · 4.07 KB
/
Copy pathtests.carp
File metadata and controls
107 lines (89 loc) · 4.07 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(load-and-use Test)
(load "./subprocess.carp")
(Debug.sanitize-addresses)
(defn test-args []
[@"sh" @"-c" @"echo 'this is stderr' 1>&2; echo 'this is stdout'; exit 42"])
(def pipe-all (Subprocess.cmd (SubprocessOptions.spp) &(test-args)))
(def print-all (Subprocess.cmd (SubprocessOptions.sss) &(test-args)))
(def fold-err-into-out (Subprocess.cmd (SubprocessOptions.spo) &(test-args)))
(def fold-err-into-out-large
(Subprocess.cmd (SubprocessOptions.spo)
&[@"printf" (String.repeat 10000 "wow")]))
(def finishes-with-open-pipe
(Subprocess.cmd (SubprocessOptions.pss) &[@"echo" @"finishes with open pipe"]))
(deftest test
(assert-equal test
&(Just @"this is stdout\n")
(SubprocessRes.out &pipe-all)
"pipe - out works with small output")
(assert-equal test
&(Just @"this is stderr\n")
(SubprocessRes.err &pipe-all)
"pipe - err works with small output")
(assert-equal test
&42
(SubprocessRes.exit-code &pipe-all)
"pipe - exit-code works with small output")
(assert-equal test
&(Nothing)
(SubprocessRes.out &print-all)
"print - out works with small output")
(assert-equal test
&(Nothing)
(SubprocessRes.err &print-all)
"print - err works with small output")
(assert-equal test
&42
(SubprocessRes.exit-code &print-all)
"print - exit-code works with small output")
(assert-equal test
&(Just @"this is stderr\nthis is stdout\n")
(SubprocessRes.out &fold-err-into-out)
"combine - out works with small output")
(assert-equal test
&(Nothing)
(SubprocessRes.err &fold-err-into-out)
"combine - err works with small output")
(assert-equal test
&42
(SubprocessRes.exit-code &fold-err-into-out)
"combine - exit-code works with small output")
(assert-true test
(= &(Just (String.repeat 10000 "wow"))
(SubprocessRes.out &fold-err-into-out-large))
"combine - out works with large output")
(assert-equal test
&(Nothing)
(SubprocessRes.err &fold-err-into-out-large)
"combine - err works with large output")
(assert-equal test
&0
(SubprocessRes.exit-code &fold-err-into-out-large)
"combine - exit-code works with large output")
(assert-equal test
&0
(SubprocessRes.exit-code &finishes-with-open-pipe)
"finishes with open pipe")
(assert-equal test
&0
(SubprocessRes.exit-code &(Subprocess.cmd (SubprocessOptions.sss) &[]))
"succeeds when no commands passed")
(assert-equal test
&(SubprocessRes (Just @"wow") (Nothing) 0)
&(let [echo (Subprocess.call (SubprocessOptions.sps) &[@"printf" @"wow"])
out-pipe (Maybe.unsafe-from @(Subprocess.out &echo))]
(Subprocess.cmd (SubprocessOptions.ips out-pipe) &[@"cat"]))
"can pipe in and pipe out on small input/output")
(assert-equal test
&(SubprocessRes (Just @"wow") (Nothing) 0)
&(let [echo (Subprocess.call (SubprocessOptions.sps) &[@"printf" @"wow"])
out-pipe (Maybe.unsafe-from @(Subprocess.out &echo))]
(Subprocess.cmd (SubprocessOptions.ips out-pipe) &[@"cat"]))
"can pipe in and pipe out on small input/output")
(assert-equal test
&(SubprocessRes (Just @"you<are>surrounded\n") (Nothing) 0)
&(Subprocess.collect
(Subprocess.pipe &[[@"echo" @"are"]
[@"awk" @"{print \"you>\" $0 \"<surrounded\"}"]
[@"tr" @"<>" @"><"]]))
"Subprocess.pipe can pipe commands together"))