author | sr |
Fri, 15 Sep 2017 13:24:12 +0200 | |
changeset 1700 | 0c5fa360fd46 |
parent 1645 | da81f14033ea |
child 1704 | ca79c2585edf |
permissions | -rw-r--r-- |
1633 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1447 | 3 |
"{ Package: 'stx:goodies/regression' }" |
153 | 4 |
|
5 |
"{ NameSpace: RegressionTests }" |
|
6 |
||
7 |
TestCase subclass:#OperatingSystemTest |
|
8 |
instanceVariableNames:'' |
|
9 |
classVariableNames:'' |
|
10 |
poolDictionaries:'' |
|
1265
df1555a5fb95
class: RegressionTests::OperatingSystemTest
Claus Gittinger <cg@exept.de>
parents:
181
diff
changeset
|
11 |
category:'tests-Regression-RuntimeSystem' |
153 | 12 |
! |
13 |
||
14 |
||
1633 | 15 |
!OperatingSystemTest methodsFor:'constants'! |
16 |
||
17 |
targetFile |
|
18 |
|baseName| |
|
19 |
||
20 |
baseName := 'lsOut'. |
|
153 | 21 |
|
1633 | 22 |
OperatingSystem isMSDOSlike ifTrue:[ |
23 |
^ Filename homeDirectory "ensure write permission" / baseName |
|
24 |
]. |
|
25 |
OperatingSystem isUNIXlike ifTrue:[ |
|
26 |
^ '/tmp' asFilename / baseName |
|
27 |
]. |
|
28 |
||
29 |
self notYetImplemented |
|
153 | 30 |
! ! |
31 |
||
1633 | 32 |
!OperatingSystemTest methodsFor:'helpers'! |
33 |
||
34 |
helperActorStreamWithCommand:aCommand |
|
35 |
|targetFile expected outStr errStr exitStatus| |
|
153 | 36 |
|
1633 | 37 |
OperatingSystem isMSDOSlike ifFalse:[ |
38 |
^ self |
|
39 |
]. |
|
154 | 40 |
|
1633 | 41 |
targetFile := self targetFile. |
42 |
||
43 |
OperatingSystem executeCommand:aCommand, ' > ', targetFile pathName. |
|
44 |
expected := targetFile contentsOfEntireFile. |
|
154 | 45 |
|
46 |
outStr := ActorStream new. |
|
47 |
outStr nextPutLineBlock:[:line | Transcript normal; showCR:line ]. |
|
48 |
errStr := ActorStream new. |
|
49 |
outStr nextPutLineBlock:[:line | Transcript bold; showCR:line ]. |
|
50 |
||
51 |
OperatingSystem |
|
1633 | 52 |
executeCommand:aCommand |
53 |
inputFrom:nil |
|
54 |
outputTo:outStr |
|
55 |
errorTo:errStr |
|
56 |
inDirectory:nil |
|
57 |
lineWise:true |
|
58 |
onError:[:status | exitStatus := status]. |
|
59 |
! |
|
60 |
||
61 |
helperCommandOutput1WithCommand:aCommand |
|
62 |
|targetFile expected outStr errStr exitStatus| |
|
63 |
||
64 |
targetFile := self targetFile. |
|
65 |
||
66 |
OperatingSystem executeCommand:aCommand, ' > ', targetFile pathName. |
|
67 |
expected := targetFile contentsOfEntireFile. |
|
68 |
||
69 |
1 to:50 do:[:counter | |
|
70 |
"/ Transcript show:counter; showCR:':'. |
|
71 |
outStr := '' writeStream. |
|
72 |
errStr := '' writeStream. |
|
73 |
OperatingSystem |
|
74 |
executeCommand:aCommand |
|
75 |
inputFrom:nil |
|
76 |
outputTo:outStr |
|
77 |
errorTo:errStr |
|
78 |
onError:[:status | exitStatus := status]. |
|
79 |
self assert:(outStr contents = expected). |
|
80 |
self assert:(errStr contents isEmpty). |
|
81 |
self assert:(exitStatus isNil). |
|
82 |
]. |
|
83 |
! |
|
84 |
||
85 |
helperCommandOutput2WithCommand:aCommand |
|
86 |
|outStr errStr exitStatus| |
|
87 |
||
88 |
1 to:50 do:[:counter | |
|
89 |
"/ Transcript show:counter; showCR:':'. |
|
90 |
outStr := '' writeStream. |
|
91 |
errStr := '' writeStream. |
|
92 |
OperatingSystem |
|
93 |
executeCommand:aCommand |
|
94 |
inputFrom:nil |
|
95 |
outputTo:outStr |
|
96 |
errorTo:errStr |
|
97 |
onError:[:status | exitStatus := status]. |
|
98 |
self assert:(outStr contents isEmpty). |
|
99 |
self assert:(errStr contents notEmpty). |
|
100 |
self assert:(exitStatus success not). |
|
101 |
self assert:(exitStatus stillAlive not). |
|
102 |
self assert:(exitStatus couldNotExecute not). |
|
103 |
]. |
|
104 |
! ! |
|
105 |
||
106 |
!OperatingSystemTest methodsFor:'release'! |
|
107 |
||
108 |
tearDown |
|
109 |
self targetFile delete. |
|
110 |
! ! |
|
111 |
||
112 |
!OperatingSystemTest methodsFor:'tests'! |
|
113 |
||
1643 | 114 |
test01_environmentVariables |
115 |
|batchFile output |
|
1644 | 116 |
expected50 expected101 expected203 expected407 expected815 expected1631 expected3263 |
1645 | 117 |
expected6527| |
1643 | 118 |
|
119 |
self |
|
120 |
skipIf:(OperatingSystem isMSWINDOWSlike not) |
|
121 |
description:'This test is only for the Windows platform'. |
|
122 |
||
1644 | 123 |
"/ creates a batch file and starts another stx inside it, which retrieves a previously |
124 |
"/ set environment variable... |
|
125 |
||
1643 | 126 |
"/ reading env-var |
127 |
||
128 |
batchFile := 'test.bat' asFilename. |
|
129 |
batchFile contents:'@set FOO=hello |
|
130 |
@stx --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''FOO'') " |
|
131 |
'. |
|
132 |
||
133 |
output := |
|
134 |
String streamContents:[:out | |
|
135 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
136 |
]. |
|
137 |
||
138 |
self assert:(output = 'hello'). |
|
139 |
||
140 |
"/ reading a longer env-var (50 chars) |
|
141 |
||
142 |
batchFile := 'test.bat' asFilename. |
|
143 |
batchFile contents:'@set FOO=12345678901234567890123456789012345678901234567890 |
|
144 |
@stx --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''FOO'') " |
|
145 |
'. |
|
146 |
||
147 |
output := |
|
148 |
String streamContents:[:out | |
|
149 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
150 |
]. |
|
151 |
||
152 |
self assert:(output = '12345678901234567890123456789012345678901234567890'). |
|
153 |
||
154 |
"/ reading a longer env-var (1631 chars) |
|
155 |
||
156 |
batchFile := 'test.bat' asFilename. |
|
157 |
batchFile contents:'@set V50=12345678901234567890123456789012345678901234567890 |
|
158 |
@set V101=%V50%;%V50% |
|
159 |
@set V203=%V101%;%V101% |
|
160 |
@set V407=%V203%;%V203% |
|
161 |
@set V815=%V407%;%V407% |
|
162 |
@set V1631=%V815%;%V815% |
|
163 |
@stx --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''V1631'') " |
|
164 |
'. |
|
165 |
||
166 |
output := |
|
167 |
String streamContents:[:out | |
|
168 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
169 |
]. |
|
170 |
||
171 |
expected50 := '12345678901234567890123456789012345678901234567890'. |
|
172 |
expected101 := expected50,';',expected50. |
|
173 |
expected203 := expected101,';',expected101. |
|
174 |
expected407 := expected203,';',expected203. |
|
175 |
expected815 := expected407,';',expected407. |
|
176 |
expected1631 := expected815,';',expected815. |
|
177 |
||
178 |
self assert:(output = expected1631). |
|
179 |
||
1644 | 180 |
"/ reading a longer env-var (3263 chars) |
1643 | 181 |
|
182 |
batchFile := 'test.bat' asFilename. |
|
183 |
batchFile contents:'@set V50=12345678901234567890123456789012345678901234567890 |
|
184 |
@set V101=%V50%;%V50% |
|
185 |
@set V203=%V101%;%V101% |
|
186 |
@set V407=%V203%;%V203% |
|
187 |
@set V815=%V407%;%V407% |
|
188 |
@set V1631=%V815%;%V815% |
|
189 |
@set V3263=%V1631%;%V1631% |
|
190 |
@stx --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''V3263'') " |
|
191 |
'. |
|
192 |
||
193 |
output := |
|
194 |
String streamContents:[:out | |
|
195 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
196 |
]. |
|
197 |
||
198 |
expected50 := '12345678901234567890123456789012345678901234567890'. |
|
199 |
expected101 := expected50,';',expected50. |
|
200 |
expected203 := expected101,';',expected101. |
|
201 |
expected407 := expected203,';',expected203. |
|
202 |
expected815 := expected407,';',expected407. |
|
203 |
expected1631 := expected815,';',expected815. |
|
204 |
expected3263 := expected1631,';',expected1631. |
|
205 |
||
206 |
self assert:(output = expected3263). |
|
207 |
||
1644 | 208 |
"/ reading a very long env-var (3263 chars) |
209 |
||
210 |
batchFile := 'test.bat' asFilename. |
|
211 |
batchFile contents:'@set V50=12345678901234567890123456789012345678901234567890 |
|
212 |
@set V101=%V50%;%V50% |
|
213 |
@set V203=%V101%;%V101% |
|
214 |
@set V407=%V203%;%V203% |
|
215 |
@set V815=%V407%;%V407% |
|
216 |
@set V1631=%V815%;%V815% |
|
217 |
@set V3263=%V1631%;%V1631% |
|
218 |
@set V6527=%V3263%;%V3263% |
|
1645 | 219 |
@stx --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''V6527'') " |
1644 | 220 |
'. |
221 |
||
222 |
output := |
|
223 |
String streamContents:[:out | |
|
224 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
225 |
]. |
|
226 |
||
227 |
expected50 := '12345678901234567890123456789012345678901234567890'. |
|
228 |
expected101 := expected50,';',expected50. |
|
229 |
expected203 := expected101,';',expected101. |
|
230 |
expected407 := expected203,';',expected203. |
|
231 |
expected815 := expected407,';',expected407. |
|
232 |
expected1631 := expected815,';',expected815. |
|
233 |
expected3263 := expected1631,';',expected1631. |
|
234 |
expected6527 := expected3263,';',expected3263. |
|
235 |
||
1645 | 236 |
self assert:(output = expected6527). |
1644 | 237 |
|
1643 | 238 |
" |
239 |
self new test01_environmentVariables |
|
240 |
" |
|
241 |
! |
|
242 |
||
1633 | 243 |
testActorStream |
244 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
245 |
self helperActorStreamWithCommand:'dir'. |
|
246 |
^ self |
|
247 |
]. |
|
248 |
OperatingSystem isUNIXlike ifTrue:[ |
|
249 |
self helperActorStreamWithCommand:'ls'. |
|
250 |
^ self |
|
251 |
]. |
|
252 |
||
253 |
self notYetImplemented |
|
154 | 254 |
|
255 |
" |
|
1633 | 256 |
self new testActorStream |
154 | 257 |
" |
258 |
! |
|
259 |
||
153 | 260 |
testCommandOutput1 |
1633 | 261 |
OperatingSystem isMSDOSlike ifTrue:[ |
262 |
self helperCommandOutput1WithCommand:'dir /b'. "/ /b print just filenames, because the filesize differs... |
|
263 |
^ self |
|
264 |
]. |
|
265 |
OperatingSystem isUNIXlike ifTrue:[ |
|
266 |
self helperCommandOutput1WithCommand:'ls'. |
|
267 |
^ self |
|
153 | 268 |
]. |
269 |
||
1633 | 270 |
self notYetImplemented |
271 |
||
153 | 272 |
" |
1633 | 273 |
self new testCommandOutput1 |
153 | 274 |
" |
275 |
! |
|
276 |
||
277 |
testCommandOutput2 |
|
1633 | 278 |
OperatingSystem isMSDOSlike ifTrue:[ |
279 |
self helperCommandOutput2WithCommand:'dir /fooBar'. |
|
280 |
^ self |
|
281 |
]. |
|
282 |
OperatingSystem isUNIXlike ifTrue:[ |
|
283 |
self helperCommandOutput2WithCommand:'ls /fooBar'. |
|
284 |
^ self |
|
153 | 285 |
]. |
286 |
||
1633 | 287 |
self notYetImplemented |
288 |
||
153 | 289 |
" |
1633 | 290 |
self new testCommandOutput2 |
153 | 291 |
" |
292 |
! |
|
293 |
||
294 |
testInvalidCommand |
|
295 |
|outStr errStr exitStatus| |
|
296 |
||
154 | 297 |
1 to:50 do:[:counter | |
155 | 298 |
"/ Transcript show:counter; showCR:':'. |
1639 | 299 |
outStr := '' writeStream. |
300 |
errStr := '' writeStream. |
|
301 |
OperatingSystem |
|
302 |
executeCommand:'blabla /fooBar' |
|
303 |
inputFrom:nil |
|
304 |
outputTo:outStr |
|
305 |
errorTo:errStr |
|
306 |
onError:[:status | exitStatus := status]. |
|
307 |
self assert:(exitStatus success not). |
|
308 |
self assert:(exitStatus stillAlive not). |
|
309 |
"/ couldNotExecute could not be detected in Windows, since cmd.exe does not return the status |
|
310 |
self assert:(OperatingSystem isMSWINDOWSlike or:[exitStatus couldNotExecute]). |
|
311 |
self assert:(outStr contents isEmpty). |
|
312 |
self assert:(errStr contents notEmpty). |
|
153 | 313 |
]. |
314 |
||
315 |
" |
|
316 |
self new testInvalidCommand |
|
317 |
" |
|
318 |
! ! |
|
319 |
||
320 |
!OperatingSystemTest class methodsFor:'documentation'! |
|
321 |
||
322 |
version |
|
323 |
^ '$Header$' |
|
1351 | 324 |
! |
325 |
||
326 |
version_CVS |
|
327 |
^ '$Header$' |
|
153 | 328 |
! ! |
1265
df1555a5fb95
class: RegressionTests::OperatingSystemTest
Claus Gittinger <cg@exept.de>
parents:
181
diff
changeset
|
329 |