| 1 | package Test::NameNote; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | Test::NameNote - add notes to test names | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Adds notes to test names in L<Test::Builder>-based test scripts. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | use Test::More tests => 10; | ||||||||||||||||||||||||||||
| 15 | use Test::NameNote; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | ok foo(), "foo true"; | ||||||||||||||||||||||||||||
| 18 | foreach my $foo (0, 1) { | ||||||||||||||||||||||||||||
| 19 | my $n1 = Test::NameNote->new("foo=$foo"); | ||||||||||||||||||||||||||||
| 20 | foreach my $bar (0, 1) { | ||||||||||||||||||||||||||||
| 21 | my $n2 = Test::NameNote->new("bar=$bar"); | ||||||||||||||||||||||||||||
| 22 | is thing($foo, $bar), "thing", "thing returns thing"; | ||||||||||||||||||||||||||||
| 23 | is thang($foo, $bar), "thang", "thang returns thang"; | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | ok bar(), "bar true"; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # prints: | ||||||||||||||||||||||||||||
| 29 | 1..10 | ||||||||||||||||||||||||||||
| 30 | ok 1 - foo true | ||||||||||||||||||||||||||||
| 31 | ok 2 - thing returns thing (foo=0,bar=0) | ||||||||||||||||||||||||||||
| 32 | ok 3 - thang returns thang (foo=0,bar=0) | ||||||||||||||||||||||||||||
| 33 | ok 4 - thing returns thing (foo=0,bar=1) | ||||||||||||||||||||||||||||
| 34 | ok 5 - thang returns thang (foo=0,bar=1) | ||||||||||||||||||||||||||||
| 35 | ok 6 - thing returns thing (foo=1,bar=0) | ||||||||||||||||||||||||||||
| 36 | ok 7 - thang returns thang (foo=1,bar=0) | ||||||||||||||||||||||||||||
| 37 | ok 8 - thing returns thing (foo=1,bar=1) | ||||||||||||||||||||||||||||
| 38 | ok 9 - thang returns thang (foo=1,bar=1) | ||||||||||||||||||||||||||||
| 39 | ok 10 - bar true | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | ▶ | use Test::Builder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 3 | ▶ | use Sub::Prepend 'prepend'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | our @_notes; | |||||||||||||||||||||||||||
| 47 | 3 | our $_wrapped_test_group_ok = 0; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 3 | _wrap('Test::Builder::ok'); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | ▶ | sub _wrap { | ||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 3 | my $target = shift; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 26 | ▶ | prepend $target => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 55 | 26 | ▶ | if (@_notes) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | # Append any current notes to the test name in $_[2]. | ||||||||||||||||||||||||||||
| 57 | 16 | my $note = join ',', map {$$_} @_notes; | |||||||||||||||||||||||||||
| 58 | 16 | ▶ | if (defined $_[2] and length $_[2]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_[2] and length $_[2]
MC/DC50%1/2
defined $_[2] and length $_[2]
defined $_[2]
length $_[2]
Truth table66%2/3
A and B
A= defined $_[2]B= length $_[2]
| |||||||||||||||||||||||||||||
| 59 | 15 | $note = "$_[2] ($note)"; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 16 | @_ = (@_[0,1], $note, @_[3,-1]); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 3 | }; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 CONSTRUCTORS | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =over | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =item new ( NOTE ) | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Builds a new C<Test::NameNote> object for the specifed NOTE text. The note | ||||||||||||||||||||||||||||
| 73 | will be added to the names of all L<Test::Builder> tests run while the | ||||||||||||||||||||||||||||
| 74 | object is in scope. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 17 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 17 | my ($pkg, $note) = @_; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 17 | ▶ | if (!$_wrapped_test_group_ok and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $Test::NameNote::_wrapped_test_group_ok and exists &Test::Builder::_HijackedByTestGroup::ok
MC/DC0%0/2
not $Test::NameNote::_wrapped_test_group_ok and exists &Test::Builder::_HijackedByTestGroup::ok
not $Test::NameNote::_wrapped_test_group_ok
exists &Test::Builder::_HijackedByTestGroup::ok
Truth table33%1/3
not(A) and B
A= not $Test::NameNote::_wrapped_test_group_okB= exists &Test::Builder::_HijackedByTestGroup::ok
| |||||||||||||||||||||||||||||
| 82 | exists &Test::Builder::_HijackedByTestGroup::ok) { | ||||||||||||||||||||||||||||
| 83 | 0 | _wrap('Test::Builder::_HijackedByTestGroup::ok'); | |||||||||||||||||||||||||||
| 84 | 0 | $_wrapped_test_group_ok = 1; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 17 | push @_notes, \$note; | |||||||||||||||||||||||||||
| 88 | 17 | ▶ | return bless { NoteRef => \$note }, ref($pkg)||$pkg; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $pkg || $pkg
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg
$pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =back | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 17 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 96 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 17 | @_notes = grep {$_ ne $self->{NoteRef}} @_notes; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Nick Cleaton, C<< <nick at cleaton dot net> >> | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Copyright 2009 Nick Cleaton, all rights reserved. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 110 | the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 3 | 1; | |||||||||||||||||||||||||||