redirect and check output (Stdout)
authorClaus Gittinger <cg@exept.de>
Wed, 31 Oct 2012 20:26:02 +0100
changeset 732 450ab2d5cf8c
parent 731 4ece34c0805e
child 733 0d9c441eba61
redirect and check output (Stdout) unfinished
RegressionTests__JavaScriptTests.st
--- a/RegressionTests__JavaScriptTests.st	Wed Oct 31 18:06:16 2012 +0100
+++ b/RegressionTests__JavaScriptTests.st	Wed Oct 31 20:26:02 2012 +0100
@@ -495,20 +495,25 @@
 !
 
 testDoWhile02
-    self 
-        execute:'test(arg) {
-                    var n;
-
-                    n = 1;
-                    do {
-                        Transcript.showCR(n);
-                        break;
-                    } while (true);
-                    return n;
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:1
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        var n;
+
+                        n = 1;
+                        do {
+                            Transcript.showCR(n);
+                            break;
+                        } while (true);
+                        return n;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:1
+    ].
+    self assert:(output asCollectionOfLinesWithReturn asArray = #( '1' ))
 
     "
      self run:#testDoWhile02
@@ -517,20 +522,25 @@
 !
 
 testDoWhile03
-    self 
-        execute:'test(arg) {
-                    var n;
-
-                    n = 1;
-                    do {
-                        break;
-                        Transcript.showCR(n);
-                    } while (true);
-                    return n;
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:1
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        var n;
+
+                        n = 1;
+                        do {
+                            break;
+                            Transcript.showCR(n);
+                        } while (true);
+                        return n;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:1
+    ].
+    self assert:(output asCollectionOfLinesWithReturn asArray = #(  ))
 
     "
      self run:#testDoWhile03
@@ -539,20 +549,25 @@
 !
 
 testDoWhile04
-    self 
-        execute:'test(arg) {
-                    var n;
-
-                    n = 1;
-                    do {
-                        if (++n == 3) continue;
-                        Transcript.showCR(n);
-                    } while (n <= 4);
-                    return n;
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:5
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        var n;
+
+                        n = 1;
+                        do {
+                            if (++n == 3) continue;
+                            Transcript.showCR(n);
+                        } while (n <= 4);
+                        return n;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:5
+    ].
+    self assert:(output asCollectionOfLinesWithReturn asArray = #( '2' '4' '5' ))
 
     "
      self run:#testDoWhile04
@@ -561,20 +576,25 @@
 !
 
 testDoWhile05
-    self 
-        execute:'test(arg) {
-                    var n;
-
-                    n = 1;
-                    do {
-                        if (++n == 3) break;
-                        Transcript.showCR(n);
-                    } while (n <= 4);
-                    return n;
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:3
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        var n;
+
+                        n = 1;
+                        do {
+                            if (++n == 3) break;
+                            Transcript.showCR(n);
+                        } while (n <= 4);
+                        return n;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:3
+    ].
+    self assert:(output asCollectionOfLinesWithReturn asArray = #( '2' ))
 
     "
      self run:#testDoWhile05
@@ -643,18 +663,33 @@
 !
 
 testFor01
-    self 
-        execute:'test(arg) {
-                    var n;
-
-                    for (n = 0; n < 10; n++) {
-                        Transcript.show("hello ");
-                        Transcript.showCR(n);
-                    }
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:nil
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        var n;
+
+                        for (n = 0; n < 10; n++) {
+                            Transcript.show("hello ");
+                            Transcript.showCR(n);
+                        }
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:nil
+    ].
+    self assert:(output asCollectionOfLinesWithReturn asArray = #( 
+        'hello 0'
+        'hello 1'
+        'hello 2'
+        'hello 3'
+        'hello 4'
+        'hello 5'
+        'hello 6'
+        'hello 7'
+        'hello 8'
+        'hello 9' ))
 
     "
      self run:#testFor01
@@ -889,6 +924,9 @@
 !
 
 testFor05c
+    |output|
+
+    output := '' writeStream.
     self 
         execute:'test(arg, out) {
                     var n = 0;
@@ -900,9 +938,15 @@
                     }
                  }'
         for:nil
-        arguments:(Array with:4 with:Transcript)
+        arguments:(Array with:4 with:output)
         expect:nil.
 
