author | sr |
Wed, 18 Oct 2017 15:00:54 +0200 | |
changeset 1884 | ad279a6d791d |
parent 1814 | bc52c5aca9b5 |
child 2160 | f2b59e219ee5 |
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 |
1704 | 115 |
|cr content batchFile output |
1644 | 116 |
expected50 expected101 expected203 expected407 expected815 expected1631 expected3263 |
1814 | 117 |
expected6527 pathOfSTXExecutable| |
118 |
||
119 |
pathOfSTXExecutable := OperatingSystem pathOfSTXExecutable. |
|
120 |
(pathOfSTXExecutable endsWith:'stx.com') ifFalse:[ |
|
121 |
"we are started by /stx/goodies/builder/quickSelfTest/quickSelfTest.com |
|
122 |
but do need stx.com" |
|
123 |
pathOfSTXExecutable := '../../../projects/smalltalk/stx.com' |
|
124 |
]. |
|
1643 | 125 |
|
126 |
self |
|
127 |
skipIf:(OperatingSystem isMSWINDOWSlike not) |
|
128 |
description:'This test is only for the Windows platform'. |
|
129 |
||
1814 | 130 |
cr := Character cr asString. |
131 |
||
1644 | 132 |
"/ creates a batch file and starts another stx inside it, which retrieves a previously |
133 |
"/ set environment variable... |
|
1643 | 134 |
"/ reading env-var |
1814 | 135 |
content := |
136 |
'@set FOO=hello', cr, |
|
137 |
('@"%1" --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''FOO'') "' |
|
138 |
bindWith:pathOfSTXExecutable). |
|
139 |
||
1643 | 140 |
batchFile := 'test.bat' asFilename. |
1704 | 141 |
batchFile contents:content. |
1643 | 142 |
|
143 |
output := |
|
144 |
String streamContents:[:out | |
|
145 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
146 |
]. |
|
147 |
||
148 |
self assert:(output = 'hello'). |
|
149 |
||
1814 | 150 |
|
1643 | 151 |
"/ reading a longer env-var (50 chars) |
1814 | 152 |
content := |
153 |
'@set FOO=12345678901234567890123456789012345678901234567890', cr, |
|
154 |
('@"%1" --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''FOO'') "' |
|
155 |
bindWith:pathOfSTXExecutable). |
|
156 |
||
1643 | 157 |
batchFile := 'test.bat' asFilename. |
1704 | 158 |
batchFile contents:content. |
1814 | 159 |
|
1643 | 160 |
output := |
161 |
String streamContents:[:out | |
|
162 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
163 |
]. |
|
164 |
||
165 |
self assert:(output = '12345678901234567890123456789012345678901234567890'). |
|
166 |
||
1814 | 167 |
|
1643 | 168 |
"/ reading a longer env-var (1631 chars) |
1814 | 169 |
content := |
170 |
'@set V50=12345678901234567890123456789012345678901234567890', cr, |
|
171 |
'@set V101=%V50%;%V50%', cr, |
|
172 |
'@set V203=%V101%;%V101%', cr, |
|
173 |
'@set V407=%V203%;%V203%', cr, |
|
174 |
'@set V815=%V407%;%V407%', cr, |
|
175 |
'@set V1631=%V815%;%V815%', cr, |
|
176 |
('@"%1" --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''V1631'') "' |
|
177 |
bindWith:pathOfSTXExecutable). |
|
1643 | 178 |
|
179 |
batchFile := 'test.bat' asFilename. |
|
1704 | 180 |
batchFile contents:content. |
1814 | 181 |
|
1643 | 182 |
output := |
183 |
String streamContents:[:out | |
|
184 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
185 |
]. |
|
186 |
||
187 |
expected50 := '12345678901234567890123456789012345678901234567890'. |
|
188 |
expected101 := expected50,';',expected50. |
|
189 |
expected203 := expected101,';',expected101. |
|
190 |
expected407 := expected203,';',expected203. |
|
191 |
expected815 := expected407,';',expected407. |
|
192 |
expected1631 := expected815,';',expected815. |
|
193 |
||
194 |
self assert:(output = expected1631). |
|
195 |
||
1814 | 196 |
|
1644 | 197 |
"/ reading a longer env-var (3263 chars) |
1814 | 198 |
content := |
199 |
'@set V50=12345678901234567890123456789012345678901234567890', cr, |
|
200 |
'@set V101=%V50%;%V50%', cr, |
|
201 |
'@set V203=%V101%;%V101%', cr, |
|
202 |
'@set V407=%V203%;%V203%', cr, |
|
203 |
'@set V815=%V407%;%V407%', cr, |
|
204 |
'@set V1631=%V815%;%V815%', cr, |
|
205 |
'@set V3263=%V1631%;%V1631%', cr, |
|
206 |
('@"%1" --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''V3263'') "' |
|
207 |
bindWith:pathOfSTXExecutable). |
|
208 |
||
1643 | 209 |
batchFile := 'test.bat' asFilename. |
1704 | 210 |
batchFile contents:content. |
1643 | 211 |
|
212 |
output := |
|
213 |
String streamContents:[:out | |
|
214 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
215 |
]. |
|
216 |
||
217 |
expected50 := '12345678901234567890123456789012345678901234567890'. |
|
218 |
expected101 := expected50,';',expected50. |
|
219 |
expected203 := expected101,';',expected101. |
|
220 |
expected407 := expected203,';',expected203. |
|
221 |
expected815 := expected407,';',expected407. |
|
222 |
expected1631 := expected815,';',expected815. |
|
223 |
expected3263 := expected1631,';',expected1631. |
|
224 |
||
225 |
self assert:(output = expected3263). |
|
226 |
||
1814 | 227 |
|
1704 | 228 |
"/ reading a very long env-var (6527 chars) |
1814 | 229 |
content := |
230 |
'@set V50=12345678901234567890123456789012345678901234567890', cr, |
|
231 |
'@set V101=%V50%;%V50%', cr, |
|
232 |
'@set V203=%V101%;%V101%', cr, |
|
233 |
'@set V407=%V203%;%V203%', cr, |
|
234 |
'@set V815=%V407%;%V407%', cr, |
|
235 |
'@set V1631=%V815%;%V815%', cr, |
|
236 |
'@set V3263=%V1631%;%V1631%', cr, |
|
237 |
'@set V6527=%V3263%;%V3263%', cr, |
|
238 |
('@"%1" --eval "Stdout nextPutAll:(OperatingSystem getEnvironment:''V6527'') "' |
|
239 |
bindWith:pathOfSTXExecutable). |
|
1644 | 240 |
|
241 |
batchFile := 'test.bat' asFilename. |
|
1704 | 242 |
batchFile contents:content. |
1644 | 243 |
|
244 |
output := |
|
245 |
String streamContents:[:out | |
|
246 |
OperatingSystem executeCommand:'test.bat' outputTo:out. |
|
247 |
]. |
|
248 |
||
249 |
expected50 := '12345678901234567890123456789012345678901234567890'. |
|
250 |
expected101 := expected50,';',expected50. |
|
251 |
expected203 := expected101,';',expected101. |
|
252 |
expected407 := expected203,';',expected203. |
|
253 |
expected815 := expected407,';',expected407. |
|
254 |
expected1631 := expected815,';',expected815. |
|
255 |
expected3263 := expected1631,';',expected1631. |
|
256 |
expected6527 := expected3263,';',expected3263. |
|
257 |
||
1645 | 258 |
self assert:(output = expected6527). |
1644 | 259 |
|
1643 | 260 |
" |
261 |
self new test01_environmentVariables |
|
262 |
" |
|
263 |
! |
|
264 |
||
1633 | 265 |
testActorStream |
266 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
267 |
self helperActorStreamWithCommand:'dir'. |
|
268 |
^ self |
|
269 |
]. |
|
270 |
OperatingSystem isUNIXlike ifTrue:[ |
|
271 |
self helperActorStreamWithCommand:'ls'. |
|
272 |
^ self |
|
273 |
]. |
|
274 |
||
275 |
self notYetImplemented |
|
154 | 276 |
|
277 |
" |
|
1633 | 278 |
self new testActorStream |
154 | 279 |
" |
280 |
! |
|
281 |
||
153 | 282 |
testCommandOutput1 |
1633 | 283 |
OperatingSystem isMSDOSlike ifTrue:[ |
284 |
self helperCommandOutput1WithCommand:'dir /b'. "/ /b print just filenames, because the filesize differs... |
|
285 |
^ self |
|
286 |
]. |
|
287 |
OperatingSystem isUNIXlike ifTrue:[ |
|
288 |
self helperCommandOutput1WithCommand:'ls'. |
|
289 |
^ self |
|
153 | 290 |
]. |
291 |
||
1633 | 292 |
self notYetImplemented |
293 |
||
153 | 294 |
" |
1633 | 295 |
self new testCommandOutput1 |
153 | 296 |
" |
297 |
! |
|
298 |
||
299 |
testCommandOutput2 |
|
1633 | 300 |
OperatingSystem isMSDOSlike ifTrue:[ |
301 |
self helperCommandOutput2WithCommand:'dir /fooBar'. |
|
302 |
^ self |
|
303 |
]. |
|
304 |
OperatingSystem isUNIXlike ifTrue:[ |
|
305 |
self helperCommandOutput2WithCommand:'ls /fooBar'. |
|
306 |
^ self |
|
153 | 307 |
]. |
308 |
||
1633 | 309 |
self notYetImplemented |
310 |
||
153 | 311 |
" |
1633 | 312 |
self new testCommandOutput2 |
153 | 313 |
" |
314 |
! |
|
315 |
||
316 |
testInvalidCommand |
|
317 |
|outStr errStr exitStatus| |
|
318 |
||
154 | 319 |
1 to:50 do:[:counter | |
155 | 320 |
"/ Transcript show:counter; showCR:':'. |
1639 | 321 |
outStr := '' writeStream. |
322 |
errStr := '' writeStream. |
|
323 |
OperatingSystem |
|
324 |
executeCommand:'blabla /fooBar' |
|
325 |
inputFrom:nil |
|
326 |
outputTo:outStr |
|
327 |
errorTo:errStr |
|
328 |
onError:[:status | exitStatus := status]. |
|
329 |
self assert:(exitStatus success not). |
|
330 |
self assert:(exitStatus stillAlive not). |
|
331 |
"/ couldNotExecute could not be detected in Windows, since cmd.exe does not return the status |
|
332 |
self assert:(OperatingSystem isMSWINDOWSlike or:[exitStatus couldNotExecute]). |
|
333 |
self assert:(outStr contents isEmpty). |
|
334 |
self assert:(errStr contents notEmpty). |
|
153 | 335 |
]. |
336 |
||
337 |
" |
|
338 |
self new testInvalidCommand |
|
339 |
" |
|
340 |
! ! |
|
341 |
||
342 |
!OperatingSystemTest class methodsFor:'documentation'! |
|
343 |
||
344 |
version |
|
345 |
^ '$Header$' |
|
1351 | 346 |
! |
347 |
||
348 |
version_CVS |
|
349 |
^ '$Header$' |
|
153 | 350 |
! ! |
1265
df1555a5fb95
class: RegressionTests::OperatingSystemTest
Claus Gittinger <cg@exept.de>
parents:
181
diff
changeset
|
351 |