[svn:parrot] r39804 - trunk/t/op

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Fri Jun 26 21:30:45 UTC 2009


Author: whiteknight
Date: Fri Jun 26 21:30:44 2009
New Revision: 39804
URL: https://trac.parrot.org/parrot/changeset/39804

Log:
[t] convert io.t and ifunless.t from Perl5 to PIR. Courtesy flh++. TT #793

Modified:
   trunk/t/op/ifunless.t
   trunk/t/op/io.t

Modified: trunk/t/op/ifunless.t
==============================================================================
--- trunk/t/op/ifunless.t	Fri Jun 26 21:27:18 2009	(r39803)
+++ trunk/t/op/ifunless.t	Fri Jun 26 21:30:44 2009	(r39804)
@@ -1,13 +1,7 @@
-#!perl
+#!parrot
 # Copyright (C) 2001-2005, Parrot Foundation.
 # $Id$
 
-use strict;
-use warnings;
-use lib qw( . lib ../lib ../../lib );
-use Test::More;
-use Parrot::Test tests => 6;
-
 =head1 NAME
 
 t/op/ifunless.t - If/Unless
@@ -22,181 +16,203 @@
 
 =cut
 
-pasm_output_is( <<CODE, <<OUTPUT, "if_i_ic" );
-        set     I0, 2147483647
-        set     I1, -2147483648
-        set     I2, 0
-
-        if      I0, ONE
-        branch  ERROR
-        print   "bad\\n"
-
-ONE:
-        print   "ok 1\\n"
-        if      I1, TWO
-        branch ERROR
-        print   "bad\\n"
-
-TWO:
-        print   "ok 2\\n"
-        if      I2, ERROR
-        branch  THREE
-        print   "bad\\n"
-
-THREE:
-        print   "ok 3\\n"
-        end
-
-ERROR:
-        print   "bad\\n"
-        end
-CODE
-ok 1
-ok 2
-ok 3
-OUTPUT
-
-pasm_output_is( <<CODE, <<OUTPUT, "if_n_ic" );
-        set     N0, 0.1
-        set     N1, -0.1
-        set     N2, 0.0
-
-        if N0, ONE
-        branch  ERROR
-        print   "bad\\n"
-
-ONE:
-        print   "ok 1\\n"
-        if      N1, TWO
-        branch ERROR
-        print   "bad\\n"
-
-TWO:
-        print   "ok 2\\n"
-        if      N2, ERROR
-        branch  THREE
-        print   "bad\\n"
-
-THREE:
-        print   "ok 3\\n"
-        end
-
-ERROR:
-        print   "bad\\n"
-        end
-CODE
-ok 1
-ok 2
-ok 3
-OUTPUT
-
-pasm_output_is( <<CODE, <<OUTPUT, "if_s_ic" );
-        set     S0, "Hello World"
-        set     S1, ""
-
-        if      S0, ONE
-        branch  ERROR
-        print   "bad\\n"
-
-ONE:
-        print   "ok 1\\n"
-        if      S1, ERROR
-        branch  TWO
-        print   "bad\\n"
-
-TWO:
-        print   "ok 2\\n"
-        end
-
-ERROR:
-        print   "bad\\n"
-        end
-CODE
-ok 1
-ok 2
-OUTPUT
-
-pasm_output_is( <<CODE, <<OUTPUT, "unless_i_ic" );
-        set     I0, 0
-        set     I1, -2147483648
-
-        unless  I0, ONE
-        branch  ERROR
-        print   "bad\\n"
-
-ONE:
-        print   "ok 1\\n"
-        unless  I1, ERROR
-        branch TWO
-        print   "bad\\n"
-
-TWO:
-        print   "ok 2\\n"
-        end
-
-ERROR:
-        print   "bad\\n"
-        end
-CODE
-ok 1
-ok 2
-OUTPUT
-
-pasm_output_is( <<CODE, <<OUTPUT, "unless_n_ic" );
-        set     N0, 0.0
-        set     N1, -0.1
-
-        unless N0, ONE
-        branch  ERROR
-        print   "bad\\n"
-
-ONE:
-        print   "ok 1\\n"
-        unless  N1, ERROR
-        branch TWO
-        print   "bad\\n"
-
-TWO:
-        print   "ok 2\\n"
-        end
-
-ERROR:
-        print   "bad\\n"
-        end
-CODE
-ok 1
-ok 2
-OUTPUT
-
-pasm_output_is( <<CODE, <<OUTPUT, "unless_s_ic" );
-        set     S1, "Hello World"
-        set     S0, ""
-
-        unless S0, ONE
-        branch  ERROR
-        print   "bad\\n"
-
-ONE:
-        print   "ok 1\\n"
-        unless  S1, ERROR
-        branch TWO
-        print   "bad\\n"
-
-TWO:
-        print   "ok 2\\n"
-        end
-
-ERROR:
-        print   "bad\\n"
-        end
-CODE
-ok 1
-ok 2
-OUTPUT
+.const int TESTS = 14
+
+.sub 'test' :main
+    .include 'test_more.pir'
+
+    plan(TESTS)
+
+    if_i_ic_positive()
+    if_i_ic_negative()
+    if_i_ic_zero()
+    if_n_ic_positive()
+    if_n_ic_negative()
+    if_n_ic_zero()
+    if_s_ic_helloworld()
+    if_s_ic_empty()
+
+    unless_i_ic_zero()
+    unless_i_ic_negative()
+    unless_n_ic_zero()
+    unless_n_ic_negative()
+    unless_s_ic_empty()
+    unless_s_ic_helloworld()
+
+.end
+
+.sub 'if_i_ic_positive'
+    $I0 = 2147483647
+
+    $I1 = 0
+    if $I0 goto if_i_ic_positive_ok
+    goto if_i_ic_positive_end
+
+  if_i_ic_positive_ok:
+    $I1 = 1
+  if_i_ic_positive_end:
+    ok($I1, "if_i_ic with a positive integer")
+.end
+
+.sub 'if_i_ic_negative'
+    $I0 = -2147483647
+
+    $I1 = 0
+    if $I0 goto if_i_ic_negative_ok
+    goto if_i_ic_negative_end
+
+  if_i_ic_negative_ok:
+    $I1 = 1
+  if_i_ic_negative_end:
+    ok($I1, "if_i_ic with a negative integer")
+.end
+
+.sub 'if_i_ic_zero'
+    $I0 = 0
+
+    $I1 = 0
+    if $I0 goto if_i_ic_zero_end
+    $I1 = 1
+
+  if_i_ic_zero_end:
+    ok($I1, "if_i_ic with integer zero")
+.end
+
+.sub 'if_n_ic_positive'
+    $N0 = 0.1
+
+    $I1 = 0
+    if $N0 goto if_n_ic_positive_ok
+    goto if_n_ic_positive_end
+
+  if_n_ic_positive_ok:
+    $I1 = 1
+  if_n_ic_positive_end:
+    ok($I1, "if_n_ic with a positive float")
+.end
+
+.sub 'if_n_ic_negative'
+    $N0 = -0.1
+
+    $I1 = 0
+    if $N0 goto if_n_ic_negative_ok
+    goto if_n_ic_negative_end
+
+  if_n_ic_negative_ok:
+    $I1 = 1
+  if_n_ic_negative_end:
+    ok($I1, "if_n_ic with a negative float")
+.end
+
+.sub 'if_n_ic_zero'
+    $N0 = 0.0
+
+    $I1 = 0
+    if $N0 goto if_n_ic_zero_end
+    $I1 = 1
+
+  if_n_ic_zero_end:
+    ok($I1, "if_n_ic with float zero")
+.end
+
+.sub 'if_s_ic_helloworld'
+    $S0 = "Hello World"
+
+    $I1 = 0
+    if $S0 goto if_s_ic_helloworld_ok
+    goto if_s_ic_helloworld_end
+
+  if_s_ic_helloworld_ok:
+    $I1 = 1
+  if_s_ic_helloworld_end:
+    ok($I1, "if_s_ic with a non-empty string")
+.end
+
+.sub 'if_s_ic_empty'
+    $S0 = ''
+
+    $I1 = 0
+    if $S0 goto if_s_ic_empty_end
+    $I1 = 1
+
+  if_s_ic_empty_end:
+    ok($I1, "if_n_ic with the empty string")
+.end
+
+.sub 'unless_i_ic_zero'
+    $I0 = 0
+
+    $I1 = 0
+    unless $I0 goto unless_i_ic_zero_ok
+    goto unless_i_ic_zero_end
+
+  unless_i_ic_zero_ok:
+    $I1 = 1
+  unless_i_ic_zero_end:
+    ok($I1, "unless_i_ic with integer zero")
+.end
+
+.sub 'unless_i_ic_negative'
+    $I0 = -2147483648
+
+    $I1 = 0
+    unless $I0 goto unless_i_ic_negative_end
+    $I1 = 1
+
+  unless_i_ic_negative_end:
+    ok($I1, "unless_i_ic with a negative integer")
+.end
+
+.sub 'unless_n_ic_zero'
+    $N0 = 0.0
+
+    $I1 = 0
+    unless $N0 goto unless_n_ic_zero_ok
+    goto unless_n_ic_zero_end
+
+  unless_n_ic_zero_ok:
+    $I1 = 1
+  unless_n_ic_zero_end:
+    ok($I1, "unless_n_ic with float zero")
+.end
+
+.sub 'unless_n_ic_negative'
+    $N0 = -0.1
+
+    $I1 = 0
+    unless $N0 goto unless_n_ic_negative_end
+    $I1 = 1
+
+  unless_n_ic_negative_end:
+    ok($I1, "unless_n_ic with a negative float")
+.end
+
+.sub 'unless_s_ic_empty'
+    $S0 = ''
+
+    $I1 = 0
+    unless $S0 goto unless_s_ic_empty_ok
+    goto unless_s_ic_empty_end
+
+  unless_s_ic_empty_ok:
+    $I1 = 1
+  unless_s_ic_empty_end:
+    ok($I1, "unless_s_ic with the empty string")
+.end
+
+.sub 'unless_s_ic_helloworld'
+    $S0 = "Hello World"
+
+    $I1 = 0
+    unless $S0 goto unless_s_ic_helloworld_end
+    $I1 = 1
+
+  unless_s_ic_helloworld_end:
+    ok($I1, "unless_s_ic with a non-empty string")
+.end
 
 # Local Variables:
