| 1 |
NAME |
| 2 |
Test::NoBreakpoints - test that files do not contain soft breakpoints |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Test::NoBreakpoints; |
| 6 |
plan tests => $num_tests; |
| 7 |
no_breakpoints_ok( $file, 'Contains no soft breakpoints' ); |
| 8 |
|
| 9 |
Module authors can include the following in a t/nobreakpoints.t file to |
| 10 |
add such checking to a module distribution: |
| 11 |
|
| 12 |
use Test::More; |
| 13 |
eval "use Test::NoBreakpoints 0.10"; |
| 14 |
plan skip_all => "Test::NoBreakpoints 0.10 required for testing" if $@; |
| 15 |
all_files_no_breakpoints_ok(); |
| 16 |
|
| 17 |
DESCRIPTION |
| 18 |
I love soft breakpoints ("$DB::single = 1") in the Perl debugger. |
| 19 |
Unfortunately, I have a habit of putting them in my code during |
| 20 |
development and forgetting to take them out before I upload it to CPAN, |
| 21 |
necessitating a hasty fix/package/bundle cycle followed by much cursing. |
| 22 |
|
| 23 |
Test::NoBreakpoints checks that files contain neither the string |
| 24 |
"$DB::single = 1" nor "$DB::signal = 1". By adding such a test to all my |
| 25 |
modules, I swear less and presumably lighten the load on the CPAN in |
| 26 |
some small way. |
| 27 |
|
| 28 |
FUNCTIONS |
| 29 |
Unless otherwise noted, all functions are tests built on top of |
| 30 |
Test::Builder, so the standard admonition about having made a plan |
| 31 |
before you run them apply. |
| 32 |
|
| 33 |
no_breakpoints_ok($file, [$description] ) |
| 34 |
Checks that $file contains no breakpoints. If the optional $description |
| 35 |
is not passed it defaults to "no breakpoint test of $file". |
| 36 |
|
| 37 |
If the test fails, the line number of the file where the breakpoint was |
| 38 |
found will be emitted. |
| 39 |
|
| 40 |
For compatibility with old versions of this module, the deprecated name |
| 41 |
"no_brkpts_ok" may also be used (but see "DEPRECATED FUNCTIONS"). |
| 42 |
|
| 43 |
all_perl_files( [@dirs] ) |
| 44 |
Returns a list of all *.pl, *.pm and *.t files in the directories |
| 45 |
listed. If @dirs is not passed, defaults to "blib" and "t". |
| 46 |
|
| 47 |
The order of the files returned is machine-dependent. If you want them |
| 48 |
sorted, you'll have to sort them yourself. |
| 49 |
|
| 50 |
all_files_no_breakpoints_ok( [@files] ) |
| 51 |
Checks all files that look like they contain Perl using |
| 52 |
no_breakpoints_ok(). If @files is not provided, it defaults to the |
| 53 |
return of all_perl_files(). |
| 54 |
|
| 55 |
For compatibility with old versions of this module, the deprecated name |
| 56 |
"all_files_no_brkpts_ok" may also be used (but see "DEPRECATED |
| 57 |
FUNCTIONS"). |
| 58 |
|
| 59 |
EXPORTS |
| 60 |
By default all_files_no_breakpoints_ok and no_breakpoints_ok. |
| 61 |
|
| 62 |
For the time being, the deprecated forms the above |
| 63 |
(all_files_no_brkpts_ok and no_brkpts_ok) are also exported (but see |
| 64 |
"DEPRECATED FUNCTIONS"). |
| 65 |
|
| 66 |
On request, all_perl_files. |
| 67 |
|
| 68 |
Everything with the tag :all. |
| 69 |
|
| 70 |
DEPRECATED FUNCTIONS |
| 71 |
Prior to v0.13 of this module, no_breakpoints_ok was called no_brkpts_ok |
| 72 |
and all_files_no_breakpoints_ok was similarly abbreviated. |
| 73 |
|
| 74 |
In v0.13, these older names were deprecated. They are still exported by |
| 75 |
default, but will emit a warning unless you disable the deprecated |
| 76 |
lexical warning category: |
| 77 |
|
| 78 |
{ |
| 79 |
no warnings 'deprecated'; |
| 80 |
no_brkpts_ok(...); |
| 81 |
} |
| 82 |
|
| 83 |
In the next release, the deprecated functions will have to be pulled in |
| 84 |
via an import tag. In the release after that, they will cease to be. |
| 85 |
|
| 86 |
ACKNOWLEDGEMENTS |
| 87 |
Michael Schwern for Test::Builder. |
| 88 |
|
| 89 |
Andy Lester for Test::Pod, which is where I got the idea and borrowed |
| 90 |
the logic of all_perl_files from. |
| 91 |
|
| 92 |
BUGS |
| 93 |
* doesn't catch some breakpoints |
| 94 |
|
| 95 |
This is a valid breakpoint: |
| 96 |
|
| 97 |
package DB; |
| 98 |
$single = 1; |
| 99 |
package main; |
| 100 |
|
| 101 |
as is this: |
| 102 |
|
| 103 |
my $break = \$DB::single; |
| 104 |
$$break = 1; |
| 105 |
|
| 106 |
but neither are currently caught. |
| 107 |
|
| 108 |
TODO |
| 109 |
* enhance regex to find esoteric setting of breakpoints |
| 110 |
|
| 111 |
If you have a legitimate breakpoint set that isn't caught, please |
| 112 |
send me an example and I'll try to augment the regex to match it. |
| 113 |
|
| 114 |
* only look at code rather than the entire file |
| 115 |
|
| 116 |
This is not as easy as simply stripping out POD, because there might |
| 117 |
be inline tests or examples that are code in there (using |
| 118 |
Test::Inline). Granted, those should be caught when the generated .t |
| 119 |
files are themselves tested, but I'd like to make it smarter. |
| 120 |
|
| 121 |
* not use regular expressions |
| 122 |
|
| 123 |
The ideal way to find a breakpoint would be to compile the code and |
| 124 |
then walk the opcode tree to find places where the breakpoint is |
| 125 |
set. B::FindAmpersand does something similar to this to find use of |
| 126 |
the $& in regular expressions, so this is probably the direction I'm |
| 127 |
going to head in. |
| 128 |
|
| 129 |
SEE ALSO |
| 130 |
Test::Builder |
| 131 |
|
| 132 |
Test::Pod |
| 133 |
|
| 134 |
AUTHORS |
| 135 |
* James FitzGibbon <[email protected]> |
| 136 |
|
| 137 |
* Apocalypse <[email protected]> |
| 138 |
|
| 139 |
* Chisel <[email protected]> |
| 140 |
|
| 141 |
COPYRIGHT AND LICENSE |
| 142 |
This software is copyright (c) 2012 by James FitzGibbon and Chisel |
| 143 |
Wright. |
| 144 |
|
| 145 |
This is free software; you can redistribute it and/or modify it under |
| 146 |
the same terms as the Perl 5 programming language system itself. |
| 147 |
|