Show
Ignore:
Timestamp:
10/21/08 14:54:19 (5 years ago)
Author:
charsbar
Message:

Test-Classy: added $class->message and refined pods and 0.04 -> CPAN

Location:
lang/perl/Test-Classy/trunk
Files:
17 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Test-Classy/trunk/Changes

    r17018 r21777  
    11Revision history for Test-Classy 
     2 
     30.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. 
    27 
    380.03 2008/08/03 
  • lang/perl/Test-Classy/trunk/lib/Test/Classy.pm

    r17018 r21777  
    66use Sub::Install qw( install_sub ); 
    77 
    8 our $VERSION = '0.03'; 
     8our $VERSION = '0.04'; 
    99 
    1010my @tests; 
  • lang/perl/Test-Classy/trunk/lib/Test/Classy/Base.pm

    r17018 r21777  
    7878 
    7979  my $tests = $class->_tests; 
    80   my $reason = 'tests only ' . ( join ', ', @monikers ); 
     80  my $reason = 'limited by attributes'; 
    8181 
    8282LOOP: 
     
    121121  my %sym = $class->_find_symbols; 
    122122 
     123  $class->test_name( undef ); 
     124 
    123125  $class->initialize(@args); 
    124126 
     
    129131 
    130132    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}; } 
    132134      next; 
    133135    } 
     
    152154    if ( exists $test->{Skip} ) {  # todo skip 
    153155      TODO: { 
    154         Test::More::todo_skip $reason, $test->{plan}; 
     156        Test::More::todo_skip $class->message($reason), $test->{plan}; 
    155157      } 
    156158    } 
     
    158160      TODO: { 
    159161        no strict 'refs'; 
    160         local ${"$class\::TODO"} = $reason; # perl 5.6.2 hates this 
     162        local ${"$class\::TODO"} = $class->message($reason); # perl 5.6.2 hates this 
    161163 
    162164        $class->__run_test($test, @args); 
     
    169171      ? $test->{Skip} 
    170172      : "skipped $name"; 
    171     SKIP: { Test::More::skip $reason, $test->{plan}; } 
     173    SKIP: { Test::More::skip $class->message($reason), $test->{plan}; } 
    172174    return; 
    173175  } 
     
    188190    if ( $rest ) { 
    189191      for ( 1 .. $rest ) { 
    190         Test::More->builder->skip( $reason ); 
     192        Test::More->builder->skip( $class->message($reason) ); 
    191193      } 
    192194    } 
     
    238240} 
    239241 
     242sub message { 
     243  my ($class, $message) = @_; 
     244 
     245  return $class->_prepend_class_name( $class->_prepend_test_name( $message ) ); 
     246} 
     247 
     248sub _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 
     260sub _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 
    240272sub initialize {} 
    241273sub finalize {} 
     
    269301  sub mytest : Test { 
    270302    my $class = shift; 
    271     ok $class->model->find('something'), $class->test_name." works"; 
     303    ok $class->model->find('something'), $class->message('works'); 
    272304  } 
    273305 
     
    275307    my $class = shift; 
    276308 
    277     pass 'this test'; 
     309    pass $class->message('this test'); 
    278310 
    279311    return $class->abort_this_test('for some reason'); 
    280312 
    281     fail 'this test'; 
     313    fail $class->message('this test'); 
    282314  } 
    283315 
     
    296328=head2 skip_this_class ( skip_the_rest -- deprecated ) 
    297329 
    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. 
     330If 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. 
    299331 
    300332  sub some_test : Tests(2) { 
     
    334366=head2 initialize 
    335367 
    336 This is called before the tests runs. 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. 
     368This 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. 
    337369 
    338370=head2 finalize 
     
    343375 
    344376returns the name of the test running currently. Handy to write a meaningful test message. 
     377 
     378=head2 message 
     379 
     380prepends the last bit of the class name, and the test name currently running if any, to a message. 
    345381 
    346382=head2 dump 
     
    384420  sub not_for_base : Test { pass 'for children only' }; 
    385421 
     422=head1 CAVEATS 
     423 
     424Beware 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 
    386426=head1 AUTHOR 
    387427 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/Plain.pm

    r14993 r21777  
    66 
    77sub plain_1 : Test { 
    8   pass "first test"; 
     8  my $class = shift; 
     9  pass $class->message("first test"); 
    910} 
    1011 
    1112sub 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"); 
    1416} 
    1517 
    1618sub 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"); 
    2023} 
    2124 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/Skip.pm

    r17018 r21777  
    66 
    77sub 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"); 
    910} 
    1011 
    1112sub 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"); 
    1416} 
    1517 
    1618sub 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"); 
    2023} 
    2124 
    2225sub skip_4_partly : Tests(3) { 
    23   pass "this should pass"; 
     26  my $class = shift; 
     27  pass $class->message("this should pass"); 
    2428 
    2529  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"); 
    2832  } 
    2933 
    30   pass "this should pass, too"; 
     34  pass $class->message("this should pass, too"); 
    3135} 
    3236 
     
    3438  my $class = shift; 
    3539 
    36   pass 'pass'; 
     40  pass $class->message('pass'); 
    3741 
    3842  return $class->abort_this_test('aborted'); 
    3943 
    40   fail 'but this is to be skipped: 5-1'; 
     44  fail $class->message('but this is to be skipped: 5-1'); 
    4145} 
    4246 
     
    4448  my $class = shift; 
    4549 
    46   pass 'pass'; 
     50  pass $class->message('pass'); 
    4751 
    4852  # this is the alias of abort_this_test 
    4953  return $class->skip_this_test; 
    5054 
    51   fail 'but this is to be skipped: 6-1'; 
     55  fail $class->message('but this is to be skipped: 6-1'); 
    5256} 
    5357 
     
    5559  my $class = shift; 
    5660 
    57   pass 'pass'; 
     61  pass $class->message('pass'); 
    5862 
    5963  return $class->abort_this_test('actually not aborted'); 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/SkipClass.pm

    r17018 r21777  
    1212 
    1313sub 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"); 
    1517} 
    1618 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/SkipClassDeprecated.pm

    r17018 r21777  
    1313 
    1414sub 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"); 
    1618} 
    1719 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Basic/Todo.pm

    r17018 r21777  
    66 
    77sub 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"); 
    911} 
    1012 
    1113sub 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"); 
    1418} 
    1519 
    1620sub 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"); 
    2026} 
    2127 
    2228sub 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"); 
    2735} 
    2836 
    2937sub todo_5_partly : Tests(3) { 
    30   pass "this should pass"; 
     38  my $class = shift; 
     39 
     40  pass $class->message("this should pass"); 
    3141 
    3242  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"); 
    3545  } 
    3646 
    37   pass "this should pass, too"; 
     47  pass $class->message("this should pass, too"); 
    3848} 
    3949 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/Base.pm

    r17018 r21777  
    1111  my ($class, @args) = @_; 
    1212 
    13   pass "tested ".$class->data; # should be ignored here 
     13  pass $class->message("tested ".$class->data); # should be ignored here 
    1414} 
    1515 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/IgnoreMe.pm

    r17018 r21777  
    1111  my ($class, @args) = @_; 
    1212 
    13   pass "tested ".$class->data; # should be ignored here 
     13  pass $class->message("tested ".$class->data); # should be ignored here 
    1414} 
    1515 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/More.pm

    r14993 r21777  
    99 
    1010sub more_test : Test { 
    11   pass "yet another test"; 
     11  my $class = shift; 
     12  pass $class->message("yet another test"); 
    1213} 
    1314 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Inherit/UseFurther.pm

    r14993 r21777  
    88 
    99sub further_test : Test { 
    10   pass "further test"; 
     10  my $class = shift; 
     11 
     12  pass $class->message("further test"); 
    1113} 
    1214 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Limit/Basic.pm

    r17018 r21777  
    66 
    77sub 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'); 
    911} 
    1012 
    1113sub not_targeted : Test { 
    12   fail 'this test should be skipped'; 
     14  my $class = shift; 
     15 
     16  fail $class->message('this test should be skipped'); 
    1317} 
    1418 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/Limit/WithoutTarget.pm

    r17018 r21777  
    66 
    77sub 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'); 
    911} 
    1012 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/NoPlan/NoPlan.pm

    r15510 r21777  
    66 
    77sub test : Test(no_plan) { 
    8   pass 'no plan'; 
     8  my $class = shift; 
     9 
     10  pass $class->message('no plan'); 
    911} 
    1012 
    1113sub 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'); 
    1317} 
    1418 
    1519sub 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'); 
    1723} 
    1824 
     
    2026 
    2127sub test4 : Test("no_plan') { 
    22   fail 'quotes mismatch'; 
     28  my $class = shift; 
     29 
     30  fail $class->message('quotes mismatch'); 
    2331} 
    2432 
    2533sub test5 : Test(no_plan') { 
    26   fail 'quotes mismatch'; 
     34  my $class = shift; 
     35 
     36  fail $class->message('quotes mismatch'); 
    2737} 
    2838 
    2939sub test6 : Test(no_plan") { 
    30   fail 'quotes mismatch'; 
     40  my $class = shift; 
     41 
     42  fail $class->message('quotes mismatch'); 
    3143} 
    3244 
    3345sub test7 : Test(noplan) { 
    34   fail 'bad plan name'; 
     46  my $class = shift; 
     47 
     48  fail $class->message('bad plan name'); 
    3549} 
    3650 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/OSTest/NotWin.pm

    r15510 r21777  
    1515sub not_for_win : Test { 
    1616  my $class = shift; 
    17   pass $class->test_name; 
     17  pass $class->message; 
    1818} 
    1919 
  • lang/perl/Test-Classy/trunk/t/lib/Test/Classy/Test/OSTest/Win.pm

    r15510 r21777  
    1515sub win_only : Test { 
    1616  my $class = shift; 
    17   pass $class->test_name; 
     17  pass $class->message; 
    1818} 
    1919