X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FTest%2FLeaner.pm;h=b629f6a8d93d377485e7303314be049fb1b4ed5e;hb=0857b9585353fe0fe98e3e1fded50f6e15b3f1f3;hp=c1b8df4b712334a900802ec34b9260407b905f2e;hpb=e3abaf6002541705d0afdab5a64e6f82dde4ec6c;p=perl%2Fmodules%2FTest-Leaner.git diff --git a/lib/Test/Leaner.pm b/lib/Test/Leaner.pm index c1b8df4..b629f6a 100644 --- a/lib/Test/Leaner.pm +++ b/lib/Test/Leaner.pm @@ -30,6 +30,29 @@ our $VERSION = '0.01'; When profiling some L-based test script that contained about 10 000 unit tests, I realized that 60% of the time was spent in L itself, even though every single test actually involved a costly C. This module aims to be a partial replacement to L in those situations where you want to run a large number of simple tests. +Its functions behave the same as their L counterparts, except for the following differences : + +=over 4 + +=item * + +Stringification isn't forced on the test operands. +However, L honors C<'bool'> overloading, L honors C<'eq'> overloading and L honors whichever overloading category corresponds to the specified operator. + +=item * + +L, L, L, L, L, L, L and L are all guaranteed to return the truth value of the test. + +=item * + +L throws an exception if the given operator isn't a valid Perl binary operator (except C<'='> and variants). +It also tests in scalar context, so C<'..'> will be treated as the flip-flop operator and not the range operator. + +=item * + +C, C, C, C, C, C, C, C blocks and C are not implemented. + +=back =cut @@ -52,14 +75,7 @@ BEGIN { } } -my $TAP_STREAM = *STDOUT; -my $DIAG_STREAM = *STDERR; - -for ($TAP_STREAM, $DIAG_STREAM) { - my $fh = select $_; - $|++; - select $fh; -} +my ($TAP_STREAM, $DIAG_STREAM); my ($plan, $test, $failed, $no_diag, $done_testing); @@ -149,7 +165,6 @@ sub plan { our @EXPORT = qw< plan - skip_all skip done_testing pass @@ -199,15 +214,6 @@ sub import { goto &Exporter::import; } -=head2 C - -=cut - -sub skip_all { - @_ = (skip_all => $_[0]); - goto &plan; -} - =head2 C<< skip $reason => $count >> =cut @@ -349,12 +355,17 @@ sub isnt ($$;$) { my %binops = ( 'or' => 'or', - 'and' => 'and', 'xor' => 'xor', + 'and' => 'and', '||' => 'hor', + ('//' => 'dor') x ($] >= 5.010), '&&' => 'hand', + '|' => 'bor', + '^' => 'bxor', + '&' => 'band', + 'lt' => 'lt', 'le' => 'le', 'gt' => 'gt', @@ -373,7 +384,21 @@ my %binops = ( '=~' => 'like', '!~' => 'unlike', - '~~' => 'smartmatch', + ('~~' => 'smartmatch') x ($] >= 5.010), + + '+' => 'add', + '-' => 'substract', + '*' => 'multiply', + '/' => 'divide', + '%' => 'modulo', + '<<' => 'lshift', + '>>' => 'rshift', + + '.' => 'concat', + '..' => 'flipflop', + '...' => 'altflipflop', + ',' => 'comma', + '=>' => 'fatcomma', ); my %binop_handlers; @@ -387,7 +412,7 @@ sub _create_binop_handler { eval <<"IS_BINOP"; sub is_$name (\$\$;\$) { my (\$got, \$expected, \$desc) = \@_; - \@_ = ((\$got $op \$expected), \$desc); + \@_ = (scalar(\$got $op \$expected), \$desc); goto &ok; } IS_BINOP @@ -502,8 +527,57 @@ END { =pod -L, L, L, L, L, L, L and L are all guaranteed to return the truth value of the test. -Their L counterparts behave the same, but it is not documented anywhere. +L also provides some functions of its own, which are never exported. + +=head2 C + +Read/write accessor for the filehandle to which the tests are outputted. +On write, it also turns autoflush on onto C<$fh>. + +Note that it can only be used as a write accessor before you start any thread, as L cannot reliably share filehandles. + +Defaults to C. + +=cut + +sub tap_stream (;*) { + if (@_) { + $TAP_STREAM = $_[0]; + + my $fh = select $TAP_STREAM; + $|++; + select $fh; + } + + return $TAP_STREAM; +} + +tap_stream *STDOUT; + +=head2 C + +Read/write accessor for the filehandle to which the diagnostics are printed. +On write, it also turns autoflush on onto C<$fh>. + +Just like L, it can only be used as a write accessor before you start any thread, as L cannot reliably share filehandles. + +Defaults to C. + +=cut + +sub diag_stream (;*) { + if (@_) { + $DIAG_STREAM = $_[0]; + + my $fh = select $DIAG_STREAM; + $|++; + select $fh; + } + + return $DIAG_STREAM; +} + +diag_stream *STDERR; =head1 DEPENDENCIES