[t][TT #1122] Convert t/op/numbert.t to PIR, mgrimes++
[parrot.git] / t / examples / tutorial.t
blob53daee447a15a83f96b404b874f15a6b529e223d
1 #!perl
2 # Copyright (C) 2007-2008 Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
9 use ExtUtils::Manifest qw(maniread);
10 use Test::More;
11 use Parrot::Test;
13 =head1 NAME
15 t/examples/tutorial.t - Test examples in F<examples/tutorial>
17 =head1 SYNOPSIS
19     % prove t/examples/tutorial.t
21 =head1 DESCRIPTION
23 Test the examples in F<examples/tutorial>.
25 =cut
27 my $manifest = maniread('MANIFEST');
28 my %files;
29 foreach my $file (keys %$manifest) {
30   next unless $file =~ m{examples/tutorial/.*pir$}; 
31   $files{$file}=undef;
34 plan tests => scalar keys %files;
36 # Set up expected output for examples
37 my %expected = (
38     '01_temp_var.pir' => << 'END_EXPECTED',
40 3.14159
41 Hello
42 Ford
43 END_EXPECTED
45     '02_local_var.pir' => << 'END_EXPECTED',
47 3.14159
48 Hello
49 Ford
50 END_EXPECTED
52     '03_temp_var_basic_pmcs.pir' => << 'END_EXPECTED',
54 6.35
55 Foo Bar Baz
56 END_EXPECTED
58     '04_pod_comments.pir' => << 'END_EXPECTED',
59 Ignored Pod comments.
60 END_EXPECTED
62     '10_math_ops.pir' => << 'END_EXPECTED',
64 5.2
65 END_EXPECTED
67     '11_math_ops_self_mod.pir' => << 'END_EXPECTED',
69 5.61
70 END_EXPECTED
72     '12_math_ops_pasm.pir' => << 'END_EXPECTED',
74 121
75 END_EXPECTED
77     '13_logical_ops.pir' => << 'END_EXPECTED',
78 0 2
79 1 2
80 END_EXPECTED
82     '20_string_ops.pir' => << 'END_EXPECTED',
83 Hello, Zaphod!
84 END_EXPECTED
86     ##Note extra whitespace after 3rd hello
87     '21_string_ops_repeat.pir' => << 'END_EXPECTED',
88 Hello Hello Hello 
89 END_EXPECTED
91     '22_string_ops_length.pir' => << 'END_EXPECTED',
94 END_EXPECTED
96     '23_string_ops_substr.pir' => << 'END_EXPECTED',
99 abcde
101 aXYZde
102 END_EXPECTED
104     '24_string_ops_clone.pir' => << 'END_EXPECTED',
105 Ford
106 Zaphod
107 Zaphod
108 END_EXPECTED
110     '30_arrays_basic.pir' => << 'END_EXPECTED',
111 Baz Foo Bar
112 Bar'
115 END_EXPECTED
117     '31_array_ops_split.pir' => << 'END_EXPECTED',
119 brown
120 END_EXPECTED
122     '32_array_ops_sprintf.pir' => << 'END_EXPECTED',
123 int 0x2a num +10.50
125 END_EXPECTED
127     '33_hashes.pir' => << 'END_EXPECTED',
129 Integer
130 String
131 END_EXPECTED
133     '34_multikey.pir' => << 'END_EXPECTED',
135 END_EXPECTED
137     '40_file_ops.pir' => << 'END_EXPECTED',
138 The quick brown fox jumps over the lazy dog.
140 END_EXPECTED
142     '50_goto.pir' => << 'END_EXPECTED',
143 before branch
144 after branch
145 END_EXPECTED
147     '51_if_unless.pir' => << 'END_EXPECTED',
148 before if
149 after if
151 before unless
152 is printed
153 after unless
154 -0.0 was false
155 END_EXPECTED
157     '52_if_compare.pir' => << 'END_EXPECTED',
158 before if
159 after if
160 END_EXPECTED
162     '53_loop.pir' => << 'END_EXPECTED',
164 END_EXPECTED
166     '55_iterator.pir' => << 'END_EXPECTED',
171 END_EXPECTED
173     '56_defined.pir' => << 'END_EXPECTED',
174 $P1 is defined
175 $P3 is undefined
176 END_EXPECTED
178     '57_exists.pir' => << 'END_EXPECTED',
179 my_array[0] is defined
180 my_array[0] exists
181 my_array[1] is not defined
182 my_array[1] exists
183 my_array[2] is not defined
184 my_array[2] does not exist
185 END_EXPECTED
187     '60_subroutines.pir' => << 'END_EXPECTED',
188 Hello, Zaphod
189 END_EXPECTED
191     '61_namespaces.pir' => << 'END_EXPECTED',
192 Hello
193 END_EXPECTED
195     '62_namespaces.pir' => << 'END_EXPECTED',
196 Hello, Zaphod
197 END_EXPECTED
199     '70_class_object.pir' => << 'END_EXPECTED',
200 Hello
202 END_EXPECTED
204     '81_continuation.pir' => << 'END_EXPECTED',
205 got argument: 4
206 continuation called
207 END_EXPECTED
209     '82_coroutine.pir' => << 'END_EXPECTED',
212 END_EXPECTED
214     '83_external_libraries.pir' => << 'END_EXPECTED',
216 END_EXPECTED
218     '90_writing_tests.pir' => << 'END_EXPECTED',
219 1..4
220 ok 1 - first test
221 ok 2 - second test
222 ok 3 #skip skipped test
223 ok 4 # TODO 42
224 END_EXPECTED
228 # note any todos. if the sub returns undef or isn't present, the
229 # test will be run.
230 my %todo = (
231     '51_if_unless.pir' => sub {
232         'Failing on Win32' if $^O =~ /Win32/;
233     }
236 foreach my $tutorial (sort keys %files) {
237     my $file = $tutorial;
238     $file =~ s{.*/}{};
239     my @todo = ();
240     if (exists $expected{$file}) {
241         my $expected = $expected{$file};
242         if (exists $todo{$file}) {
243             my $reason = $todo{$file}->();
244             @todo = (todo => $reason) if defined $reason;
245         }
246         example_output_is( $tutorial, $expected, @todo );
247     } else {
248         fail($tutorial);
249     }
252 # Local Variables:
253 #   mode: cperl
254 #   cperl-indent-level: 4
255 #   fill-column: 100
256 # End:
257 # vim: expandtab shiftwidth=4: