From 467363c94c6068ed6bbb31a017eca2d362e362db Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Quelin?= Date: Mon, 25 May 2009 20:23:19 +0200 Subject: [PATCH] ported to test::output --- t/5-befunge/d-dir.t | 177 +++++++++++++--------------------------------------- 1 file changed, 45 insertions(+), 132 deletions(-) diff --git a/t/5-befunge/d-dir.t b/t/5-befunge/d-dir.t index 75f1897..7a1d943 100644 --- a/t/5-befunge/d-dir.t +++ b/t/5-befunge/d-dir.t @@ -8,195 +8,122 @@ # # -#---------------------------------------# -# Direction changing. # -#---------------------------------------# +# -- direction changing use strict; +use warnings; + +use Test::More tests => 19; +use Test::Output; + use Language::Befunge; -use POSIX qw! tmpnam !; -use Test; - -# Vars. -my $file; -my $fh; -my $tests; -my $out; my $bef = Language::Befunge->new; -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; -} - -# Go west. -sel; -$bef->store_code( <<'END_OF_CODE' ); -run_code; -$out = slurp; -ok( $out, "10 " ); -BEGIN { $tests += 1 }; -# Go south. -sel; + +# go west +$bef->store_code( 'run_code } '10 ', 'go west'; + + +# go south $bef->store_code( <<'END_OF_CODE' ); v a . q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "10 " ); -BEGIN { $tests += 1 }; +stdout_is { $bef->run_code } '10 ', 'go south'; + -# Go north. -sel; +# go north $bef->store_code( <<'END_OF_CODE' ); ^ q . a END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "10 " ); -BEGIN { $tests += 1 }; +stdout_is { $bef->run_code } '10 ', 'go north'; + -# Go east. -sel; +# go east $bef->store_code( <<'END_OF_CODE' ); v > a . q > ^ END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "10 " ); -BEGIN { $tests += 1 }; +stdout_is { $bef->run_code } '10 ', 'go east'; + -# Go away. -sel; +# go away $bef->store_code( <<'END_OF_CODE' ); v > 2.q > #v? 1.q > 3.q > 4.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, qr/^[1-4] $/ ); -BEGIN { $tests += 1 }; +stdout_like { $bef->run_code } qr/^[1-4] $/, 'go away'; + -# Turn left. -sel; # from west. +# turn left $bef->store_code( <<'END_OF_CODE' ); v > 1.q > [ > 2.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -sel; # from east. +stdout_is { $bef->run_code } '1 ', 'turn left, from west'; $bef->store_code( <<'END_OF_CODE' ); v > 1.q < [ > 2.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "2 " ); -sel; # from north. +stdout_is { $bef->run_code } '2 ', 'turn left, from east'; $bef->store_code( <<'END_OF_CODE' ); > v q.2 [ 1.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -sel; # from south. +stdout_is { $bef->run_code } '1 ', 'turn left, from north'; $bef->store_code( <<'END_OF_CODE' ); > ^ q.2 [ 1.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "2 " ); -BEGIN { $tests += 4 }; +stdout_is { $bef->run_code } '2 ', 'turn left, from south'; -# Turn right. -sel; # from west. + +# turn right $bef->store_code( <<'END_OF_CODE' ); v > 1.q > ] > 2.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "2 " ); -sel; # from east. +stdout_is { $bef->run_code } '2 ', 'turn right, from west'; $bef->store_code( <<'END_OF_CODE' ); v > 1.q < ] > 2.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -sel; # from north. +stdout_is { $bef->run_code } '1 ', 'turn right, from east'; $bef->store_code( <<'END_OF_CODE' ); > v q.2 ] 1.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "2 " ); -sel; # from south. +stdout_is { $bef->run_code } '2 ', 'turn right, from north'; $bef->store_code( <<'END_OF_CODE' ); > ^ q.2 ] 1.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -BEGIN { $tests += 4 }; +stdout_is { $bef->run_code } '1 ', 'turn right, from south'; + -# Reverse. -sel; # from west. +# reverse $bef->store_code( <<'END_OF_CODE' ); > #vr 2.q > 1.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -sel; # from east. +stdout_is { $bef->run_code } '1 ', 'reverse, from west'; $bef->store_code( <<'END_OF_CODE' ); < q.2 rv# q.1 < END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -sel; # from north. +stdout_is { $bef->run_code } '1 ', 'reverse, from east'; $bef->store_code( <<'END_OF_CODE' ); > v # @@ -204,10 +131,7 @@ $bef->store_code( <<'END_OF_CODE' ); r > 2.q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -sel; # from south. +stdout_is { $bef->run_code } '1 ', 'reverse, from north'; $bef->store_code( <<'END_OF_CODE' ); > ^ > 2.q @@ -215,34 +139,23 @@ $bef->store_code( <<'END_OF_CODE' ); > 1.q # END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -BEGIN { $tests += 4 }; +stdout_is { $bef->run_code } '1 ', 'reverse, from south'; -# Absolute vector. -sel; # diagonal. + +# absolute vector $bef->store_code( <<'END_OF_CODE' ); 11x 1 . q END_OF_CODE -$bef->run_code; -$out = slurp; -ok( $out, "1 " ); -sel; # diagonal/out-of-bounds. +stdout_is { $bef->run_code } '1 ', 'absolute vectore, diagonal'; $bef->store_code( <<'END_OF_CODE' ); 101-x q . 1 END_OF_CODE +stdout_is { $bef->run_code } '1 ', 'absolute vectore, diagonal out of bounds'; $bef->run_code; -$out = slurp; -ok( $out, "1 " ); -BEGIN { $tests += 2 }; - - -BEGIN { plan tests => $tests }; -- 2.11.4.GIT