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