RegressionTests__JavaScriptTests.st
changeset 731 4ece34c0805e
parent 700 ea80598f6402
child 732 450ab2d5cf8c
--- a/RegressionTests__JavaScriptTests.st	Wed Oct 31 17:37:13 2012 +0100
+++ b/RegressionTests__JavaScriptTests.st	Wed Oct 31 18:06:16 2012 +0100
@@ -148,12 +148,36 @@
     "Modified: / 09-10-2011 / 11:41:57 / cg"
 !
 
+outputToTranscriptOf:aBlock
+    "yes, globals are bad - that's what we need stuff like this for..."
+
+    |output|
+
+    output := '' writeStream.
+    self withTranscriptRedirectedTo:output do:aBlock.
+    ^ output contents
+!
+
 setUp
     JavaScriptCompiler isNil ifTrue:[
         Smalltalk loadPackage:'stx:libjavascript'
     ].
 
     "Created: / 09-08-2011 / 23:12:13 / cg"
+!
+
+withTranscriptRedirectedTo:aStream do:aBlock
+    "yes, globals are bad - that's what we need stuff like this for..."
+
+    |savedTranscript|
+
+    savedTranscript := Transcript.
+    [
+        Transcript := aStream.
+        aBlock value.
+    ] ensure:[
+        Transcript := savedTranscript
+    ].
 ! !
 
 !JavaScriptTests methodsFor:'tests'!
@@ -445,19 +469,24 @@
 !
 
 testDoWhile01
-    self 
-        execute:'test(arg) {
-                    var n;
-
-                    n = 1;
-                    do {
-                        Transcript.showCR(n);
-                    } while (++n <= 3);
-                    return n;
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:4
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        var n;
+
+                        n = 1;
+                        do {
+                            Transcript.showCR(n);
+                        } while (++n <= 3);
+                        return n;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:4
+    ].
+    self assert:(output asCollectionOfLinesWithReturn asArray = #( '1' '2' '3' ))
 
     "
      self run:#testDoWhile01