Changeset 21777 for lang/perl/Test-Classy
- Timestamp:
- 10/21/08 14:54:19 (5 years ago)
- Location:
- lang/perl/Test-Classy/trunk
- Files:
-
- 17 modified
-
Changes (modified) (1 diff)
-
lib/Test/Classy.pm (modified) (1 diff)
-
lib/Test/Classy/Base.pm (modified) (14 diffs)
-
t/lib/Test/Classy/Test/Basic/Plain.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Basic/Skip.pm (modified) (4 diffs)
-
t/lib/Test/Classy/Test/Basic/SkipClass.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Basic/SkipClassDeprecated.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Basic/Todo.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Inherit/Base.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Inherit/IgnoreMe.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Inherit/More.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Inherit/UseFurther.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Limit/Basic.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/Limit/WithoutTarget.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/NoPlan/NoPlan.pm (modified) (2 diffs)
-
t/lib/Test/Classy/Test/OSTest/NotWin.pm (modified) (1 diff)
-
t/lib/Test/Classy/Test/OSTest/Win.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Test-Classy/trunk/Changes
r17018 r21777 1 1 Revision history for Test-Classy 2 3 0.04 2008/10/21 4 - added $class->message to prepend test/class names to 5 a test message to make it easier to see which test 6 comes from which class. 2 7 3 8 0.03 2008/08/03 -
lang/perl/Test-Classy/trunk/lib/Test/Classy.pm
r17018 r21777 6 6 use Sub::Install qw( install_sub ); 7 7 8 our $VERSION = '0.0 3';8 our $VERSION = '0.04'; 9 9 10 10 my @tests; -
lang/perl/Test-Classy/trunk/lib/Test/Classy/Base.pm
r17018 r21777 78 78 79 79 my $tests = $class->_tests; 80 my $reason = ' tests only ' . ( join ', ', @monikers );80 my $reason = 'limited by attributes'; 81 81 82 82 LOOP: … … 121 121 my %sym = $class->_find_symbols; 122 122 123 $class->test_name( undef ); 124 123 125 $class->initialize(@args); 124 126 … … 129 131 130 132 if ( my $reason = $class->_should_skip_this_class ) { 131 SKIP: { Test::More::skip $ reason, $tests->{$name}->{plan}; }133 SKIP: { Test::More::skip $class->message($reason), $tests->{$name}->{plan}; } 132 134 next; 133 135 } … … 152 154 if ( exists $test->{Skip} ) { # todo skip 153 155 TODO: { 154 Test::More::todo_skip $ reason, $test->{plan};156 Test::More::todo_skip $class->message($reason), $test->{plan}; 155 157 } 156 158 } … … 158 160 TODO: { 159 161 no strict 'refs'; 160 local ${"$class\::TODO"} = $ reason; # perl 5.6.2 hates this162 local ${"$class\::TODO"} = $class->message($reason); # perl 5.6.2 hates this 161 163 162 164 $class->__run_test($test, @args); … … 169 171 ? $test->{Skip} 170 172 : "skipped $name"; 171 SKIP: { Test::More::skip $ reason, $test->{plan}; }173 SKIP: { Test::More::skip $class->message($reason), $test->{plan}; } 172 174 return; 173 175 } … … 188 190 if ( $rest ) { 189 191 for ( 1 .. $rest ) { 190 Test::More->builder->skip( $ reason);192 Test::More->builder->skip( $class->message($reason) ); 191 193 } 192 194 } … … 238 240 } 239 241 242 sub message { 243 my ($class, $message) = @_; 244 245 return $class->_prepend_class_name( $class->_prepend_test_name( $message ) ); 246 } 247 248 sub _prepend_test_name { 249 my ($class, $message) = @_; 250 251 $message = '' unless defined $message; 252 253 if ( my $name = $class->test_name ) { 254 $message = "$name: $message" unless $message =~ /\b$name\b/; 255 } 256 257 return $message; 258 } 259 260 sub _prepend_class_name { 261 my ($class, $message) = @_; 262 263 $message = '' unless defined $message; 264 265 if ( my ($name) = $class =~ /(\w+)$/ ) { 266 $message = "$name: $message" unless $message =~ /\b$name\b/; 267 } 268 269 return $message; 270 } 271 240 272 sub initialize {} 241 273 sub finalize {} … … 269 301 sub mytest : Test { 270 302 my $class = shift; 271 ok $class->model->find('something'), $class-> test_name." works";303 ok $class->model->find('something'), $class->message('works'); 272 304 } 273 305 … … 275 307 my $class = shift; 276 308 277 pass 'this test';309 pass $class->message('this test'); 278 310 279 311 return $class->abort_this_test('for some reason'); 280 312 281 fail 'this test';313 fail $class->message('this test'); 282 314 } 283 315 … … 296 328 =head2 skip_this_class ( skip_the_rest -- deprecated ) 297 329 298 If you called this with a reason why you want to skip (unsupported OS or lack of modules, for example), all the tests in the package will be skipped. Note that this is useful in the initialize phase. You need to use good old 'skip' and 'Skip:' block when you want to skip some of the tests in a test unit.330 If you called this with a reason why you want to skip (unsupported OS or lack of modules, for example), all the tests in the package will be skipped. Note that this is only useful in the initialize phase. You need to use good old 'skip' and 'Skip:' block when you want to skip some of the tests in a test unit. 299 331 300 332 sub some_test : Tests(2) { … … 334 366 =head2 initialize 335 367 336 This is called before the tests run s. You might want to set up database or something like that here. You can store initialized thingy as a class data (via Class::Data::Inheritable), or as a package-wide variable, maybe. Note that you can set up thingy in a test script and pass it as an argument for each of the tests instead.368 This is called before the tests run. You might want to set up database or something like that here. You can store initialized thingy as a class data (via Class::Data::Inheritable), or as a package-wide variable, maybe. Note that you can set up thingy in a test script and pass it as an argument for each of the tests instead. 337 369 338 370 =head2 finalize … … 343 375 344 376 returns the name of the test running currently. Handy to write a meaningful test message. 377 378 =head2 message 379 380 prepends the last bit of the class name, and the test name currently running if any, to a message. 345 381 346 382 =head2 dump … … 384 420 sub not_for_base : Test { pass 'for children only' }; 385 421 422 =head1 CAVEATS 423 424 Beware if you want to inherit only some of the tests from a base class (to remove or replace others). All the tests with a C<Test(s)> attribute will be counted while calculating the test plan (i.e. both the ones to replace and the ones to be replaced will be counted). The simplest remedy to avoid a plan error is to use C<no_plan> obviously, but you may find it better to split the class into the mandatory one, and the one which may be skipped while initializing. 425 386 426 =head1 AUTHOR 387 427 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/Plain.pm
r14993 r21777 6 6 7 7 sub plain_1 : Test { 8 pass "first test"; 8 my $class = shift; 9 pass $class->message("first test"); 9 10 } 10 11 11 12 sub plain_2 : Tests(2) { 12 pass "second test"; 13 pass "third test"; 13 my $class = shift; 14 pass $class->message("second test"); 15 pass $class->message("third test"); 14 16 } 15 17 16 18 sub plain_3 : Tests(3) { 17 pass "fourth test"; 18 pass "fifth test"; 19 pass "sixth test"; 19 my $class = shift; 20 pass $class->message("fourth test"); 21 pass $class->message("fifth test"); 22 pass $class->message("sixth test"); 20 23 } 21 24 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/Skip.pm
r17018 r21777 6 6 7 7 sub skip_1 : Test Skip { 8 fail "but this is to be skipped: 1-1"; 8 my $class = shift; 9 fail $class->message("but this is to be skipped: 1-1"); 9 10 } 10 11 11 12 sub skip_2 : Test(2) Skip { 12 fail "but this is to be skipped: 2-1"; 13 fail "but this is to be skipped: 2-2"; 13 my $class = shift; 14 fail $class->message("but this is to be skipped: 2-1"); 15 fail $class->message("but this is to be skipped: 2-2"); 14 16 } 15 17 16 18 sub skip_3 : Tests(3) Skip(skipped by attribute) { 17 fail "but this is to be skipped: 3-1"; 18 fail "but this is to be skipped: 3-2"; 19 fail "but this is to be skipped: 3-3"; 19 my $class = shift; 20 fail $class->message("but this is to be skipped: 3-1"); 21 fail $class->message("but this is to be skipped: 3-2"); 22 fail $class->message("but this is to be skipped: 3-3"); 20 23 } 21 24 22 25 sub skip_4_partly : Tests(3) { 23 pass "this should pass"; 26 my $class = shift; 27 pass $class->message("this should pass"); 24 28 25 29 SKIP: { 26 skip 'skip inside a test', 1;27 fail "but this is to be skipped";30 skip $class->message('skip inside a test'), 1; 31 fail $class->message("but this is to be skipped"); 28 32 } 29 33 30 pass "this should pass, too";34 pass $class->message("this should pass, too"); 31 35 } 32 36 … … 34 38 my $class = shift; 35 39 36 pass 'pass';40 pass $class->message('pass'); 37 41 38 42 return $class->abort_this_test('aborted'); 39 43 40 fail 'but this is to be skipped: 5-1';44 fail $class->message('but this is to be skipped: 5-1'); 41 45 } 42 46 … … 44 48 my $class = shift; 45 49 46 pass 'pass';50 pass $class->message('pass'); 47 51 48 52 # this is the alias of abort_this_test 49 53 return $class->skip_this_test; 50 54 51 fail 'but this is to be skipped: 6-1';55 fail $class->message('but this is to be skipped: 6-1'); 52 56 } 53 57 … … 55 59 my $class = shift; 56 60 57 pass 'pass';61 pass $class->message('pass'); 58 62 59 63 return $class->abort_this_test('actually not aborted'); -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/SkipClass.pm
r17018 r21777 12 12 13 13 sub failing_test : Test { 14 fail "but this is to be skipped"; 14 my $class = shift; 15 16 fail $class->message("but this is to be skipped"); 15 17 } 16 18 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/SkipClassDeprecated.pm
r17018 r21777 13 13 14 14 sub failing_test2 : Test { 15 fail "but this is to be skipped"; 15 my $class = shift; 16 17 fail $class->message("but this is to be skipped"); 16 18 } 17 19 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/Todo.pm
r17018 r21777 6 6 7 7 sub todo_1 : Test TODO { 8 fail "but this is a todo test: 1-1"; 8 my $class = shift; 9 10 fail $class->message("but this is a todo test: 1-1"); 9 11 } 10 12 11 13 sub todo_2 : Test(2) TODO { 12 fail "but this is a todo test: 2-1"; 13 fail "but this is a todo test: 2-2"; 14 my $class = shift; 15 16 fail $class->message("but this is a todo test: 2-1"); 17 fail $class->message("but this is a todo test: 2-2"); 14 18 } 15 19 16 20 sub todo_3 : Tests(3) TODO(skipped by attribute) { 17 fail "but this is a todo test: 3-1"; 18 fail "but this is a todo test: 3-2"; 19 fail "but this is a todo test: 3-3"; 21 my $class = shift; 22 23 fail $class->message("but this is a todo test: 3-1"); 24 fail $class->message("but this is a todo test: 3-2"); 25 fail $class->message("but this is a todo test: 3-3"); 20 26 } 21 27 22 28 sub todo_4 : Tests(3) TODO Skip { 23 fail "but this is a todo test: 4-1"; 24 fail "but this is a todo test: 4-2"; 25 fail "but this is a todo test: 4-3"; 26 fail "but this is a todo test: 4-4"; 29 my $class = shift; 30 31 fail $class->message("but this is a todo test: 4-1"); 32 fail $class->message("but this is a todo test: 4-2"); 33 fail $class->message("but this is a todo test: 4-3"); 34 fail $class->message("but this is a todo test: 4-4"); 27 35 } 28 36 29 37 sub todo_5_partly : Tests(3) { 30 pass "this should pass"; 38 my $class = shift; 39 40 pass $class->message("this should pass"); 31 41 32 42 TODO: { 33 local $TODO = 'this is not implemented';34 fail "this is a todo test";43 local $TODO = $class->message('this is not implemented'); 44 fail $class->message("this is a todo test"); 35 45 } 36 46 37 pass "this should pass, too";47 pass $class->message("this should pass, too"); 38 48 } 39 49 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/Base.pm
r17018 r21777 11 11 my ($class, @args) = @_; 12 12 13 pass "tested ".$class->data; # should be ignored here13 pass $class->message("tested ".$class->data); # should be ignored here 14 14 } 15 15 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/IgnoreMe.pm
r17018 r21777 11 11 my ($class, @args) = @_; 12 12 13 pass "tested ".$class->data; # should be ignored here13 pass $class->message("tested ".$class->data); # should be ignored here 14 14 } 15 15 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/More.pm
r14993 r21777 9 9 10 10 sub more_test : Test { 11 pass "yet another test"; 11 my $class = shift; 12 pass $class->message("yet another test"); 12 13 } 13 14 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/UseFurther.pm
r14993 r21777 8 8 9 9 sub further_test : Test { 10 pass "further test"; 10 my $class = shift; 11 12 pass $class->message("further test"); 11 13 } 12 14 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Limit/Basic.pm
r17018 r21777 6 6 7 7 sub limit_test : Test Target { 8 pass 'this test will be executed'; 8 my $class = shift; 9 10 pass $class->message('this test will be executed'); 9 11 } 10 12 11 13 sub not_targeted : Test { 12 fail 'this test should be skipped'; 14 my $class = shift; 15 16 fail $class->message('this test should be skipped'); 13 17 } 14 18 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Limit/WithoutTarget.pm
r17018 r21777 6 6 7 7 sub not_targeted_at_all : Test { 8 fail 'this test should be skipped'; 8 my $class = shift; 9 10 fail $class->message('this test should be skipped'); 9 11 } 10 12 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/NoPlan/NoPlan.pm
r15510 r21777 6 6 7 7 sub test : Test(no_plan) { 8 pass 'no plan'; 8 my $class = shift; 9 10 pass $class->message('no plan'); 9 11 } 10 12 11 13 sub test2 : Test('no_plan') { 12 pass 'no plan with single quotes'; 14 my $class = shift; 15 16 pass $class->message('no plan with single quotes'); 13 17 } 14 18 15 19 sub test3 : Test("no_plan") { 16 pass 'no plan with double quotes'; 20 my $class = shift; 21 22 pass $class->message('no plan with double quotes'); 17 23 } 18 24 … … 20 26 21 27 sub test4 : Test("no_plan') { 22 fail 'quotes mismatch'; 28 my $class = shift; 29 30 fail $class->message('quotes mismatch'); 23 31 } 24 32 25 33 sub test5 : Test(no_plan') { 26 fail 'quotes mismatch'; 34 my $class = shift; 35 36 fail $class->message('quotes mismatch'); 27 37 } 28 38 29 39 sub test6 : Test(no_plan") { 30 fail 'quotes mismatch'; 40 my $class = shift; 41 42 fail $class->message('quotes mismatch'); 31 43 } 32 44 33 45 sub test7 : Test(noplan) { 34 fail 'bad plan name'; 46 my $class = shift; 47 48 fail $class->message('bad plan name'); 35 49 } 36 50 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/OSTest/NotWin.pm
r15510 r21777 15 15 sub not_for_win : Test { 16 16 my $class = shift; 17 pass $class-> test_name;17 pass $class->message; 18 18 } 19 19 -
lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/OSTest/Win.pm
r15510 r21777 15 15 sub win_only : Test { 16 16 my $class = shift; 17 pass $class-> test_name;17 pass $class->message; 18 18 } 19 19
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)