Changeset 1647

Show
Ignore:
Timestamp:
09/02/06 06:55:07
Author:
mark
Message:

r12@travis: mark | 2006-09-01 20:54:58 +0100

added some documentation to the Test
Base extention

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/t/TestPlagger.pm

    r1641 r1647  
    2424} 
    2525 
     26=item test_requires 
     27 
     28Checks to see if the module can be loaded. 
     29 
     30   test_requires("Your::Momma"); 
     31   test_requires("Your::Momma",3.141); # version 3.141 or later 
     32 
     33If this fails rather than failing tests this B<skips all tests>. 
     34 
     35=cut 
     36 
    2637sub test_requires() { 
    2738    my($mod, $ver) = @_; 
     
    4354} 
    4455 
     56=item has_network($spec) 
     57 
     58Returns true if and only if the specified port can be established.  The 
     59spec should be of the form: 
     60 
     61  hostname:port 
     62 
     63e.g. 
     64 
     65  plagger.org:80 
     66 
     67This function always returns false immediatly without connecting to the 
     68network if the enviroment varible C<NO_NETWORK> has been set. 
     69 
     70=cut 
     71 
    4572sub has_network() { 
    4673    my $host = shift; 
     
    5279} 
    5380 
     81=item test_requires_network 
     82 
     83This function skips all tests if the network is not reachable, e.g. 
     84 
     85  # can I reach google's web site? 
     86  test_requires_network(); 
     87   
     88  # can I reach plagger's web site? 
     89  test_requires_network("plagger.org") 
     90   
     91  # can I reach a different port? 
     92  test_requires_network("gmail.com:443"); 
     93 
     94=cut 
     95 
    5496sub test_requires_network() { 
    5597    my $host = shift || 'www.google.com:80'; 
     
    60102    } 
    61103} 
     104 
     105=item test_requires_command($command) 
     106 
     107This function skips all tests if the given command 
     108doesn't exist in your path (i.e. in the dirs in the PATH enviroment 
     109variable.) 
     110 
     111=cut 
    62112 
    63113sub test_requires_command() { 
     
    71121} 
    72122 
     123=item test_plugin_deps 
     124 
     125This function skips all tests if the module's requirements 
     126(modules, versions, platforms, bundles) aren't installed. 
     127 
     128If you pass an argument then it will check the requirement 
     129for that module: 
     130 
     131  # this will check the Foo-Bar.yaml file for deps 
     132  test_plugin_deps("Foo::Bar"); 
     133 
     134Called with no arguments it works out magically the name of 
     135the plugin based on the directory the test file is located 
     136in. 
     137 
     138   # in the Foo-Bar/wobble.t file 
     139   # this will check the Foo-Bar.yaml file for deps    
     140   test_plugin_deps(); 
     141   
     142The requirements are defined in YAML files located 
     143in the C<deps> directory inside the Plagger directory.  A typical 
     144YAML file looks like this: 
     145 
     146  name: Publish::Speech::MacOSX 
     147  author: Ryo Okamoto 
     148  platform: darwin 
     149  depends:  
     150    Mac::Files: 0 
     151    Mac::Speech: 0 
     152 
     153Or 
     154 
     155  name: Subscription::Bookmarks::Mozilla 
     156  author: youpy 
     157  bundles: 
     158    - Subscription::XPath 
     159 
     160=cut 
     161 
    73162sub test_plugin_deps() { 
    74163    my($mod, $no_warning) = @_; 
     
    98187} 
    99188 
     189=item run_eval_expected 
     190 
     191Add a new test run across all blocks to check that 
     192the expected blocks can be evaled succesfully.  During 
     193these evaluations the expected input is availible from 
     194C<$context>. 
     195 
     196One extra test failure will happen per block that's expected 
     197output throws an error when evaluated.  No successes are 
     198generated by this code, but the expected code may in 
     199turn generate many sucesses or failures. 
     200 
     201=cut 
     202 
    100203sub run_eval_expected { 
    101204    run { 
    102205        my $block = shift; 
     206         
     207        # context is being pulled out here so that 
     208        # the eval box can see it 
    103209        my $context = $block->input; # it's not always true 
     210         
    104211        eval $block->expected; 
    105212        fail $@ if $@; 
     
    107214} 
    108215 
     216=item run_eval_expected_with_capture 
     217 
     218Add new test run across all blocks to check that 
     219the expected blocks can be evaled succesfully.  During 
     220these evaluations the expected input is availible from 
     221C<$context>, and warnings created by the filters 
     222are avalible from C<$warnings>. 
     223 
     224=cut 
     225 
    109226sub run_eval_expected_with_capture { 
    110227    filters_delay; 
    111228    for my $block (blocks) { 
     229       
     230        # capture all the warnings from the filters 
     231        # this is often used in the tests as a way to find 
     232        # out what has happened (e.g. the Growl plugin) 
    112233        my $warning; 
    113234        { 
     
    115236            $block->run_filters; 
    116237        } 
     238         
     239        # context is being pulled out here so that 
     240        # the eval box can see it 
    117241        my $context = $block->input; 
     242         
    118243        eval $block->expected; 
    119244        fail $@ if $@; 
    120245    } 
    121246} 
     247 
     248=item slurp_file($filename) 
     249 
     250Returns the contents of the file, as a single scalar 
     251 
     252=cut 
    122253 
    123254sub slurp_file() {