Acme-FSM
view release on metacpan or search on metacpan
t/TestSuite.pm view on Meta::CPAN
=item B<AFSMTS_method_wrap()>
use t::TestSuite qw/ :wraps /;
our( $rc, %st, $bb );
our( $stdout, $stderr );
AFSMTS_method_wrap 'some_method', @list;
Complete analogy of B<AFSMTS_wrap()> except instead of B<process()> some
requested I<$method> is B<can>ed first, than invoked with I<@list> over
I<$main::bb> in list context.
What is returned is placed in I<$main::rc> wrapped in ARRAY.
If I<$method> returned one element then ARRAY is replaced with scalar.
=cut
sub AFSMTS_method_wrap ( $@ ) {
open my $stdout_bak, q|>&|, \*STDOUT;
open my $stderr_bak, q|>&|, \*STDERR;
close STDOUT; open STDOUT, q|>|, \$main::stdout;
close STDERR; open STDERR, q|>|, \$main::stderr;
my $method = $main::bb->can( shift @_ );
my $rc = [ eval {
local $SIG{ALRM} = sub { die qq|ALRM\n| };
alarm 3;
$main::rc = [ $main::bb->$method( @_ ) ];
alarm 0;
1 } ];
alarm 0;
unless( @$rc ) {
$main::stderr = substr $main::stderr // '', 0, 1024 unless $NO_TRIM;
$main::rc = [ $@ ] }
$main::rc = $main::rc->[0] if 1 == @$main::rc;
close STDERR; open STDERR, q|>&|, $stderr_bak;
close STDOUT; open STDOUT, q|>&|, $stdout_bak;
AFSMTS_diag $main::stderr }
=item B<AFSMTS_croakson> 'actual description'
use t::TestSuite qw/ :diag /;
$rc = eval { die 'as expected'; 1 };
is !$rc, 0, AFSMTS_croakson 'surprise';
That will add I<$@> (with newlines replaced with spaces) to otherwise dumb
description, like this:
ok 1 - croaks on (surprise) (as expected at test-unit.t line 12 )
=cut
sub AFSMTS_croakson ( $ ) {
my $eval_msg = $@;
$eval_msg =~ tr{\n}{ };
return sprintf q|croaks on (%s) (%s)|, shift @_, $eval_msg }
=item B<AFSMTS_shift()>
our %opts;
our @inbase = ( qw/ a b c /, undef );
our @input = @inbase;
$opts{source} = \&AFSMTS_shift;
AFSMTS_wrap;
Quiet generic implementation of I<{source}> code.
Uses script globals:
=over
=item I<@inbase>
Read-only.
When I<@input> runs empty it will be reset from I<@inbase>.
=item I<@input>
Supposed items will be B<shift>ed from this array.
=back
=cut
sub AFSMTS_shift ( ) {
do {
no warnings qw| once |;
@main::input = @main::inbase unless
@main::input };
return shift @main::input }
=item B<AFSMTS_U()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_U, "", "", qw/ S0 NEXT /]);
Convinience switch.
An item is saved in I<@{$bb->{queue}>.
Returns C<undef> and consumes an item.
=cut
sub AFSMTS_U { push @{$_[0]{queue}}, $_[1]; ( undef, undef ) }
=item B<AFSMTS_UK()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_UK, "", "", qw/ S0 NEXT /]);
Convinience switch.
An item is saved in I<@{$bb->{queue}>.
Returns C<undef> and an item unaltered.
=cut
sub AFSMTS_UK { push @{$_[0]{queue}}, $_[1]; ( undef, $_[1] ) }
=item B<AFSMTS_F()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_F, "", "", qw/ S0 NEXT /]);
Convinience switch.
An item is saved in I<@{$bb->{queue}>.
Returns FALSE but C<undef> and consumes an item.
=cut
sub AFSMTS_F { push @{$_[0]{queue}}, $_[1]; ( !1, undef ) }
=item B<AFSMTS_FK()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_FK, "", "", qw/ S0 NEXT /]);
Convinience switch.
An item is saved in I<@{$bb->{queue}>.
Returns FALSE but C<undef> and an item unaltered.
=cut
sub AFSMTS_FK { push @{$_[0]{queue}}, $_[1]; ( !1, $_[1] ) }
=item B<AFSMTS_T()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_T, qw/ S0 NEXT /]);
Convinience switch.
An item is saved in I<@{$bb->{queue}>.
Returns TRUE and consumes an item.
=cut
sub AFSMTS_T { push @{$_[0]{queue}}, $_[1]; ( !0, undef ) }
=item B<AFSMTS_TK()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_TK, qw/ S0 NEXT /]);
Convinience switch.
An item is saved in I<@{$bb->{queue}>.
Returns TRUE and an item unaltered.
=cut
sub AFSMTS_TK { push @{$_[0]{queue}}, $_[1]; ( !0, $_[1] ) }
=item B<AFSMTS_t()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_t, qw/ S0 NEXT /]);
Convinience switch.
Returns TRUE and consumes an item.
=cut
sub AFSMTS_t { ( !0, undef ) }
=item B<AFSMTS_tK()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => [qw/ S0 DONE /, \&AFSMTS_tK, qw/ S0 NEXT /]);
Convinience switch.
Returns TRUE and an item unaltered.
=cut
sub AFSMTS_tK { ( !0, $_[1] ) }
=item B<AFSMTS_D()>
use t::TestSuite qw/ :switches /;
%st = ( S0 => ["", "", \&AFSMTS_D]);
Convinience switch.
Just dies with C<die switch> message.
=cut
sub AFSMTS_D { die qq|die switch| }
=item B<AFSMTS_smartmatch()>
use t::TestSuite qw/ :utils /;
fail 'assert' unless AFSMTS_smartmatch @result, @target;
(B<v2.3.6>)
I<rationale: on>
Since B<v5.41.5> L<B<smartmatch>|perlop/Smartmatch Operator> is less then before
(C<use 5.10> fails to compile double-tilde now).
Unfortunately, testsuite used B<smartmatch> to compare two arrays
and it can't.
I<rationale: off>
The sub-name is misleading -- this one isn't close to be drop in replacement for L<B<smartmatch>|perlop/Smartmatch Operator>
(but it has potential nevertheless).
Two B<ARRAY>s are compared for equality.
=over
=item *
If sizes of arrays differ returns C<undef>
=item *
If any two elements mismatch then returns Perl's B<FALSE>
=item *
Otherwise returns Perl's B<TRUE>
=item *
Values are treated as plain scalars (it's too early for recursion)
=back
=cut
sub AFSMTS_smartmatch ( \@\@ ) {
my( $jkCX1Y, $jlVW4H ) = @_;
@$jkCX1Y == @$jlVW4H or return undef;
not grep $jkCX1Y->[$_] ne $jlVW4H->[$_], ( 0 .. $#$jkCX1Y ) }
=item B<AFSMTS_grep()>
use t::TestSuite qw/ :utils /;
AFSTMTS_grep $item, @mass or next;
(B<v2.3.6>)
This should be in L<B<AFSMTS_smartmatch>|/AFSMTS_smartmatch()>.
But that would be too much work for testsuite support.
So it isn't.
Verifies if I<$item> is present in I<@mass>
=over
=item *
Returns Perl's B<TRUE> if I<$item> is present
=item *
Returns Perl's B<FALSE> otherwise
=back
=cut
sub AFSMTS_grep ( $@ ) {
my( $bnabT2, @ikHNm4 ) = @_;
not not grep $bnabT2 eq $_, @ikHNm4 }
=back
=cut
1;
( run in 1.072 second using v1.01-cache-2.11-cpan-d80b1682f3f )