+    self assert:(output contents asCollectionOfLinesWithReturn asArray = #( 
+        'hello 0'
+        'hello 1'
+        'hello 2'
+        'hello 3'))
+
     "
      self run:#testFor05c
      self new testFor05c  
@@ -910,6 +954,9 @@
 !
 
 testFor05d
+    |output|
+
+    output := '' writeStream.
     self 
         execute:'test(arg, out) {
                     var n = 0;
@@ -923,9 +970,14 @@
                     }
                  }'
         for:nil
-        arguments:(Array with:5 with:Transcript)
+        arguments:(Array with:5 with:output)
         expect:nil.
 
+    self assert:(output contents asCollectionOfLinesWithReturn asArray = #( 
+        'hello 1'
+        'hello 3'
+        'hello 4' ))
+
     "
      self run:#testFor05d
      self new testFor05d  
@@ -933,17 +985,33 @@
 !
 
 testFor06
-    self 
-        execute:'test(arg) {
+    |output|
+
+    output := '' writeStream.
+    self 
+        execute:'test(arg, out) {
                     for (var n = 0, var m = 10; n < 10; n++, m--) {
-                        Transcript.show(n);
-                        Transcript.show(" -> ");
-                        Transcript.showCR(m);
+                        out.show(n);
+                        out.show(" -> ");
+                        out.showCR(m);
                     }
                  }'
         for:nil
-        arguments:#(5)
-        expect:nil
+        arguments:(Array with:5 with:output)
+        expect:nil.
+
+    self assert:(output contents asCollectionOfLinesWithReturn asArray = #( 
+        '0 -> 10'
+        '1 -> 9'
+        '2 -> 8'
+        '3 -> 7'
+        '4 -> 6'
+        '5 -> 5'
+        '6 -> 4'
+        '7 -> 3'
+        '8 -> 2'
+        '9 -> 1'
+       ))
 
     "
      self run:#testFor06
@@ -3083,19 +3151,24 @@
 !
 
 testPrint
-    self 
-        execute:'
-                  testPrint() {
-                      print("1 ");
-                      print("2 ");
-                      print("3 ");
-                      println("4");
-                      return null;
-                  }
-                 '
-        for:JavaScriptEnvironment new
-        arguments:#(  )
-        expect:nil
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'
+                      testPrint() {
+                          print("1 ");
+                          print("2 ");
+                          print("3 ");
+                          println("4");
+                          return null;
+                      }
+                     '
+            for:JavaScriptEnvironment new
+            arguments:#(  )
+            expect:nil.
+    ].
+    self assert:(output = '1 2 3 4\' withCRs).
 
     "
      self run:#testPrint
@@ -3680,20 +3753,25 @@
 !
 
 testSwitch04
-    self 
-        execute:'test(arg) {
-                    switch (arg) {
-                    default:
-                        Transcript.show("hello ");
-                        Transcript.show("world ");
-                        Transcript.cr();
-                        return 1;
-                    }
-                    return 0;
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:1
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        switch (arg) {
+                        default:
+                            Transcript.show("hello ");
+                            Transcript.show("world ");
+                            Transcript.cr();
+                            return 1;
+                        }
+                        return 0;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:1
+    ].
+    self assert:(output = 'hello world \' withCRs).
 
     "
      self run:#testSwitch04
@@ -3702,20 +3780,25 @@
 !
 
 testSwitch05
-    self 
-        execute:'test(arg) {
-                    switch (arg) {
-                    default:
-                        Transcript.show("hello ");
-                        Transcript.show("world ");
-                        return 1;
-                        Transcript.cr();
-                    }
-                    return 0;
-                 }'
-        for:nil
-        arguments:#(5)
-        expect:1
+    |output|
+
+    output := self outputToTranscriptOf:[
+        self 
+            execute:'test(arg) {
+                        switch (arg) {
+                        default:
+                            Transcript.show("hello ");
+                            Transcript.show("world ");
+                            return 1;
+                            Transcript.cr();
+                        }
+                        return 0;
+                     }'
+            for:nil
+            arguments:#(5)
+            expect:1
+    ].
+    self assert:(output = 'hello world ').
 
     "
      self run:#testSwitch05