From a465c6dbc0c087f4ee6907b74907b58b89f598e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Quelin?= Date: Mon, 25 May 2009 16:46:21 +0200 Subject: [PATCH] ported to test::output --- t/4-interpreter/trefunge.t | 105 +++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 75 deletions(-) diff --git a/t/4-interpreter/trefunge.t b/t/4-interpreter/trefunge.t index 6b47316..c677bcf 100644 --- a/t/4-interpreter/trefunge.t +++ b/t/4-interpreter/trefunge.t @@ -8,53 +8,24 @@ # # -#-----------------------------------# -# Exported funcs. # -#-----------------------------------# - use strict; +use warnings; + use Language::Befunge; use aliased 'Language::Befunge::Vector' => 'LBV'; -use POSIX qw! tmpnam !; -use Test::More; - -# Vars. -my ($file, $fh); -my $tests; -my $out; -my $tref = Language::Befunge->new( {syntax=>'trefunge98'} ); -BEGIN { $tests = 0 }; - -# In order to see what happens... -sub sel () { - $file = tmpnam(); - open OUT, ">$file" or die $!; - $fh = select OUT; -} -sub slurp () { - select $fh; - close OUT; - open OUT, "<$file" or die $!; - my $content; - { - local $/; - $content = ; - } - close OUT; - unlink $file; - return $content; -} - -# Basic constructor. -sel; +use Test::More tests => 11; +use Test::Output; + +my $tref; + + +# basic constructor. $tref = Language::Befunge->new( {file=>'t/_resources/q.bf', syntax=>'trefunge98'} ); -$tref->run_code; -$out = slurp; -is( $out, '', 'constructor worked' ); -BEGIN { $tests += 1 }; +stdout_is { $tref->run_code } '', 'constructor worked'; + -# Custom constructor. +# custom constructor. $tref = Language::Befunge->new({ syntax => 'trefunge98', storage => 'Language::Befunge::Storage::Generic::Vec' }); @@ -71,50 +42,37 @@ $tref = Language::Befunge->new({ syntax => 'trefunge98', dims => 4 }); is($$tref{dimensions}, 4, 'dims specified'); -BEGIN { $tests += 4 }; -# Basic reading. + +# basic reading. $tref = Language::Befunge->new( {syntax=>'trefunge98'} ); -sel; $tref->read_file( "t/_resources/q.bf" ); -$tref->run_code; -$out = slurp; -is( $out, "", 'read_file' ); -BEGIN { $tests += 1 }; +stdout_is { $tref->run_code } '', 'read_file'; + -# Basic storing. -sel; +# basic storing. $tref->store_code( <<'END_OF_CODE' ); q END_OF_CODE -$tref->run_code; -$out = slurp; -is( $out, '', 'store_code' ); -BEGIN { $tests += 1 }; +stdout_is { $tref->run_code } '', 'store_code'; + -# Interpreter must treat non-characters as if they were an 'r' instruction. -sel; +# interpreter must treat non-characters as if they were an 'r' instruction. $tref->store_code( <<'END_OF_CODE' ); 01-c00p#q1.2 q END_OF_CODE -$tref->run_code; -$out = slurp; -is( $out, "1 2 ", 'treats non-characters like "r"' ); -BEGIN { $tests += 1 }; +stdout_is { $tref->run_code } '1 2 ', 'treats non-characters like "r"'; -# Interpreter must treat non-commands as if they were an 'r' instruction. -sel; + +# interpreter must treat non-commands as if they were an 'r' instruction. $tref->store_code( <<'END_OF_CODE' ); 01+c00p#q1.2 q END_OF_CODE -$tref->run_code; -$out = slurp; -is( $out, "1 2 ", 'treats non-commands like "r"' ); -BEGIN { $tests += 1 }; +stdout_is { $tref->run_code } '1 2 ', 'treats non-commands like "r"'; + -# Interpreter reads trefunge code properly, and operates in 3 dimensions, and +# interpreter reads trefunge code properly, and operates in 3 dimensions, and # knows that vectors are 3 integers. -sel; my $code = <<"END_OF_CODE"; #v401-11x >..q @@ -122,14 +80,11 @@ my $code = <<"END_OF_CODE"; ^3 < END_OF_CODE $tref->store_code( $code ); -$tref->run_code; -$out = slurp; -is( $out, "3 4 ", 'full operation' ); -BEGIN { $tests += 1 }; +stdout_is { $tref->run_code } '3 4 ', 'full operation'; + # rectangle() returns the original box again chomp $code; -is($tref->get_storage->rectangle(LBV->new(0,0,0), LBV->new(9,2,2)), $code, 'rectangle works'); -BEGIN { $tests += 1 }; +is( $tref->get_storage->rectangle( LBV->new(0,0,0), LBV->new(9,2,2) ), + $code, 'rectangle works' ); -BEGIN { plan tests => $tests }; -- 2.11.4.GIT