Author: coke
Date: Tue Dec 30 16:25:18 2008
New Revision: 34679
Modified:
trunk/examples/tutorial/11_math_ops_self_mod.pir
trunk/t/examples/tutorial.t
Log:
Test all tutorial PIR [1]
* every PIR file in the directory must be tested or FAIL.
* don't special case the TODO for windows quite so much.
* update one tutorial to simplify & make it testable
(original version threw an exception, which didn't help teach anything at
that point.)
[1] except on windows!
Modified: trunk/examples/tutorial/11_math_ops_self_mod.pir
==============================================================================
--- trunk/examples/tutorial/11_math_ops_self_mod.pir (original)
+++ trunk/examples/tutorial/11_math_ops_self_mod.pir Tue Dec 30 16:25:18 2008
@@ -13,7 +13,7 @@
say $I0
$N0 = 22.44
- $N0 /= 0
+ $N0 /= 4
say $N0
.end
Modified: trunk/t/examples/tutorial.t
==============================================================================
--- trunk/t/examples/tutorial.t (original)
+++ trunk/t/examples/tutorial.t Tue Dec 30 16:25:18 2008
@@ -6,9 +6,9 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
+use ExtUtils::Manifest qw(maniread);
use Test::More;
-use Parrot::Test tests => 34;
-use Parrot::Config;
+use Parrot::Test;
=head1 NAME
@@ -22,17 +22,16 @@
Test the examples in F<examples/tutorial>.
-=head1 SEE ALSO
-
-F<t/examples/pir.t>
-
-=head1 AUTHORS
-
-Bernhard Schmalhofer - <[email protected]>
+=cut
-Colin Kuskie - <[email protected]>
+my $manifest = maniread('MANIFEST');
+my %files;
+foreach my $file (keys %$manifest) {
+ next unless $file =~ m{examples/tutorial/.*pir$};
+ $files{$file}=undef;
+}
-=cut
+plan tests => scalar keys %files;
# Set up expected output for examples
my %expected = (
@@ -65,6 +64,16 @@
5.2
END_EXPECTED
+ '11_math_ops_self_mod.pir' => << 'END_EXPECTED',
+6
+5.61
+END_EXPECTED
+
+ '12_math_ops_pasm.pir' => << 'END_EXPECTED',
+5
+121
+END_EXPECTED
+
'13_logical_ops.pir' => << 'END_EXPECTED',
0 2
1 2
@@ -135,18 +144,15 @@
after branch
END_EXPECTED
-##
-## Output for when the test is not marked as "todo" anymore.
-##
- # '51_if_unless.pir' => << 'END_EXPECTED',
- #before if
- #after if
- #
- #before unless
- #is printed
- #after unless
- #-0.0 was false
- #END_EXPECTED
+ '51_if_unless.pir' => << 'END_EXPECTED',
+before if
+after if
+
+before unless
+is printed
+after unless
+-0.0 was false
+END_EXPECTED
'52_if_compare.pir' => << 'END_EXPECTED',
before if
@@ -219,40 +225,31 @@
);
-my %skips = ();
+# note any todos. if the sub returns undef or isn't present, the
+# test will be run.
+my %todo = (
+ '51_if_unless.pir' => sub {
+ 'Failing on Win32' if $^O =~ /Win32/;
+ }
+);
-while ( my ( $example, $expected ) = each %expected ) {
- my $skip = $skips{$example};
- if ($skip) {
- my ( $cond, $reason ) = @{$skip};
- if ( eval "$cond" ) {
- Test::More->builder->skip("$example $reason");
- next;
+foreach my $tutorial (sort keys %files) {
+ my $file = $tutorial;
+ $file =~ s{.*/}{};
+ my @todo = ();
+ if (exists $expected{$file}) {
+ my $expected = $expected{$file};
+ if (exists $todo{$file}) {
+ my $reason = $todo{$file}->();
+ @todo = (todo => $reason) if defined $reason;
}
+ example_output_is( $tutorial, $expected, @todo );
+ } else {
+ fail($tutorial);
}
- example_output_is( "examples/tutorial/$example", $expected );
-}
-
-TODO:
-{
- local $TODO = 'some examples not passing yet';
- fail('11_math_ops_self_mod.pir');
- fail('12_math_ops_pasm.pir');
}
-my @TODO_35 = ();
-if ($^O =~ /Win32/) {
- @TODO_35 = ( todo => 'Failing on Win32' );
-}
-example_output_is( "examples/tutorial/51_if_unless.pir", << 'END_EXPECTED',
@TODO_35 );
-before if
-after if
-before unless
-is printed
-after unless
--0.0 was false
-END_EXPECTED
# cleanup
{