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