Changeset 1647
- Timestamp:
- 09/02/06 06:55:07
- trunk/plagger (modified) (previous)
- trunk/plagger/t/TestPlagger.pm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/plagger/t/TestPlagger.pm
r1641 r1647 24 24 } 25 25 26 =item test_requires 27 28 Checks 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 33 If this fails rather than failing tests this B<skips all tests>. 34 35 =cut 36 26 37 sub test_requires() { 27 38 my($mod, $ver) = @_; … … 43 54 } 44 55 56 =item has_network($spec) 57 58 Returns true if and only if the specified port can be established. The 59 spec should be of the form: 60 61 hostname:port 62 63 e.g. 64 65 plagger.org:80 66 67 This function always returns false immediatly without connecting to the 68 network if the enviroment varible C<NO_NETWORK> has been set. 69 70 =cut 71 45 72 sub has_network() { 46 73 my $host = shift; … … 52 79 } 53 80 81 =item test_requires_network 82 83 This 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 54 96 sub test_requires_network() { 55 97 my $host = shift || 'www.google.com:80'; … … 60 102 } 61 103 } 104 105 =item test_requires_command($command) 106 107 This function skips all tests if the given command 108 doesn't exist in your path (i.e. in the dirs in the PATH enviroment 109 variable.) 110 111 =cut 62 112 63 113 sub test_requires_command() { … … 71 121 } 72 122 123 =item test_plugin_deps 124 125 This function skips all tests if the module's requirements 126 (modules, versions, platforms, bundles) aren't installed. 127 128 If you pass an argument then it will check the requirement 129 for that module: 130 131 # this will check the Foo-Bar.yaml file for deps 132 test_plugin_deps("Foo::Bar"); 133 134 Called with no arguments it works out magically the name of 135 the plugin based on the directory the test file is located 136 in. 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 142 The requirements are defined in YAML files located 143 in the C<deps> directory inside the Plagger directory. A typical 144 YAML 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 153 Or 154 155 name: Subscription::Bookmarks::Mozilla 156 author: youpy 157 bundles: 158 - Subscription::XPath 159 160 =cut 161 73 162 sub test_plugin_deps() { 74 163 my($mod, $no_warning) = @_; … … 98 187 } 99 188 189 =item run_eval_expected 190 191 Add a new test run across all blocks to check that 192 the expected blocks can be evaled succesfully. During 193 these evaluations the expected input is availible from 194 C<$context>. 195 196 One extra test failure will happen per block that's expected 197 output throws an error when evaluated. No successes are 198 generated by this code, but the expected code may in 199 turn generate many sucesses or failures. 200 201 =cut 202 100 203 sub run_eval_expected { 101 204 run { 102 205 my $block = shift; 206 207 # context is being pulled out here so that 208 # the eval box can see it 103 209 my $context = $block->input; # it's not always true 210 104 211 eval $block->expected; 105 212 fail $@ if $@; … … 107 214 } 108 215 216 =item run_eval_expected_with_capture 217 218 Add new test run across all blocks to check that 219 the expected blocks can be evaled succesfully. During 220 these evaluations the expected input is availible from 221 C<$context>, and warnings created by the filters 222 are avalible from C<$warnings>. 223 224 =cut 225 109 226 sub run_eval_expected_with_capture { 110 227 filters_delay; 111 228 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) 112 233 my $warning; 113 234 { … … 115 236 $block->run_filters; 116 237 } 238 239 # context is being pulled out here so that 240 # the eval box can see it 117 241 my $context = $block->input; 242 118 243 eval $block->expected; 119 244 fail $@ if $@; 120 245 } 121 246 } 247 248 =item slurp_file($filename) 249 250 Returns the contents of the file, as a single scalar 251 252 =cut 122 253 123 254 sub slurp_file() {