-#   mode: cperl
-#   cperl-indent-level: 4
+#   mode: pir
 #   fill-column: 100
 # End:
-# vim: expandtab shiftwidth=4:
+# vim: expandtab shiftwidth=4 ft=pir:

Modified: trunk/t/op/io.t
==============================================================================
--- trunk/t/op/io.t	Fri Jun 26 21:27:18 2009	(r39803)
+++ trunk/t/op/io.t	Fri Jun 26 21:30:44 2009	(r39804)
@@ -1,14 +1,7 @@
-#!perl
+#!parrot
 # Copyright (C) 2008, Parrot Foundation.
 # $Id$
 
-use strict;
-use warnings;
-use lib qw( . lib ../lib ../../lib );
-
-use Test::More;
-use Parrot::Test tests => 4;
-
 =head1 NAME
 
 t/op/io.t - Testing io opcodes
@@ -23,118 +16,135 @@
 
 =cut
 
-pir_output_is( <<'CODE', <<'OUTPUT', 'open with null filename' );
-.sub main
-    push_eh failed
+.const int TESTS = 4
+
+.sub 'main' :main
+    .include 'test_more.pir'
+
+    plan(TESTS)
+
+    open_null_filename()
+    open_null_mode()
+    open_pipe_for_reading()
+    open_pipe_for_writing()
+.end
+
+.sub 'open_null_filename'
+    push_eh open_null_filename_failed
     $P0 = open $S0, '<'
