| 1 | package Badger::Test; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 70 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 70 | ▶ | use Badger; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | use Badger::Class | ||||||||||||||||||||||||||||||
| 6 | version => 0.01, | ||||||||||||||||||||||||||||||
| 7 | base => 'Badger::Base', | ||||||||||||||||||||||||||||||
| 8 | import => 'CLASS class', | ||||||||||||||||||||||||||||||
| 9 | constants => 'ARRAY DELIMITER PKG', | ||||||||||||||||||||||||||||||
| 10 | words => 'DEBUG DEBUG_MODULES', | ||||||||||||||||||||||||||||||
| 11 | exports => { | ||||||||||||||||||||||||||||||
| 12 | all => 'plan ok is isnt like unlike pass fail | ||||||||||||||||||||||||||||||
| 13 | skip_some skip_rest skip_all manager', | ||||||||||||||||||||||||||||||
| 14 | after => \&_after_hook, | ||||||||||||||||||||||||||||||
| 15 | hooks => { | ||||||||||||||||||||||||||||||
| 16 | lib => [\&_lib_hook, 1], | ||||||||||||||||||||||||||||||
| 17 | skip => [\&_skip_hook, 1], | ||||||||||||||||||||||||||||||
| 18 | if_env => [\&_if_env_hook, 1], | ||||||||||||||||||||||||||||||
| 19 | debug => \&_debug_hook, | ||||||||||||||||||||||||||||||
| 20 | 70 | map { $_ => \&_export_hook } | |||||||||||||||||||||||||||||
| 21 | qw( summary colour color args tests ) | ||||||||||||||||||||||||||||||
| 22 | }, | ||||||||||||||||||||||||||||||
| 23 | 70 | ▶ | }; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 70 | ▶ | use Badger::Debug; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 26 | 70 | ▶ | use Badger::Exception; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 27 | 70 | ▶ | use Badger::Test::Manager; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 28 | 70 | our $MANAGER = 'Badger::Test::Manager'; | |||||||||||||||||||||||||||||
| 29 | 70 | our $DEBUGGER = 'Badger::Debug'; | |||||||||||||||||||||||||||||
| 30 | 70 | our $EXCEPTION = 'Badger::Exception'; | |||||||||||||||||||||||||||||
| 31 | 70 | our ($ALL, $IF_ENV, $DEBUG, $DEBUG_MODULES); | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 70 | *color = \&colour; | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | sub _lib_hook { | ||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | Badger->lib($_[3]); | ||||||||||||||||||||||||||||
|
Subroutine
_lib_hook: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | sub _skip_hook { | ||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | $MANAGER->skip_all($_[3]); | ||||||||||||||||||||||||||||
|
Subroutine
_skip_hook: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | sub _if_env_hook { | ||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | my $vars = $_[3]; | ||||||||||||||||||||||||||||
|
Subroutine
_if_env_hook: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | $IF_ENV = $vars eq ARRAY | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 47 | ? $vars | ||||||||||||||||||||||||||||||
| 48 | : [ split(DELIMITER, $vars) ] | ||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | sub _export_hook { | ||||||||||||||||||||||||||||||
| 52 | 126 | ▶ | my ($class, $target, $key, $symbols) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_export_hook: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||
| 53 | 126 | ▶ | croak "You didn't specify a value for the '$key' load option" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 54 | unless @$symbols; | ||||||||||||||||||||||||||||||
| 55 | 126 | $class->$key(shift @$symbols); | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | sub _debug_hook { | ||||||||||||||||||||||||||||||
| 59 | 64 | ▶ | my ($class, $target, $key, $symbols, $import) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_debug_hook: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||
| 60 | 64 | ▶ | croak "You didn't specify any values for the 'debug' load option.\n" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 61 | unless @$symbols; | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | # define $DEBUG in caller | ||||||||||||||||||||||||||||||
| 65 | 70 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 66 | 64 | *{ $target.PKG.DEBUG } = \$DEBUG; | |||||||||||||||||||||||||||||
| 67 | 64 | ▶ | *{ $target.PKG.DEBUG } = sub { $DEBUG }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | # set $DEBUG_MODULE in this class to contain the argument passed - a list | ||||||||||||||||||||||||||||||
| 70 | # of class names to enable $DEBUG in when/if debugging is enabled | ||||||||||||||||||||||||||||||
| 71 | 64 | my $modules = shift @$symbols; | |||||||||||||||||||||||||||||
| 72 | 64 | ▶ | return unless $modules; # zero/false for no debugging | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 73 | 64 | $class->debug_modules($modules); | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | sub _after_hook { | ||||||||||||||||||||||||||||||
| 77 | 98 | ▶ | my ($class, $target) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_after_hook: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | # See if we've got any constraints specified and assert that they're | ||||||||||||||||||||||||||||||
| 80 | # met. If the --all command line parameter is specified (which sets | ||||||||||||||||||||||||||||||
| 81 | # $ALL) then we run the tests regardless | ||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 98 | ▶ | if ($IF_ENV && ! $ALL) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Badger::Test::IF_ENV and not $Badger::Test::ALL
MC/DC50%1/2
$Badger::Test::IF_ENV and not $Badger::Test::ALL
$Badger::Test::IF_ENV
not $Badger::Test::ALL
Truth table66%2/3
A and not(B)
A= $Badger::Test::IF_ENVB= not $Badger::Test::ALL
| |||||||||||||||||||||||||||||||
| 84 | 2 | my $run = 0; | |||||||||||||||||||||||||||||
| 85 | 2 | my @names = @$IF_ENV; | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | 2 | foreach my $var (@names) { | |||||||||||||||||||||||||||||
| 88 | 3 | ▶ | $run++, last if $ENV{$var}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | unless ($run) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 91 | 1 | my $name = pop(@names); | |||||||||||||||||||||||||||||
| 92 | 1 | $name = join(' or ', join(', ', @names), $name); | |||||||||||||||||||||||||||||
| 93 | 1 | $MANAGER->skip_all("Tests only apply for $name"); | |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | sub manager { | ||||||||||||||||||||||||||||||
| 99 | 1702 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||
|
Subroutine
manager: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 100 | return @_ | ||||||||||||||||||||||||||||||
| 101 | 1702 | ▶ | ? ($MANAGER = shift) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 102 | : $MANAGER; | ||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | sub colour { | ||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | shift; | ||||||||||||||||||||||||||||
|
Subroutine
colour: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 107 | 0 | manager->colour(@_); | |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | sub summary { | ||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | shift; | ||||||||||||||||||||||||||||
|
Subroutine
summary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 112 | 0 | manager->summary(@_); | |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | sub args { | ||||||||||||||||||||||||||||||
| 116 | 67 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
args: called CC=11 SCAR=42.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 117 | 67 | ▶ | my $args = @_ && ref $_[0] eq ARRAY ? shift : [ @_ ]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0] eq "ARRAY"
MC/DC0%0/2
@_ and ref $_[0] eq "ARRAY"
@_
ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||
| 118 | 67 | my $arg; | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | # quick hack until Badger::Config is done | ||||||||||||||||||||||||||||||
| 121 | 67 | ▶ | while (@$args && $args->[0] =~ /^-/) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$args and $args->[0] =~ /^-/
MC/DC0%0/2
@$args and $args->[0] =~ /^-/
@$args
$args->[0] =~ /^-/
Truth table33%1/3
A and B
A= @$argsB= $args->[0] =~ /^-/
| |||||||||||||||||||||||||||||||
| 122 | 0 | $arg = shift @$args; | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($arg =~ /^(-c|--colou?r)$/) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 124 | 0 | $self->colour(1); | |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||
| 126 | elsif ($arg =~ /^(-d|--debug)$/) { | ||||||||||||||||||||||||||||||
| 127 | # physically set $DEBUG in this package (required for exported | ||||||||||||||||||||||||||||||
| 128 | # aliases) and also call debugging() for any subclasses to use | ||||||||||||||||||||||||||||||
| 129 | 0 | $self->debugging( $DEBUG = 1 ); | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||
| 131 | elsif ($arg =~ /^(-s|--summary)$/) { | ||||||||||||||||||||||||||||||
| 132 | 0 | $self->summary(1); | |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||
| 134 | elsif ($arg =~ /^(-t|--trace)$/) { | ||||||||||||||||||||||||||||||
| 135 | 0 | $self->trace(1); | |||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||
| 137 | elsif ($arg =~ /^(-a|--all)$/) { | ||||||||||||||||||||||||||||||
| 138 | 0 | $self->all(1); | |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||
| 140 | elsif ($arg =~ /^(-h|--help)$/) { | ||||||||||||||||||||||||||||||
| 141 | 0 | warn $self->help; | |||||||||||||||||||||||||||||
| 142 | 0 | exit; | |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||||
| 145 | 0 | unshift(@$args, $arg); | |||||||||||||||||||||||||||||
| 146 | 0 | last; | |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | sub tests { | ||||||||||||||||||||||||||||||
| 152 | 59 | ▶ | shift; | ||||||||||||||||||||||||||||
|
Subroutine
tests: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 153 | 59 | plan(@_); | |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||
| 156 | sub debug_modules { | ||||||||||||||||||||||||||||||
| 157 | 64 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
debug_modules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 158 | 64 | $self->class->var( DEBUG_MODULES => shift ); | |||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | sub debugging { | ||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
debugging: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $flag = $DEBUG = (@_ ? shift : 1); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $modules = $self->class->var(DEBUG_MODULES) || return; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->class->var('DEBUG_MODULES') || (return)
MC/DC0%0/1
$self->class->var('DEBUG_MODULES') || (return)
$self->class->var('DEBUG_MODULES')
Truth table0%0/2
A
A= $self->class->var('DEBUG_MODULES')
| |||||||||||||||||||||||||||||||
| 165 | 0 | $DEBUGGER->debug_modules($modules); | |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||
| 168 | sub trace { | ||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
trace: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $flag = @_ ? shift : 1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 171 | 0 | $EXCEPTION->trace($flag); | |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||
| 174 | sub all { | ||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
all: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $ALL = @_ ? shift : 1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | sub help { | ||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | return <<END_OF_HELP; | ||||||||||||||||||||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 181 | Options: | ||||||||||||||||||||||||||||||
| 182 | -a --all Run all tests (e.g. author/release tests) | ||||||||||||||||||||||||||||||
| 183 | -d --debug Enable debugging | ||||||||||||||||||||||||||||||
| 184 | -t --trace Enable stack tracing | ||||||||||||||||||||||||||||||
| 185 | -c --colour/--color Enable colour output | ||||||||||||||||||||||||||||||
| 186 | -s --summary Display summary of test results | ||||||||||||||||||||||||||||||
| 187 | -h --help This help summary | ||||||||||||||||||||||||||||||
| 188 | END_OF_HELP | ||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||
| 192 | class->methods( | ||||||||||||||||||||||||||||||
| 193 | 62 | ▶ | plan => sub ($;$) { manager->plan(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 194 | 486 | ▶ | ok => sub ($;$) { manager->ok(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 195 | 1084 | ▶ | is => sub ($$;$) { manager->is(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 196 | 5 | ▶ | isnt => sub ($$;$) { manager->isnt(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 197 | 39 | ▶ | like => sub ($$;$) { manager->like(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 198 | 2 | ▶ | unlike => sub ($$;$) { manager->unlike(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 199 | 21 | ▶ | pass => sub (;$) { manager->pass(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | fail => sub (;$) { manager->fail(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | skip => sub (;$) { manager->skip(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | skip_some => sub (;$$) { manager->skip_some(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | skip_rest => sub (;$) { manager->skip_rest(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 204 | 3 | ▶ | skip_all => sub (;$) { manager->skip_all(@_) }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 205 | 70 | ); | |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||
| 208 | 70 | 1; | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||
| 210 | __END__ | ||||||||||||||||||||||||||||||