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