]> gitweb.factorcode.org Git - factor.git/blob - basis/io/launcher/windows/nt/nt-tests.factor
Merge branch 'master' into experimental
[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 ;
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         vm "-quiet" "-run=hello-world" 3array >>command
29         "out.txt" temp-file >>stdout
30     try-process
31 ] unit-test
32
33 [ "Hello world" ] [
34     "out.txt" temp-file ascii file-lines first
35 ] unit-test
36
37 [ ] [
38     <process>
39         vm "-run=listener" 2array >>command
40         +closed+ >>stdin
41     try-process
42 ] unit-test
43
44 : launcher-test-path ( -- str )
45     "resource:basis/io/launcher/windows/nt/test" ;
46
47 [ ] [
48     launcher-test-path [
49         <process>
50             vm "-script" "stderr.factor" 3array >>command
51             "out.txt" temp-file >>stdout
52             "err.txt" temp-file >>stderr
53         try-process
54     ] with-directory
55 ] unit-test
56
57 [ "output" ] [
58     "out.txt" temp-file ascii file-lines first
59 ] unit-test
60
61 [ "error" ] [
62     "err.txt" temp-file ascii file-lines first
63 ] unit-test
64
65 [ ] [
66     launcher-test-path [
67         <process>
68             vm "-script" "stderr.factor" 3array >>command
69             "out.txt" temp-file >>stdout
70             +stdout+ >>stderr
71         try-process
72     ] with-directory
73 ] unit-test
74
75 [ "outputerror" ] [
76     "out.txt" temp-file ascii file-lines first
77 ] unit-test
78
79 [ "output" ] [
80     launcher-test-path [
81         <process>
82             vm "-script" "stderr.factor" 3array >>command
83             "err2.txt" temp-file >>stderr
84         ascii <process-reader> lines first
85     ] with-directory
86 ] unit-test
87
88 [ "error" ] [
89     "err2.txt" temp-file ascii file-lines first
90 ] unit-test
91
92 [ t ] [
93     launcher-test-path [
94         <process>
95             vm "-script" "env.factor" 3array >>command
96         ascii <process-reader> contents
97     ] with-directory eval
98
99     os-envs =
100 ] unit-test
101
102 [ t ] [
103     launcher-test-path [
104         <process>
105             vm "-script" "env.factor" 3array >>command
106             +replace-environment+ >>environment-mode
107             os-envs >>environment
108         ascii <process-reader> contents
109     ] with-directory eval
110     
111     os-envs =
112 ] unit-test
113
114 [ "B" ] [
115     launcher-test-path [
116         <process>
117             vm "-script" "env.factor" 3array >>command
118             { { "A" "B" } } >>environment
119         ascii <process-reader> contents
120     ] with-directory eval
121
122     "A" swap at
123 ] unit-test
124
125 [ f ] [
126     launcher-test-path [
127         <process>
128             vm "-script" "env.factor" 3array >>command
129             { { "USERPROFILE" "XXX" } } >>environment
130             +prepend-environment+ >>environment-mode
131         ascii <process-reader> contents
132     ] with-directory eval
133
134     "USERPROFILE" swap at "XXX" =
135 ] unit-test
136
137 2 [
138     [ ] [
139         <process>
140             "cmd.exe /c dir" >>command
141             "dir.txt" temp-file >>stdout
142         try-process
143     ] unit-test
144
145     [ ] [ "dir.txt" temp-file delete-file ] unit-test
146 ] times
147
148 [ "append-test" temp-file delete-file ] ignore-errors
149
150 [ "Hello appender\r\nHello appender\r\n" ] [
151     2 [
152         launcher-test-path [
153             <process>
154                 vm "-script" "append.factor" 3array >>command
155                 "append-test" temp-file <appender> >>stdout
156             try-process
157         ] with-directory
158     ] times
159    
160     "append-test" temp-file ascii file-contents
161 ] unit-test