From dd3dd9e0fff2d79974fe4b414aeb98647db1ba02 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Quelin?= Date: Tue, 8 Jan 2008 18:53:55 +0100 Subject: [PATCH] more robust way of skipping when Test::Exception is not present - BEGIN { use_ok('Test::Exception') } isn't very wise - added "use warnings" - cleaned tests number counting (now in the plan at the top) --- t/1-classes/vector.t | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/t/1-classes/vector.t b/t/1-classes/vector.t index 49bd2ec..9bc3dfc 100644 --- a/t/1-classes/vector.t +++ b/t/1-classes/vector.t @@ -13,35 +13,32 @@ #--------------------------------------# use strict; -use Test::More; +use warnings; + +use Test::More tests => 91; + use Language::Befunge::IP; use Language::Befunge::Vector; -BEGIN { use_ok ('Test::Exception') }; -my $test_exception_loaded = defined($Test::Exception::VERSION); -my $tests; my $ip = Language::Befunge::IP->new; -BEGIN { $tests = 0 }; # CONSTRUCTORS # ->new() my $v1 = Language::Befunge::Vector->new(3, 2, 1, 0); -isa_ok( $v1, "Language::Befunge::Vector"); -is($v1->get_dims, 3, "three dimensions"); -is($v1->get_component(0), 2, "X is correct"); -is($v1->get_component(1), 1, "Y is correct"); -is($v1->get_component(2), 0, "Z is correct"); +isa_ok($v1, "Language::Befunge::Vector"); +is($v1->get_dims, 3, "three dimensions"); +is($v1->get_component(0), 2, "X is correct"); +is($v1->get_component(1), 1, "Y is correct"); +is($v1->get_component(2), 0, "Z is correct"); is($v1->vector_as_string, '(2,1,0)', "stringifies back to (2,1,0)"); is("$v1", '(2,1,0)', "overloaded stringify back to (2,1,0)"); -BEGIN { $tests += 7 }; # ->new_zeroes() $v1 = Language::Befunge::Vector->new_zeroes(4); isa_ok( $v1, "Language::Befunge::Vector"); is($v1->get_dims, 4, "four dimensions"); is("$v1", '(0,0,0,0)', "all values are 0"); -BEGIN { $tests += 3 }; # METHODS @@ -58,7 +55,6 @@ is($v2->get_component(0), -5, "X is the inverse of v1's"); is($v2->get_component(1), -6, "Y is the inverse of v1's"); is($v3->get_component(0), -5, "X is the inverse of v1's"); is($v3->get_component(1), -6, "Y is the inverse of v1's"); -BEGIN { $tests += 6 }; # vector_add my $v4 = Language::Befunge::Vector->new(2, 1, 1); @@ -72,7 +68,6 @@ is($v2->get_component(0), 6, "X is v1's X plus v4's X"); is($v2->get_component(1), 7, "Y is v1's Y plus v4's Y"); is($v3->get_component(0), 6, "X is v1's X plus v4's X"); is($v3->get_component(1), 7, "Y is v1's Y plus v4's Y"); -BEGIN { $tests += 8 }; # vector_add_inplace $v2 = $v1->vector_copy(); @@ -84,7 +79,6 @@ is($v2->get_component(0), 6, "X has had 1 added in v2"); is($v2->get_component(1), 7, "Y has had 1 added in v2"); is($v4->get_component(0), 1, "X hasn't changed in v4"); is($v4->get_component(1), 1, "Y hasn't changed in v4"); -BEGIN { $tests += 6 }; # vector_copy $v2 = $v1->vector_copy(); @@ -98,15 +92,13 @@ is($v2->get_component(0), 6, "X hasn't changed in v2"); is($v2->get_component(1), 7, "Y hasn't changed in v2"); is($v3->get_component(0), 6, "X hasn't changed in v3"); is($v3->get_component(1), 7, "Y hasn't changed in v3"); -BEGIN { $tests += 8 }; # setd $v1->set_component(0,1); $v1->set_component(1,2); -is($v1->get_component(0), 1, "X is now 1"); -is($v1->get_component(1), 2, "Y is now 2"); +is($v1->get_component(0), 1, "X is now 1"); +is($v1->get_component(1), 2, "Y is now 2"); is($v1->vector_as_string, "(1,2)", "setd works"); -BEGIN { $tests += 3 }; # getd is tested all over this script. @@ -115,13 +107,11 @@ my @list = $v1->get_all_components; is(scalar @list, 2, "get_all_components returned 2 elements"); is($list[0], 1, "X is 1"); is($list[1], 2, "Y is 2"); -BEGIN { $tests += 3 }; # zero $v1->zero(); is($v1->get_component(0), 0, "X is now 0"); is($v1->get_component(1), 0, "Y is now 0"); -BEGIN { $tests += 2 }; # bounds_check $v1 = Language::Befunge::Vector->new(2, -1, -1); @@ -140,7 +130,6 @@ $v3 = Language::Befunge::Vector->new(2, 23, 0); ok(!$v3->bounds_check($v1, $v2), "(23,0) is out of bounds"); $v3 = Language::Befunge::Vector->new(2, 0, 23); ok(!$v3->bounds_check($v1, $v2), "(0,23) is out of bounds"); -BEGIN { $tests += 7 }; # vector_as_string is already tested, above @@ -158,7 +147,6 @@ ok( $v2->vector_equality($v1) , "v2 == v1"); ok( $v1->vector_equality($v1) , "v1 == v1"); ok(!($v1->vector_equality($v3)), "!(v1 == v3)"); ok(!($v2->vector_equality($v3)), "!(v2 == v3)"); -BEGIN { $tests += 10 }; # vector_inequality $v1 = Language::Befunge::Vector->new(2, 1, 1); @@ -174,11 +162,12 @@ ok(!($v2->vector_inequality($v1)), "!(v2 != v1)"); ok(!($v1->vector_inequality($v1)), "!(v1 != v1)"); ok( ($v1->vector_inequality($v3)), "v1 != v3"); ok( ($v2->vector_inequality($v3)), "v2 != v3"); -BEGIN { $tests += 10 }; # finally, test all the possible ways to die SKIP: { - skip 'need Test::Exception', 18 unless $test_exception_loaded; + eval { require Test::Exception; Test::Exception->import; }; + skip 'need Test::Exception', 18 unless defined $Test::Exception::VERSION; + # new throws_ok(sub { Language::Befunge::Vector->new() }, qr/Usage/, "Vector->new needs a defined 'dimensions' argument"); @@ -228,10 +217,5 @@ SKIP: { throws_ok(sub { $tref_v != $bef_v }, qr/uneven dimensions/, "misaligned vector arithmetic (!=)"); } -BEGIN { $tests += 18 }; - - - -BEGIN { plan tests => $tests }; -- 2.11.4.GIT