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
10 [ "hello world" ] [ { "hello" "world" } join-arguments ] unit-test
12 [ "bob \"mac arthur\"" ] [ { "bob" "mac arthur" } join-arguments ] unit-test
14 [ "bob mac\\\\arthur" ] [ { "bob" "mac\\\\arthur" } join-arguments ] unit-test
16 [ "bob \"mac arthur\\\\\"" ] [ { "bob" "mac arthur\\" } join-arguments ] unit-test
19 [ "\\\"hi\\\"" ] [ { "\"hi\"" } join-arguments ] unit-test
21 [ "\"\\\"hi you\\\"\"" ] [ { "\"hi you\"" } join-arguments ] unit-test
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
28 ! \"foo"\\bar\\\bas\ -> \\\"foo\"\\bar\\\bas\
29 [ "\\\\\\\"foo\\\"\\\\bar\\\\\\bas\\" ]
30 [ { "\\\"foo\"\\\\bar\\\\\\bas\\" } join-arguments ] unit-test
32 ! \foo\\"bar"\\\bas\ -> \foo\\\\\"bar\"\\\bas\
33 [ "\\foo\\\\\\\\\\\"bar\\\"\\\\\\bas\\" ]
34 [ { "\\foo\\\\\"bar\"\\\\\\bas\\" } join-arguments ] unit-test
36 ! \foo\\bar\\\"bas"\ -> \foo\\bar\\\\\\\"bas\"\
37 [ "\\foo\\\\bar\\\\\\\\\\\\\\\"bas\\\"\\" ]
38 [ { "\\foo\\\\bar\\\\\\\"bas\"\\" } join-arguments ] unit-test
40 ! \foo\\bar bar\\\bas\ -> "\foo\\bar bar\\\bas\\"
41 [ "\"\\foo\\\\bar bar\\\\\\bas\\\\\"" ]
42 [ { "\\foo\\\\bar bar\\\\\\bas\\" } join-arguments ] unit-test
52 [ f ] [ "notepad" get process-running? ] unit-test
54 [ f ] [ "notepad" get process-started? ] unit-test
56 [ ] [ "notepad" [ run-detached ] change ] unit-test
58 [ "notepad" get wait-for-process ] must-fail
60 [ t ] [ "notepad" get killed>> ] unit-test
62 [ f ] [ "notepad" get process-running? ] unit-test
78 : console-vm-path ( -- path )
79 vm-path ".exe" ?tail [ ".com" append ] when ;
81 SYMBOLS: out-path err-path ;
85 console-vm-path "-run=hello-world" 2array >>command
86 [ "out" ".txt" unique-file ] with-temp-directory
87 [ out-path set-global ] keep >>stdout
92 out-path get-global ascii file-lines first
95 [ "IN: scratchpad " ] [
97 console-vm-path "-run=listener" 2array >>command
100 utf8 [ lines last ] with-process-reader
103 : launcher-test-path ( -- str )
104 "resource:basis/io/launcher/windows/test" ;
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
119 out-path get-global ascii file-lines first
123 err-path get-global ascii file-lines first
129 console-vm-path "-script" "stderr.factor" 3array >>command
130 [ "out" ".txt" unique-file ] with-temp-directory
131 [ out-path set-global ] keep >>stdout
138 out-path get-global ascii file-lines first
144 console-vm-path "-script" "stderr.factor" 3array >>command
145 [ "err2" ".txt" unique-file ] with-temp-directory
146 [ err-path set-global ] keep >>stderr
152 err-path get-global ascii file-lines first
160 console-vm-path "-script" "env.factor" 3array >>command
161 utf8 [ read-contents ] with-process-reader
162 ] with-directory eval( -- alist )
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 )
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 )
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 )
199 "USERPROFILE" of "XXX" =
205 "cmd.exe /c dir" >>command
206 [ "dir" ".txt" unique-file ] with-temp-directory
207 [ out-path set-global ] keep >>stdout
211 [ ] [ out-path get-global delete-file ] unit-test
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
219 console-vm-path "-script" "append.factor" 3array >>command
220 out-path get-global <appender> >>stdout
225 out-path get-global utf8 file-contents
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
232 [ "IN: scratchpad " ] [
233 console-vm-path "-run=listener" 2array
234 ascii [ "USE: system 0 exit" print flush lines last ] with-process-stream
238 console-vm-path "-run=listener" 2array
239 ascii [ "USE: system 0 exit" print ] with-process-writer
244 console-vm-path "-run=listener" 2array >>command
245 "vocab:io/launcher/windows/test/input.txt" >>stdin
250 [ "asdfdontexistplzplz" >process wait-for-success ]
254 [ process>> process? ]
255 [ process>> command>> "asdfdontexistplzplz" = ]
256 [ process>> status>> f = ]