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