]> gitweb.factorcode.org Git - factor.git/blob - basis/io/launcher/windows/nt/nt-tests.factor
c97c411d2cbef4bb48ffa55262ccb2af031c7b07
[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 [
27     <process>
28         "notepad" >>command
29         1/2 seconds >>timeout
30     try-process
31 ] must-fail
32
33 [
34     <process>
35         "notepad" >>command
36         1/2 seconds >>timeout
37     try-output-process
38 ] must-fail
39
40 : console-vm ( -- path )
41     vm ".exe" ?tail [ ".com" append ] when ;
42
43 [ ] [
44     <process>
45         console-vm "-quiet" "-run=hello-world" 3array >>command
46         "out.txt" temp-file >>stdout
47     try-process
48 ] unit-test
49
50 [ "Hello world" ] [
51     "out.txt" temp-file ascii file-lines first
52 ] unit-test
53
54 [ "( scratchpad ) " ] [
55     <process>
56         console-vm "-run=listener" 2array >>command
57         +closed+ >>stdin
58         +stdout+ >>stderr
59     ascii [ lines last ] with-process-reader
60 ] unit-test
61
62 : launcher-test-path ( -- str )
63     "resource:basis/io/launcher/windows/nt/test" ;
64
65 [ ] [
66     launcher-test-path [
67         <process>
68             console-vm "-script" "stderr.factor" 3array >>command
69             "out.txt" temp-file >>stdout
70             "err.txt" temp-file >>stderr
71         try-process
72     ] with-directory
73 ] unit-test
74
75 [ "output" ] [
76     "out.txt" temp-file ascii file-lines first
77 ] unit-test
78
79 [ "error" ] [
80     "err.txt" temp-file ascii file-lines first
81 ] unit-test
82
83 [ ] [
84     launcher-test-path [
85         <process>
86             console-vm "-script" "stderr.factor" 3array >>command
87             "out.txt" temp-file >>stdout
88             +stdout+ >>stderr
89         try-process
90     ] with-directory
91 ] unit-test
92
93 [ "outputerror" ] [
94     "out.txt" temp-file ascii file-lines first
95 ] unit-test
96
97 [ "output" ] [
98     launcher-test-path [
99         <process>
100             console-vm "-script" "stderr.factor" 3array >>command
101             "err2.txt" temp-file >>stderr
102         ascii <process-reader> stream-lines first
103     ] with-directory
104 ] unit-test
105
106 [ "error" ] [
107     "err2.txt" temp-file ascii file-lines first
108 ] unit-test
109
110 [ t ] [
111     launcher-test-path [
112         <process>
113             console-vm "-script" "env.factor" 3array >>command
114         ascii <process-reader> stream-contents
115     ] with-directory eval( -- alist )
116
117     os-envs =
118 ] unit-test
119
120 [ t ] [
121     launcher-test-path [
122         <process>
123             console-vm "-script" "env.factor" 3array >>command
124             +replace-environment+ >>environment-mode
125             os-envs >>environment
126         ascii <process-reader> stream-contents
127     ] with-directory eval( -- alist )
128     
129     os-envs =
130 ] unit-test
131
132 [ "B" ] [
133     launcher-test-path [
134         <process>
135             console-vm "-script" "env.factor" 3array >>command
136             { { "A" "B" } } >>environment
137         ascii <process-reader> stream-contents
138     ] with-directory eval( -- alist )
139
140     "A" swap at
141 ] unit-test
142
143 [ f ] [
144     launcher-test-path [
145         <process>
146             console-vm "-script" "env.factor" 3array >>command
147             { { "USERPROFILE" "XXX" } } >>environment
148             +prepend-environment+ >>environment-mode
149         ascii <process-reader> stream-contents
150     ] with-directory eval( -- alist )
151
152     "USERPROFILE" swap at "XXX" =
153 ] unit-test
154
155 2 [
156     [ ] [
157         <process>
158             "cmd.exe /c dir" >>command
159             "dir.txt" temp-file >>stdout
160         try-process
161     ] unit-test
162
163     [ ] [ "dir.txt" temp-file delete-file ] unit-test
164 ] times
165
166 [ "append-test" temp-file delete-file ] ignore-errors
167
168 [ "Hello appender\r\nHello appender\r\n" ] [
169     2 [
170         launcher-test-path [
171             <process>
172                 console-vm "-script" "append.factor" 3array >>command
173                 "append-test" temp-file <appender> >>stdout
174             try-process
175         ] with-directory
176     ] times
177    
178     "append-test" temp-file ascii file-contents
179 ] unit-test
180
181 [ "( scratchpad ) " ] [
182     console-vm "-run=listener" 2array
183     ascii [ "USE: system 0 exit" print flush lines last ] with-process-stream
184 ] unit-test
185
186 [ ] [
187     console-vm "-run=listener" 2array
188     ascii [ "USE: system 0 exit" print ] with-process-writer
189 ] unit-test
190
191 [ ] [
192     <process>
193     console-vm "-run=listener" 2array >>command
194     "vocab:io/launcher/windows/nt/test/input.txt" >>stdin
195     try-process
196 ] unit-test