Skip to content

Commit

Permalink
Merge branch 'master' into fix-pod
Browse files Browse the repository at this point in the history
  • Loading branch information
bayashi committed Apr 24, 2020
2 parents 37b7f69 + e451a9f commit 99ed952
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
requires 'perl', '5.008005';
requires 'strict';
requires 'warnings';
requires 'Carp';
requires 'Test::Builder::Module';
requires 'Test::Name::FromLine';
requires 'Text::MatchedPosition';
Expand Down
46 changes: 38 additions & 8 deletions lib/Test/Arrow.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package Test::Arrow;
use strict;
use warnings;
use Carp qw/croak/;
use Test::Builder::Module;
use Test::Name::FromLine;
use Text::MatchedPosition;
Expand All @@ -20,14 +21,15 @@ sub import {
my $caller = caller;
no strict 'refs'; ## no critic
*{"${caller}::done"} = \&done;
*{"${caller}::t"} = \&t;
}

$pkg->_import_option_no_strict(\%args);
$pkg->_import_option_no_warnings(\%args);
$pkg->_import_option_binary(\%args);

if (scalar(keys %args) > 0) {
die "Wrong option: " . join(", ", keys %args);
croak "Wrong option: " . join(", ", keys %args);
}

if ($] < 5.014000) {
Expand Down Expand Up @@ -81,6 +83,10 @@ sub new {
$self;
}

sub t {
return __PACKAGE__->new(@_);
}

sub _tb { __PACKAGE__->builder }

sub _reset {
Expand Down Expand Up @@ -153,7 +159,7 @@ sub expected {
my $arg_count = scalar(@_) - 1;

if ($arg_count > 1) {
die "'expected' method expects just only one arg. You passed $arg_count args.";
croak "'expected' method expects just only one arg. You passed $arg_count args.";
}

$self->{_expected} = $value;
Expand All @@ -167,7 +173,7 @@ sub got {
my $arg_count = scalar(@_) - 1;

if ($arg_count > 1) {
die "'got' method expects just only one arg. You passed $arg_count args.";
croak "'got' method expects just only one arg. You passed $arg_count args.";
}

$self->{_got} = $value;
Expand Down Expand Up @@ -377,7 +383,7 @@ sub isa_ok {
my ($result, $error) = _tb->_try(sub { $got->isa($expected) });

if ($error) {
die <<WHOA unless $error =~ /^Can't (locate|call) method "isa"/;
croak <<WHOA unless $error =~ /^Can't (locate|call) method "isa"/;
WHOA! I tried to call ->isa on your $whatami and got some weird error.
Here's the error.
$error
Expand Down Expand Up @@ -437,7 +443,7 @@ sub _get_isa_diag_name {
$diag = "$test_name isn't a '$expected'";
}
else {
die;
croak;
}

return($diag, $name);
Expand All @@ -459,7 +465,7 @@ sub throw {
my $self = shift;
my $code = shift;

die 'The `throw` method expects code ref.' unless ref $code eq 'CODE';
croak 'The `throw` method expects code ref.' unless ref $code eq 'CODE';

eval { $code->() };

Expand Down Expand Up @@ -518,7 +524,7 @@ sub warnings_ok {
sub warnings {
my ($self, $code, $regex, $name) = @_;

die 'The `warn` method expects code ref.' unless ref $code eq 'CODE';
croak 'The `warn` method expects code ref.' unless ref $code eq 'CODE';

my @warns;
eval {
Expand Down Expand Up @@ -673,7 +679,7 @@ sub __deep_check_type {
$ok = FAIL;
}
else {
die <<_WHOA_;
croak <<_WHOA_;
WHOA! No type in _deep_check
This should never happen! Please contact the author immediately!
_WHOA_
Expand Down Expand Up @@ -873,6 +879,17 @@ Test::Arrow - Object-Oriented testing library
$arr->warnings(sub { warn 'Bar' })->catch(qr/^Ba/);
$arr->throw(sub { die 'Baz' })->catch(qr/^Ba/);
done;
The function C<t> is exported as a shortcut for constructer. It initializes an instance for each.
use Test::Arrow;
t->got(1)->ok;
t->expect(uc 'foo')->to_be('FOO');
done;
=head1 DESCRIPTION
Expand Down Expand Up @@ -947,6 +964,19 @@ It should be in constructor option or should be called as straightforward method
=back
=head3 t
The function C<t> will be exported. It's initializer to get instance as shortcut.
my $arr = Test::Arrow;
$arr->got(1)->ok;
Above test is same as below.
t->got(1)->ok;
The function C<t> can get arguments as same as C<new>.
=head2 SETTERS
=head3 expected($expected)
Expand Down
7 changes: 7 additions & 0 deletions t/17_t.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use Test::Arrow;

t->ok(1);

t->got(123)->expected(123)->is;

done;

0 comments on commit 99ed952

Please sign in to comment.