1package Test2::Event::Fail;
2use strict;
3use warnings;
4
5our $VERSION = '1.302162';
6
7use Test2::EventFacet::Info;
8
9BEGIN {
10    require Test2::Event;
11    our @ISA = qw(Test2::Event);
12    *META_KEY = \&Test2::Util::ExternalMeta::META_KEY;
13}
14
15use Test2::Util::HashBase qw{ -name -info };
16
17#############
18# Old API
19sub summary          { "fail" }
20sub increments_count { 1 }
21sub diagnostics      { 0 }
22sub no_display       { 0 }
23sub subtest_id       { undef }
24sub terminate        { () }
25sub global           { () }
26sub sets_plan        { () }
27
28sub causes_fail {
29    my $self = shift;
30    return 0 if $self->{+AMNESTY} && @{$self->{+AMNESTY}};
31    return 1;
32}
33
34#############
35# New API
36
37sub add_info {
38    my $self = shift;
39
40    for my $in (@_) {
41        $in = {%$in} if ref($in) ne 'ARRAY';
42        $in = Test2::EventFacet::Info->new($in);
43
44        push @{$self->{+INFO}} => $in;
45    }
46}
47
48sub facet_data {
49    my $self = shift;
50    my $out = $self->common_facet_data;
51
52    $out->{about}->{details} = 'fail';
53
54    $out->{assert} = {pass => 0, details => $self->{+NAME}};
55
56    $out->{info} = [map {{ %{$_} }} @{$self->{+INFO}}] if $self->{+INFO};
57
58    return $out;
59}
60
611;
62
63__END__
64
65=pod
66
67=encoding UTF-8
68
69=head1 NAME
70
71Test2::Event::Fail - Event for a simple failed assertion
72
73=head1 DESCRIPTION
74
75This is an optimal representation of a failed assertion.
76
77=head1 SYNOPSIS
78
79    use Test2::API qw/context/;
80
81    sub fail {
82        my ($name) = @_;
83        my $ctx = context();
84        $ctx->fail($name);
85        $ctx->release;
86    }
87
88=head1 SOURCE
89
90The source code repository for Test2 can be found at
91F<http://github.com/Test-More/test-more/>.
92
93=head1 MAINTAINERS
94
95=over 4
96
97=item Chad Granum E<lt>exodist@cpan.orgE<gt>
98
99=back
100
101=head1 AUTHORS
102
103=over 4
104
105=item Chad Granum E<lt>exodist@cpan.orgE<gt>
106
107=back
108
109=head1 COPYRIGHT
110
111Copyright 2019 Chad Granum E<lt>exodist@cpan.orgE<gt>.
112
113This program is free software; you can redistribute it and/or
114modify it under the same terms as Perl itself.
115
116See F<http://dev.perl.org/licenses/>
117
118=cut
119