-    say 'never'
-    goto finish
-failed:
-    say 'Catched'
-finish:
-.end
-CODE
-Catched
-OUTPUT
-
-pir_output_is( <<'CODE', <<'OUTPUT', 'open with null mode' );
-.sub main
-    push_eh failed
+    nok(1, 'open with null filename')
+    .return ()
+
+  open_null_filename_failed:
+    ok(1, 'open with null filename')
+.end
+
+.sub 'open_null_mode'
+    push_eh open_null_mode_failed
     $P0 = open 'some_name', $S0
-    say 'never'
-    goto finish
-failed:
-    say 'Catched'
-finish:
-.end
-CODE
-Catched
-OUTPUT
-
-TODO: {
-local $TODO = 'Unimplemented in this platform, TT #661' unless $^O =~ /linux|darwin|MSWin32/;
-
-pir_output_like( <<'CODE', <<'OUTPUT', 'open pipe for reading' );
-.include 'iglobals.pasm'
-
-.sub testreadpipe :main
-  .local pmc interp
-  interp = getinterp
-  .local pmc conf
-  conf = interp[.IGLOBALS_CONFIG_HASH]
-  .local string command
-  command = conf['build_dir']
-  .local string aux
-  aux = conf['slash']
-  command .= aux
-  aux = conf['test_prog']
-  command .= aux
-  aux = conf['exe']
-  command .= aux
-  command .= ' -V'
-
-  .local pmc pipe
-  pipe = open command, 'rp'
-  unless pipe goto failed
-  .local string line
-nextline:
-  line = readline pipe
-  print line
-  if pipe goto nextline
-  .return()
-failed:
-  say 'FAILED'
-.end
-CODE
-/This is Parrot.*/
-OUTPUT
-
-}
-
-TODO: {
-local $TODO = 'Unimplemented in this platform, TT #661' unless $^O =~ /linux|darwin|MSWin32/;
-
-pir_output_is( <<'CODE', <<'OUTPUT', 'open pipe for writing' );
-.include 'iglobals.pasm'
-
-.sub testwritepipe :main
-  .local pmc interp
-  interp = getinterp
-  .local pmc conf
-  conf = interp[.IGLOBALS_CONFIG_HASH]
-  .local string command
-  command = conf['build_dir']
-  .local string aux
-  aux = conf['slash']
-  command .= aux
-  .local string filename
-  filename .= command
-  filename .= 'examples/pasm/cat.pasm'
-  aux = conf['test_prog']
-  command .= aux
-  aux = conf['exe']
-  command .= aux
-  command .= ' '
-  command .= filename
-
-  .local pmc pipe
-  pipe = open command, 'wp'
-  unless pipe goto failed
-  pipe.'puts'("Hello, pipe!\n")
-  close pipe
-  .return()
-failed:
-  say 'FAILED'
-.end
-CODE
-Hello, pipe!
-OUTPUT
+    nok(1, 'open with null mode')
+    .return ()
 
-}
+  open_null_mode_failed:
+    ok(1, 'open with null mode')
+.end
+
+.sub 'tt661_todo_test'
+    # Checks whether the platform is linux, MSWin32, darwin: on other
+    # platforms, the following tests are todo'ed.
+    $S0 = sysinfo 4
+    if $S0 == 'linux' goto tt661_ok
+    if $S0 == 'MSWin32' goto tt661_ok
+    if $S0 == 'darwin' goto tt661_ok
+
+    .return (0)
+
+  tt661_ok:
+    .return(1)
+.end
+
+.sub 'open_pipe_for_reading'
+    $I0 = tt661_todo_test()
+    unless $I0 goto open_pipe_for_reading_todoed
+
+    .include 'iglobals.pasm'
+
+    .local pmc interp
+    interp = getinterp
+
+    .local pmc conf
+    conf = interp[.IGLOBALS_CONFIG_HASH]
+
+    .local string command
+    command = conf['build_dir']
+
+    .local string aux
+    aux = conf['slash']
+    command .= aux
+    aux = conf['test_prog']
+    command .= aux
+    aux = conf['exe']
+    command .= aux
+    command .= ' -V'
+
+    .local pmc pipe
+    pipe = open command, 'rp'
+    unless pipe goto open_pipe_for_reading_failed
+    .local string line
+    line = readline pipe
+    like('This is Parrot', ":s This is Parrot", 'open pipe for reading')
+    .return()
+
+  open_pipe_for_reading_failed:
+    nok(1, 'open pipe for reading')
+    .return ()
+
+  open_pipe_for_reading_todoed:
+    todo(1, 'Unimplemented in this platform, TT #661')
+.end
+
+.sub 'open_pipe_for_writing'
+    .include 'iglobals.pasm'
+    
+    .local pmc interp
+    interp = getinterp
+
+    .local pmc conf
+    conf = interp[.IGLOBALS_CONFIG_HASH]
+  
+    .local string command
+    command = conf['build_dir']
+  
+    .local string aux
+    aux = conf['slash']
+    command .= aux
+    .local string filename
+    filename .= command
+    filename .= 'examples/pasm/cat.pasm'
+    aux = conf['test_prog']
+    command .= aux
+    aux = conf['exe']
+    command .= aux
+    command .= ' '
+    command .= filename
+
+    .local pmc pipe
+    pipe = open command, 'wp'
+    unless pipe goto open_pipe_for_writing_failed
+    pipe.'puts'("ok - open pipe for writing\n")
+    close pipe
+    .return()
+
+  open_pipe_for_writing_failed:
+    nok(1, 'open pipe for writing')
+    .return ()
+
+  open_pipe_for_writing_todoed:
+    todo(1, 'Unimplemented in this platform, TT #661')
+.end
 
 # Local Variables:
-#   mode: cperl
-#   cperl-indent-level: 4
+#   mode: pir
 #   fill-column: 100
 # End:
-# vim: expandtab shiftwidth=4:
+# vim: expandtab shiftwidth=4 ft=pir:


More information about the parrot-commits mailing list