Author: bernhard
Date: Wed Nov 9 11:44:52 2005
New Revision: 9866
Modified:
trunk/lib/Parrot/Test.pm
trunk/t/examples/pasm.t
trunk/t/examples/past.t
trunk/t/examples/pir.t
Log:
Teach Parrot::Test::language_output_\w+ about PIR, PAST and PASM.
Add Parrot::Test::example_output_is() that calls language_output_is().
Modified: trunk/lib/Parrot/Test.pm
==============================================================================
--- trunk/lib/Parrot/Test.pm (original)
+++ trunk/lib/Parrot/Test.pm Wed Nov 9 11:44:52 2005
@@ -26,6 +26,7 @@ This module provides various Parrot-spec
=head2 Functions
+The parameter C<$language> is the language of the code.
The parameter C<$code> is the code that should be executed or transformed.
The parameter C<$expected> is the expected result.
The parameter C<$unexpected> is the unexpected result.
@@ -40,6 +41,26 @@ C<unimplemented>, and so on.
=over 4
+=item C<language_output_is( $language, $code, $expected, $description)>
+
+Runs a langugage test and passes the test if a string comparison
+of the output with the expected result it true.
+
+=item C<language_output_like( $language, $code, $expected, $description)>
+
+Runs a langugage test and passes the test
+if the output matches the expected result.
+
+=item C<language_output_isnt( $language, $code, $expected, $description)>
+
+Runs a langugage test and passes the test if a string comparison
+if a string comparison of the output with the unexpected result is false.
+
+=item C<pasm_output_isnt($code, $unexpected, $description)> or
C<output_isnt($code, $unexpected, $description)>
+
+Runs the Parrot Assembler code and passes the test
+if a string comparison of the output with the unexpected result is false.
+
=item C<pasm_output_is($code, $expected, $description)> or C<output_is($code,
$expected, $description)>
Runs the Parrot Assembler code and passes the test if a string comparison
@@ -130,6 +151,11 @@ expected result.
Compiles and runs the C code, passing the test if a string comparison of
output with the unexpected result is false.
+=item C<example_output_is( $example_fn, $expected )
+
+Determine the language from the extension of C<$example_fn> and
+runs language_output_is().
+
=item C<skip($why, $how_many)>
Use within a C<SKIP: { ... }> block to indicate why and how many test
@@ -173,14 +199,16 @@ require Test::Builder;
require Test::More;
[EMAIL PROTECTED] = qw( output_is output_like output_isnt
[EMAIL PROTECTED] = qw(
+ language_output_is language_output_like language_output_isnt
+ example_output_is
+ output_is output_like output_isnt
pasm_output_is pasm_output_like pasm_output_isnt
past_output_is past_output_like past_output_isnt
pir_output_is pir_output_like pir_output_isnt
pir_2_pasm_is pir_2_pasm_like pir_2_pasm_isnt
pbc_output_is pbc_output_like pbc_output_isnt
c_output_is c_output_like c_output_isnt
- language_output_is language_output_like language_output_isnt
plan
skip
slurp_file
@@ -468,39 +496,54 @@ sub _generate_functions {
}
}
+ my %builtin_language_prefix = (
+ IMC => 'pir',
+ PASM => 'pasm',
+ PAST => 'past',
+ PIR => 'pir',
+ );
+
my %language_test_map = (
language_output_is => 'output_is',
language_output_like => 'output_like',
language_output_isnt => 'output_isnt',
- );
+ );
foreach my $func ( keys %language_test_map ) {
no strict 'refs';
*{$package.'::'.$func} = sub ($$$;$) {
- # TODO: $language should be the name of the test Module
- # that would open the door for Scheme::Test
- my $language = $_[0];
- $language = ucfirst($language) unless ( $language eq 'm4' );
-
- # make sure TODO will work, by telling Test::Builder which package
- # the .t file is in (one more than usual, due to the extra layer
- # of package indirection
- my $level = $builder->level();
- $builder->level(2);
-
- # get modified parrot command.
- require "Parrot/Test/$language.pm";
- # set the builder object, and parrot config.
- my $obj = eval "Parrot::Test::${language}->new()";
- $obj->{builder} = $builder;
- $obj->{relpath} = $path_to_parrot;
- $obj->{parrot} = $parrot;
+ my ( $language, @remaining ) = @_;
+
my $meth = $language_test_map{$func};
- $obj->$meth(@_[1..$#_]);
+ if ( my $prefix = $builtin_language_prefix{$language} ) {
+ my $test_func = "${package}::${prefix}_${meth}";
+ &$test_func( @remaining );
+ }
+ else {
+ # TODO: $language should be the name of the test Module
+ # that would open the door for Scheme::Test
+ # try it both ways
+ $language = ucfirst($language) unless ( $language eq 'm4' );
+
+ # make sure TODO will work, by telling Test::Builder which
package
+ # the .t file is in (one more than usual, due to the extra
layer
+ # of package indirection
+ my $level = $builder->level();
+ $builder->level(2);
+
+ # get modified parrot command.
+ require "Parrot/Test/$language.pm";
+ # set the builder object, and parrot config.
+ my $obj = eval "Parrot::Test::${language}->new()";
+ $obj->{builder} = $builder;
+ $obj->{relpath} = $path_to_parrot;
+ $obj->{parrot} = $parrot;
+ $obj->$meth(@remaining);
- # restore prior level, just in case.
- $builder->level($level);
+ # restore prior level, just in case.
+ $builder->level($level);
+ }
}
}
@@ -607,6 +650,28 @@ sub _generate_functions {
}
}
+sub example_output_is {
+ my ($example_fn, $expected) = @_;
+
+ my %lang_for_extension
+ = ( pasm => 'PASM',
+ past => 'PAST',
+ pir => 'PIR',
+ imc => 'PIR', );
+
+ my ( $extension ) = $example_fn =~ m{ [.] #
introducing extension
+ ( pasm | pir | imc | past ) # match
and capture the extension
+ \z # at end
of string
+ }ixms or Usage();
+ if ( defined $extension ) {
+ my $code = slurp_file($example_fn);
+ language_output_is( $lang_for_extension{$extension}, $code, $expected,
$example_fn );
+ }
+ else {
+ fail( defined $extension, "no extension recognized for $example_fn" );
+ }
+}
+
Parrot::Test::_generate_functions(__PACKAGE__, \&generate_code );
=head1 TODO
Modified: trunk/t/examples/pasm.t
==============================================================================
--- trunk/t/examples/pasm.t (original)
+++ trunk/t/examples/pasm.t Wed Nov 9 11:44:52 2005
@@ -28,10 +28,10 @@ F<t/examples/pir.t>
use strict;
use Parrot::Test tests => 6;
-use Test::More;
# Set up expected output for examples
-my %expected = (
+my %expected
+ = (
'fact.pasm' => << 'END_EXPECTED',
fact of 0 is: 1
@@ -101,25 +101,8 @@ Close inner
Close top
END_EXPECTED
- );
-
-# Do the testing
-my %test_func = ( pasm => \&pasm_output_is,
- pir => \&pir_output_is,
- imc => \&pir_output_is );
+ );
while ( my ( $example, $expected ) = each %expected ) {
- my $code_fn = "examples/pasm/$example";
- my $code = Parrot::Test::slurp_file($code_fn);
-
- my ( $extension ) = $example =~ m{ [.] # introducing
extension
- ( pasm | pir | imc ) # match and
capture the extension
- \z # at end of string
- }ixms or Usage();
- if ( defined $extension ) {
- $test_func{$extension}->($code, $expected, $code_fn);
- }
- else {
- ok( defined $extension, "no extension recognized for $code_fn" );
- }
+ example_output_is( "examples/pasm/$example", $expected );
}
Modified: trunk/t/examples/past.t
==============================================================================
--- trunk/t/examples/past.t (original)
+++ trunk/t/examples/past.t Wed Nov 9 11:44:52 2005
@@ -32,36 +32,15 @@ Bernhard Schmalhofer - <Bernhard.Schmalh
use strict;
use Parrot::Test tests => 1;
-use Test::More;
-use Parrot::Config;
-
-my $PARROT = ".$PConfig{slash}$PConfig{test_prog}";
# Set up expected output for examples
-my %expected = (
+my %expected
+ = (
'hello.past' => << 'END_EXPECTED',
Hello PAST
END_EXPECTED
- );
-
-# Do the testing
-my %test_func = ( pasm => \&pasm_output_is,
- past => \&past_output_is,
- pir => \&pir_output_is,
- imc => \&pir_output_is );
+ );
while ( my ( $example, $expected ) = each %expected ) {
- my $code_fn = "examples/past/$example";
- my $code = Parrot::Test::slurp_file($code_fn);
-
- my ( $extension ) = $example =~ m{ [.] #
introducing extension
- ( pasm | pir | imc | past ) # match and
capture the extension
- \z # at end of
string
- }ixms or Usage();
- if ( defined $extension ) {
- $test_func{$extension}->($code, $expected, $code_fn);
- }
- else {
- ok( defined $extension, "no extension recognized for $code_fn" );
- }
+ example_output_is( "examples/past/$example", $expected );
}
Modified: trunk/t/examples/pir.t
==============================================================================
--- trunk/t/examples/pir.t (original)
+++ trunk/t/examples/pir.t Wed Nov 9 11:44:52 2005
@@ -19,7 +19,6 @@ Test the examples in F<examples/pir>.
=head1 TODO
Check on remaining examples.
-Perhaps use Parrot::Test::run_command().
=head1 SEE ALSO
@@ -36,10 +35,10 @@ use Parrot::Test tests => 11;
use Test::More;
use Parrot::Config;
-my $PARROT = ".$PConfig{slash}$PConfig{test_prog}";
# Set up expected output for examples
-my %expected = (
+my %expected
+ = (
'circle.pir' => << 'END_EXPECTED',
[H[2J[23;40H*[23;40H*[23;41H*[23;41H*[23;42H*[23;42H*[23;43H*[23;44H*[23;44H*[23;45H*[23;45H*[23;46H*[23;46H*[23;47H*[22;48H*[22;48H*[22;49H*[22;49H*[22;50H*[22;50H*[22;51H*[22;52H*[22;52H*[22;53H*[22;53H*[22;54H*[22;54H*[22;55H*[22;55H*[22;56H*[22;56H*[21;57H*[21;58H*[21;58H*[21;59H*[21;59H*[21;60H*[21;60H*[21;61H*[21;61H*[21;62H*[21;62H*[20;62H*[20;63H*[20;63H*[20;64H*[20;64H*[20;65H*[20;65H*[20;66H*[20;66H*[19;66H*[19;67H*[19;67H*[19;68H*[19;68H*[19;68H*[19;69H*[18;69H*[18;70H*[18;70H*[18;70H*[18;71H*[18;71H*[18;71H*[17;72H*[17;72H*[17;72H*[17;72H*[17;73H*[17;73H*[17;73H*[16;74H*[16;74H*[16;74H*[16;74H*[16;75H*[16;75H*[15;75H*[15;75H*[15;75H*[15;76H*[15;76H*[15;76H*[14;76H*[14;76H*[14;76H*[14;77H*[14;77H*[14;77H*[13;77H*[13;77H*[13;77H*[13;77H*[13;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[12;77H*[11;77H*[11;77H*[11;77H*[11;77H*[11;77H*[10;77H*[10;77H*[10;77H*[10;77H*[10;76H*[10;76H*[9;76H*[9;76H*[9;76H*[9;76H*[9;75H*[9;75H*[8;75H*[8;75H*[8;75H*[8;74H*[8;74H*[8;74H*[7;74H*[7;73H*[7;73H*[7;73H*[7;72H*[7;72H*[7;72H*[6;72H*[6;71H*[6;71H*[6;71H*[6;70H*[6;70H*[5;70H*[5;69H*[5;69H*[5;68H*[5;68H*[5;68H*[5;67H*[5;67H*[4;66H*[4;66H*[4;66H*[4;65H*[4;65H*[4;64H*[4;64H*[4;63H*[3;63H*[3;62H*[3;62H*[3;61H*[3;61H*[3;60H*[3;60H*[3;59H*[3;59H*[3;58H*[2;58H*[2;57H*[2;57H*[2;56H*[2;56H*[2;55H*[2;55H*[2;54H*[2;54H*[2;53H*[2;52H*[2;52H*[2;51H*[2;51H*[1;50H*[1;50H*[1;49H*[1;48H*[1;48H*[1;47H*[1;47H*[1;46H*[1;46H*[1;45H*[1;44H*[1;44H*[1;43H*[1;43H*[1;42H*[1;41H*[1;41H*[1;40H*[1;40H*[1;40H*[1;39H*[1;39H*[1;38H*[1;38H*[1;37H*[1;36H*[1;36H*[1;35H*[1;35H*[1;34H*[1;33H*[1;33H*[1;32H*[1;32H*[1;31H*[1;30H*[1;30H*[1;29H*[2;29H*[2;28H*[2;28H*[2;27H*[2;26H*[2;26H*[2;25H*[2;25H*[2;24H*[2;24H*[2;23H*[2;23H*[2;22H*[2;22H*[3;21H*[3;21H*[3;20H*[3;20H*[3;19H*[3;19H*[3;18H*[3;18H*[3;17H*[3;17H*[4;16H*[4;16H*[4;15H*[4;15H*[4;14H*[4;14H*[4;13H*[4;13H*[5;13H*[5;12H*[5;12H*[5;11H*[5;11H*[5;11H*[5;10H*[5;10H*[6;9H*[6;9H*[6;9H*[6;8H*[6;8H*[6;8H*[7;7H*[7;7H*[7;7H*[7;6H*[7;6H*[7;6H*[7;6H*[8;5H*[8;5H*[8;5H*[8;5H*[8;4H*[8;4H*[9;4H*[9;4H*[9;4H*[9;3H*[9;3H*[10;3H*[10;3H*[10;3H*[10;3H*[10;2H*[10;2H*[11;2H*[11;2H*[11;2H*[11;2H*[11;2H*[11;2H*[12;2H*[12;2H*[12;2H*[12;2H*[12;2H*[12;2H*[12;2H*[12;2H*[12;2H*[12;2H*[12;2H*[13;2H*[13;2H*[13;2H*[13;2H*[13;2H*[14;2H*[14;2H*[14;2H*[14;3H*[14;3H*[14;3H*[15;3H*[15;3H*[15;3H*[15;4H*[15;4H*[16;4H*[16;4H*[16;4H*[16;5H*[16;5H*[16;5H*[17;5H*[17;6H*[17;6H*[17;6H*[17;6H*[17;7H*[17;7H*[18;7H*[18;8H*[18;8H*[18;8H*[18;9H*[18;9H*[19;9H*[19;10H*[19;10H*[19;10H*[19;11H*[19;11H*[19;12H*[20;12H*[20;12H*[20;13H*[20;13H*[20;14H*[20;14H*[20;15H*[20;15H*[21;16H*[21;16H*[21;17H*[21;17H*[21;18H*[21;18H*[21;19H*[21;19H*[21;20H*[22;20H*[22;21H*[22;21H*[22;22H*[22;22H*[22;23H*[22;23H*[22;24H*[22;24H*[22;25H*[22;25H*[22;26H*[23;27H*[23;27H*[23;28H*[23;28H*[23;29H*[23;30H*[23;30H*[23;31H*[23;31H*[23;32H*[23;32H*[23;33H*[23;34H*[23;34H*[23;35H*[23;36H*[23;36H*[23;37H*[23;37H*[23;38H*[23;39H*[23;39H*[23;40H*[23;40H*[23;40H*[24;0H
END_EXPECTED
@@ -187,29 +186,14 @@ init ok
+---------+---------+---------+
solved
END_EXPECTED
- );
-
-# Do the testing
-my %test_func = ( pasm => \&pasm_output_is,
- pir => \&pir_output_is,
- imc => \&pir_output_is );
+ );
while ( my ( $example, $expected ) = each %expected ) {
- my $code_fn = "examples/pir/$example";
- my $code = Parrot::Test::slurp_file($code_fn);
-
- my ( $extension ) = $example =~ m{ [.] # introducing
extension
- ( pasm | pir | imc ) # match and
capture the extension
- \z # at end of string
- }ixms or Usage();
- if ( defined $extension ) {
- $test_func{$extension}->($code, $expected, $code_fn);
- }
- else {
- ok( defined $extension, "no extension recognized for $code_fn" );
- }
+ example_output_is( "examples/pir/$example", $expected );
}
+my $PARROT = ".$PConfig{slash}$PConfig{test_prog}";
+
# For testing life.pir, the number of generations should be small,
# because users should not get bored.
{