]> gitweb.factorcode.org Git - factor.git/blob - basis/io/launcher/windows/windows-tests.factor
Squashed commit of the following:
[factor.git] / basis / io / launcher / windows / windows-tests.factor
1 USING: accessors arrays assocs calendar continuations\r
2 environment eval hashtables io io.directories\r
3 io.encodings.ascii io.files io.files.temp io.launcher\r
4 io.launcher.windows io.pathnames kernel math namespaces parser\r
5 sequences splitting system tools.test ;\r
6 IN: io.launcher.windows.tests\r
7 \r
8 [ "hello world" ] [ { "hello" "world" } join-arguments ] unit-test\r
9 \r
10 [ "bob \"mac arthur\"" ] [ { "bob" "mac arthur" } join-arguments ] unit-test\r
11 \r
12 [ "bob mac\\\\arthur" ] [ { "bob" "mac\\\\arthur" } join-arguments ] unit-test\r
13 \r
14 [ "bob \"mac arthur\\\\\"" ] [ { "bob" "mac arthur\\" } join-arguments ] unit-test\r
15 \r
16 [ ] [\r
17     <process>\r
18         "notepad" >>command\r
19         1/2 seconds >>timeout\r
20     "notepad" set\r
21 ] unit-test\r
22 \r
23 [ f ] [ "notepad" get process-running? ] unit-test\r
24 \r
25 [ f ] [ "notepad" get process-started? ] unit-test\r
26 \r
27 [ ] [ "notepad" [ run-detached ] change ] unit-test\r
28 \r
29 [ "notepad" get wait-for-process ] must-fail\r
30 \r
31 [ t ] [ "notepad" get killed>> ] unit-test\r
32 \r
33 [ f ] [ "notepad" get process-running? ] unit-test\r
34 \r
35 [\r
36     <process>\r
37         "notepad" >>command\r
38         1/2 seconds >>timeout\r
39     try-process\r
40 ] must-fail\r
41 \r
42 [\r
43     <process>\r
44         "notepad" >>command\r
45         1/2 seconds >>timeout\r
46     try-output-process\r
47 ] must-fail\r
48 \r
49 : console-vm ( -- path )\r
50     vm ".exe" ?tail [ ".com" append ] when ;\r
51 \r
52 [ ] [\r
53     <process>\r
54         console-vm "-quiet" "-run=hello-world" 3array >>command\r
55         "out.txt" temp-file >>stdout\r
56     try-process\r
57 ] unit-test\r
58 \r
59 [ "Hello world" ] [\r
60     "out.txt" temp-file ascii file-lines first\r
61 ] unit-test\r
62 \r
63 [ "( scratchpad ) " ] [\r
64     <process>\r
65         console-vm "-run=listener" 2array >>command\r
66         +closed+ >>stdin\r
67         +stdout+ >>stderr\r
68     ascii [ lines last ] with-process-reader\r
69 ] unit-test\r
70 \r
71 : launcher-test-path ( -- str )\r
72     "resource:basis/io/launcher/windows/test" ;\r
73 \r
74 [ ] [\r
75     launcher-test-path [\r
76         <process>\r
77             console-vm "-script" "stderr.factor" 3array >>command\r
78             "out.txt" temp-file >>stdout\r
79             "err.txt" temp-file >>stderr\r
80         try-process\r
81     ] with-directory\r
82 ] unit-test\r
83 \r
84 [ "output" ] [\r
85     "out.txt" temp-file ascii file-lines first\r
86 ] unit-test\r
87 \r
88 [ "error" ] [\r
89     "err.txt" temp-file ascii file-lines first\r
90 ] unit-test\r
91 \r
92 [ ] [\r
93     launcher-test-path [\r
94         <process>\r
95             console-vm "-script" "stderr.factor" 3array >>command\r
96             "out.txt" temp-file >>stdout\r
97             +stdout+ >>stderr\r
98         try-process\r
99     ] with-directory\r
100 ] unit-test\r
101 \r
102 [ "outputerror" ] [\r
103     "out.txt" temp-file ascii file-lines first\r
104 ] unit-test\r
105 \r
106 [ "output" ] [\r
107     launcher-test-path [\r
108         <process>\r
109             console-vm "-script" "stderr.factor" 3array >>command\r
110             "err2.txt" temp-file >>stderr\r
111         ascii <process-reader> stream-lines first\r
112     ] with-directory\r
113 ] unit-test\r
114 \r
115 [ "error" ] [\r
116     "err2.txt" temp-file ascii file-lines first\r
117 ] unit-test\r
118 \r
119 [ t ] [\r
120     launcher-test-path [\r
121         <process>\r
122             console-vm "-script" "env.factor" 3array >>command\r
123         ascii <process-reader> stream-contents\r
124     ] with-directory eval( -- alist )\r
125 \r
126     os-envs =\r
127 ] unit-test\r
128 \r
129 [ t ] [\r
130     launcher-test-path [\r
131         <process>\r
132             console-vm "-script" "env.factor" 3array >>command\r
133             +replace-environment+ >>environment-mode\r
134             os-envs >>environment\r
135         ascii <process-reader> stream-contents\r
136     ] with-directory eval( -- alist )\r
137     \r
138     os-envs =\r
139 ] unit-test\r
140 \r
141 [ "B" ] [\r
142     launcher-test-path [\r
143         <process>\r
144             console-vm "-script" "env.factor" 3array >>command\r
145             { { "A" "B" } } >>environment\r
146         ascii <process-reader> stream-contents\r
147     ] with-directory eval( -- alist )\r
148 \r
149     "A" swap at\r
150 ] unit-test\r
151 \r
152 [ f ] [\r
153     launcher-test-path [\r
154         <process>\r
155             console-vm "-script" "env.factor" 3array >>command\r
156             { { "USERPROFILE" "XXX" } } >>environment\r
157             +prepend-environment+ >>environment-mode\r
158         ascii <process-reader> stream-contents\r
159     ] with-directory eval( -- alist )\r
160 \r
161     "USERPROFILE" swap at "XXX" =\r
162 ] unit-test\r
163 \r
164 2 [\r
165     [ ] [\r
166         <process>\r
167             "cmd.exe /c dir" >>command\r
168             "dir.txt" temp-file >>stdout\r
169         try-process\r
170     ] unit-test\r
171 \r
172     [ ] [ "dir.txt" temp-file delete-file ] unit-test\r
173 ] times\r
174 \r
175 [ "append-test" temp-file delete-file ] ignore-errors\r
176 \r
177 [ "Hello appender\r\nHello appender\r\n" ] [\r
178     2 [\r
179         launcher-test-path [\r
180             <process>\r
181                 console-vm "-script" "append.factor" 3array >>command\r
182                 "append-test" temp-file <appender> >>stdout\r
183             try-process\r
184         ] with-directory\r
185     ] times\r
186    \r
187     "append-test" temp-file ascii file-contents\r
188 ] unit-test\r
189 \r
190 [ "( scratchpad ) " ] [\r
191     console-vm "-run=listener" 2array\r
192     ascii [ "USE: system 0 exit" print flush lines last ] with-process-stream\r
193 ] unit-test\r
194 \r
195 [ ] [\r
196     console-vm "-run=listener" 2array\r
197     ascii [ "USE: system 0 exit" print ] with-process-writer\r
198 ] unit-test\r
199 \r
200 [ ] [\r
201     <process>\r
202     console-vm "-run=listener" 2array >>command\r
203     "vocab:io/launcher/windows/test/input.txt" >>stdin\r
204     try-process\r
205 ] unit-test\r