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