3 # This file is part of Language::Befunge.
4 # Copyright (c) 2001-2008 Jerome Quelin, all rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
11 #---------------------------------#
13 #---------------------------------#
16 use File::Spec::Functions qw{ catfile };
17 use Language::Befunge;
18 use POSIX qw! tmpnam !;
26 my $bef = Language::Befunge->new;
29 # In order to see what happens...
32 open OUT, ">$file" or die $!;
38 open OUT, "<$file" or die $!;
51 skip 'will barf on windows...', 1 if $^O eq 'MSWin32';
54 $bef->store_code( '< q . = "a_file_unlikely_to_exist"0' );
56 local $SIG{__WARN__} = sub {};
62 sel; # normal system-ing.
63 $bef->store_code( <<'END_OF_CODE' );
64 < q . = "perl t/_resources/exit3.pl"0
69 BEGIN { $tests += 2 };
71 # System info retrieval.
73 $bef->store_code( <<'END_OF_CODE' );
79 BEGIN { $tests += 1 };
81 sel; # 2. size of funge integers in bytes.
82 $bef->store_code( <<'END_OF_CODE' );
88 BEGIN { $tests += 1 };
91 $bef->store_code( <<'END_OF_CODE' );
97 $handprint = $handprint*256 + ord($_) for split //, $bef->get_handprint;
98 is( $out, "$handprint " );
99 BEGIN { $tests += 1 };
101 sel; # 4. version of interpreter.
102 $bef->store_code( <<'END_OF_CODE' );
107 my $ver = $Language::Befunge::VERSION;
110 BEGIN { $tests += 1 };
113 $bef->store_code( <<'END_OF_CODE' );
119 BEGIN { $tests += 1 };
121 sel; # 6. path separator.
122 $bef->store_code( <<'END_OF_CODE' );
127 is( $out, catfile('','') );
128 BEGIN { $tests += 1 };
130 sel; # 7. size of funge (2D).
131 $bef->store_code( <<'END_OF_CODE' );
137 BEGIN { $tests += 1 };
140 $bef->store_code( <<'END_OF_CODE' );
145 like( $out, qr/^\d+ $/ );
146 BEGIN { $tests += 1 };
148 sel; # 9. NetFunge (unimplemented).
149 $bef->store_code( <<'END_OF_CODE' );
155 BEGIN { $tests += 1 };
157 sel; # 10. pos of IP.
158 $bef->store_code( <<'END_OF_CODE' );
165 BEGIN { $tests += 1 };
167 sel; # 11. delta of IP.
168 $bef->store_code( <<'END_OF_CODE' );
178 BEGIN { $tests += 1 };
180 sel; # 12. Storage offset.
181 $bef->store_code( <<'END_OF_CODE' );
187 BEGIN { $tests += 1 };
189 sel; # 13. top-left corner of Lahey space.
190 $bef->store_code( <<'END_OF_CODE' );
195 is( $out, "-4 -3 " );
196 BEGIN { $tests += 1 };
198 sel; # 14. bottom-right corner of Lahey space.
199 $bef->store_code( <<'END_OF_CODE' );
200 6 ff+8p 6 03-04-p ey..q
204 is( $out, "12 33 " );
205 BEGIN { $tests += 1 };
208 my ($s,$m,$h,$dd,$mm,$yy)=localtime;
209 my $date = $yy*256*256+$mm*256+$dd;
210 my $time = $h*256*256+$m*256+$s;
211 $bef->store_code( <<'END_OF_CODE' );
216 chop($out); # remove trailing space.
217 is( $out >= $date, 1); # There is a tiny little chance
218 is( $out <= $date+1, 1); # that the date has changed.
219 BEGIN { $tests += 2 };
222 $bef->store_code( <<'END_OF_CODE' );
227 chop($out); # remove trailing space.
228 is( $out >= $time, 1); # The two tests should not take
229 is( $out <= $time+15, 1); # more than 15 seconds.
230 BEGIN { $tests += 2 };
232 sel; # 17. Size of stack stack.
233 $bef->store_code( <<'END_OF_CODE' );
234 0{0{0{0{ 89+y. 0}0} 89+y.q
239 BEGIN { $tests += 1 };
241 sel; # 18. Size of each stack.
242 $bef->store_code( <<'END_OF_CODE' );
243 123 0{ 12 0{ 987654 99+y...q
247 is( $out, "6 4 5 " );
248 BEGIN { $tests += 1 };
251 $bef->store_code( <<'END_OF_CODE' );
252 a9+y > :#, _ $a, :#v _q
255 $bef->run_code( "foo", 7, "bar" );
257 is( $out, "STDIN\nfoo\n7\nbar\n" );
258 BEGIN { $tests += 1 };
264 $bef->store_code( <<'END_OF_CODE' );
267 > 2a*y : | ;new pair; : <
272 is( $out, "LANG=C\nLC_ALL=C\n" );
273 BEGIN { $tests += 1 };
276 $bef->store_code( <<'END_OF_CODE' );
281 is( $out, "15 4 $handprint " );
282 BEGIN { $tests += 1 };
284 sel; # pick in stack.
285 $bef->store_code( <<'END_OF_CODE' );
291 BEGIN { $tests += 1 };
293 BEGIN { plan tests => $tests };