This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
7a35e0e8abb4d60ad646a5afe615df9c6a2e6e54
[perl5.git] / cpan / Test-Simple / lib / Test2 / Event / Exception.pm
1 package Test2::Event::Exception;
2 use strict;
3 use warnings;
4
5 our $VERSION = '1.302166';
6
7
8 BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) }
9 use Test2::Util::HashBase qw{error};
10
11 sub init {
12     my $self = shift;
13     $self->{+ERROR} = "$self->{+ERROR}";
14 }
15
16 sub causes_fail { 1 }
17
18 sub summary {
19     my $self = shift;
20     chomp(my $msg = "Exception: " . $self->{+ERROR});
21     return $msg;
22 }
23
24 sub diagnostics { 1 }
25
26 sub facet_data {
27     my $self = shift;
28     my $out = $self->common_facet_data;
29
30     $out->{errors} = [
31         {
32             tag     => 'ERROR',
33             fail    => 1,
34             details => $self->{+ERROR},
35         }
36     ];
37
38     return $out;
39 }
40
41
42 1;
43
44 __END__
45
46 =pod
47
48 =encoding UTF-8
49
50 =head1 NAME
51
52 Test2::Event::Exception - Exception event
53
54 =head1 DESCRIPTION
55
56 An exception event will display to STDERR, and will prevent the overall test
57 file from passing.
58
59 =head1 SYNOPSIS
60
61     use Test2::API qw/context/;
62     use Test2::Event::Exception;
63
64     my $ctx = context();
65     my $event = $ctx->send_event('Exception', error => 'Stuff is broken');
66
67 =head1 METHODS
68
69 Inherits from L<Test2::Event>. Also defines:
70
71 =over 4
72
73 =item $reason = $e->error
74
75 The reason for the exception.
76
77 =back
78
79 =head1 CAVEATS
80
81 Be aware that all exceptions are stringified during construction.
82
83 =head1 SOURCE
84
85 The source code repository for Test2 can be found at
86 F<http://github.com/Test-More/test-more/>.
87
88 =head1 MAINTAINERS
89
90 =over 4
91
92 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
93
94 =back
95
96 =head1 AUTHORS
97
98 =over 4
99
100 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
101
102 =back
103
104 =head1 COPYRIGHT
105
106 Copyright 2019 Chad Granum E<lt>exodist@cpan.orgE<gt>.
107
108 This program is free software; you can redistribute it and/or
109 modify it under the same terms as Perl itself.
110
111 See F<http://dev.perl.org/licenses/>
112
113 =cut