[svn:parrot] r47449 - in trunk/t: dynoplibs pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Tue Jun 8 05:21:11 UTC 2010


Author: plobsing
Date: Tue Jun  8 05:21:10 2010
New Revision: 47449
URL: https://trac.parrot.org/parrot/changeset/47449

Log:
move io tests away from dynops and PASM towards methods and PIR

Modified:
   trunk/t/dynoplibs/io.t
   trunk/t/pmc/io.t

Modified: trunk/t/dynoplibs/io.t
==============================================================================
--- trunk/t/dynoplibs/io.t	Tue Jun  8 04:27:57 2010	(r47448)
+++ trunk/t/dynoplibs/io.t	Tue Jun  8 05:21:10 2010	(r47449)
@@ -16,7 +16,7 @@
 
 =cut
 
-.const int TESTS = 10
+.const int TESTS = 11
 
 .loadlib 'io_ops'
 
@@ -31,6 +31,7 @@
     open_null_mode()
     open_pipe_for_reading()
     getfd_fdopen()
+    printerr_tests()
 
     # must come after (these don't use test_more)
     open_pipe_for_writing()
@@ -158,7 +159,7 @@
     pipe = open command, 'wp'
     unless pipe goto open_pipe_for_writing_failed
 
-    pipe.'puts'("ok 7 - open pipe for writing\n")
+    pipe.'puts'("ok 8 - open pipe for writing\n")
     close pipe
     .return ()
 
@@ -202,7 +203,7 @@
     print "not "
 
 _readline_handler:
-        print "ok 8\n"
+        print "ok 9\n"
         pop_eh
 
     push_eh _read_handler
@@ -210,7 +211,7 @@
     print "not "
 
 _read_handler:
-        print "ok 9\n"
+        print "ok 10\n"
         pop_eh
 
     push_eh _print_handler
@@ -218,10 +219,40 @@
     print "not "
 
 _print_handler:
-        print "ok 10\n"
+        print "ok 11\n"
         pop_eh
 .end
 
+.sub 'printerr_tests'
+    # temporarily capture stderr
+    $P0 = getstderr
+    $P1 = new ['StringHandle']
+    $S0 = null
+    $P1.'open'($S0, 'w')
+    setstderr $P1
+
+    $P2 = new ['String']
+    $P2 = "This is a test\n"
+    printerr 10
+    printerr "\n"
+    printerr 1.0
+    printerr "\n"
+    printerr "foo"
+    printerr "\n"
+    printerr $P2
+
+    # restore stderr
+    setstderr $P0
+    
+    $S0 = $P1.'readall'()
+    is($S0, <<'OUTPUT', 'printerr opcode')
+10
+1
+foo
+This is a test
+OUTPUT
+.end
+
 .namespace ["Testing"]
 
 .sub open :method

Modified: trunk/t/pmc/io.t
==============================================================================
--- trunk/t/pmc/io.t	Tue Jun  8 04:27:57 2010	(r47448)
+++ trunk/t/pmc/io.t	Tue Jun  8 05:21:10 2010	(r47449)
@@ -191,43 +191,47 @@
 close $FOO;
 
 # write to file opened for reading
-pasm_output_is( <<"CODE", <<'OUTPUT', "3-arg open" );
-.loadlib 'io_ops'
-   open P1, "$temp_file", 'w'
-   print P1, "Foobar\\n"
-   close P1
-
-   push_eh _print_to_read_only
-
-   open P2, "$temp_file", 'r'
-   print P2, "baz\\n"
-   say "skipped"
-
-_print_to_read_only:
-   say "caught writing to file opened for reading"
-   pop_eh
-
-   close P2
-
-   open P3, "$temp_file", 'r'
-   readline S1, P3
-   close P3
-   print S1
+pir_output_is( sprintf(<<'CODE', $temp_file), <<'OUTPUT', "3-arg open" );
+.const string temp_file = '%s'
+.sub 'main' :main
+    $P1 = new ['FileHandle']
+    $P1.'open'(temp_file, 'w')
+    $P1.'print'("Foobar\n")
+    $P1.'close'()
 
+    push_eh _print_to_read_only
 
-   end
+    $P2 = new ['FileHandle']
+    $P2.'open'(temp_file, 'r')
+    $P2.'print'("baz\n")
+    say "skipped"
+
+  _print_to_read_only:
+    say "caught writing to file opened for reading"
+    pop_eh
+
+    $P2.'close'()
+
+    $P3 = new ['FileHandle']
+    $P3.'open'(temp_file, 'r')
+    $S1 = $P3.'readline'()
+    $P3.'close'()
+    print $S1
+.end
 CODE
 caught writing to file opened for reading
 Foobar
 OUTPUT
 
-pasm_output_is( <<"CODE", <<'OUTPUT', 'open and close' );
-.loadlib 'io_ops'
-   open P1, "$temp_file", "w"
-   print P1, "Hello, World!\\n"
-   close P1
-   say "done"
-   end
+pir_output_is( sprintf(<<'CODE', $temp_file), <<'OUTPUT', 'open and close' );
+.const string temp_file = '%s'
+.sub 'main' :main
+    $P1 = new ['FileHandle']
+    $P1.'open'(temp_file, "w")
+    $P1.'print'("Hello, World!\n")
+    $P1.'close'()
+    say "done"
+.end
 CODE
 done
 OUTPUT
@@ -236,12 +240,14 @@
 Hello, World!
 OUTPUT
 
-pasm_output_is( <<"CODE", '', 'append' );
-.loadlib 'io_ops'
-   open P1, "$temp_file", 'wa'
-   print P1, "Parrot flies\\n"
-   close P1
-   end
+pir_output_is( sprintf(<<'CODE', $temp_file), '', 'append' );
+.const string temp_file = '%s'
+.sub 'main' :main
+    $P1 = new ['FileHandle']
+    $P1.'open'(temp_file, 'wa')
+    $P1.'print'("Parrot flies\n")
+    $P1.'close'()
+.end
 CODE
 
 file_content_is( $temp_file, <<'OUTPUT', 'append file contents' );
@@ -249,12 +255,14 @@
 Parrot flies
 OUTPUT
 
-pasm_output_is( <<"CODE", '', 'write to file' );
-.loadlib 'io_ops'
-   open P1, "$temp_file", 'w'
-   print P1, "Parrot overwrites\\n"
-   close P1
-   end
+pir_output_is( sprintf(<<'CODE', $temp_file), '', 'write to file' );
+.const string temp_file = '%s'
+.sub 'main' :main
+    $P1 = new ['FileHandle']
+    $P1.'open'(temp_file, 'w')
+    $P1.'print'("Parrot overwrites\n")
+    $P1.'close'()
+.end
 CODE
 
 file_content_is( $temp_file, <<'OUTPUT', 'file contents' );


More information about the parrot-commits mailing list