This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Test::Simple from version 1.302052 to 1.302056
[perl5.git] / cpan / Test-Simple / lib / Test2 / Event / Ok.pm
1 package Test2::Event::Ok;
2 use strict;
3 use warnings;
4
5 our $VERSION = '1.302056';
6
7
8 BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) }
9 use Test2::Util::HashBase qw{
10     pass effective_pass name todo
11 };
12
13 sub init {
14     my $self = shift;
15
16     # Do not store objects here, only true or false
17     $self->{+PASS} = $self->{+PASS} ? 1 : 0;
18     $self->{+EFFECTIVE_PASS} = $self->{+PASS} || (defined($self->{+TODO}) ? 1 : 0);
19 }
20
21 {
22     no warnings 'redefine';
23     sub set_todo {
24         my $self = shift;
25         my ($todo) = @_;
26         $self->{+TODO} = $todo;
27         $self->{+EFFECTIVE_PASS} = defined($todo) ? 1 : $self->{+PASS};
28     }
29 }
30
31 sub increments_count { 1 };
32
33 sub causes_fail { !$_[0]->{+EFFECTIVE_PASS} }
34
35 sub summary {
36     my $self = shift;
37
38     my $name = $self->{+NAME} || "Nameless Assertion";
39
40     my $todo = $self->{+TODO};
41     if ($todo) {
42         $name .= " (TODO: $todo)";
43     }
44     elsif (defined $todo) {
45         $name .= " (TODO)"
46     }
47
48     return $name;
49 }
50
51 1;
52
53 __END__
54
55 =pod
56
57 =encoding UTF-8
58
59 =head1 NAME
60
61 Test2::Event::Ok - Ok event type
62
63 =head1 DESCRIPTION
64
65 Ok events are generated whenever you run a test that produces a result.
66 Examples are C<ok()>, and C<is()>.
67
68 =head1 SYNOPSIS
69
70     use Test2::API qw/context/;
71     use Test2::Event::Ok;
72
73     my $ctx = context();
74     my $event = $ctx->ok($bool, $name, \@diag);
75
76 or:
77
78     my $ctx   = context();
79     my $event = $ctx->send_event(
80         'Ok',
81         pass => $bool,
82         name => $name,
83     );
84
85 =head1 ACCESSORS
86
87 =over 4
88
89 =item $rb = $e->pass
90
91 The original true/false value of whatever was passed into the event (but
92 reduced down to 1 or 0).
93
94 =item $name = $e->name
95
96 Name of the test.
97
98 =item $b = $e->effective_pass
99
100 This is the true/false value of the test after TODO and similar modifiers are
101 taken into account.
102
103 =item $b = $e->allow_bad_name
104
105 This relaxes the test name checks such that they allow characters that can
106 confuse a TAP parser.
107
108 =back
109
110 =head1 SOURCE
111
112 The source code repository for Test2 can be found at
113 F<http://github.com/Test-More/test-more/>.
114
115 =head1 MAINTAINERS
116
117 =over 4
118
119 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
120
121 =back
122
123 =head1 AUTHORS
124
125 =over 4
126
127 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
128
129 =back
130
131 =head1 COPYRIGHT
132
133 Copyright 2016 Chad Granum E<lt>exodist@cpan.orgE<gt>.
134
135 This program is free software; you can redistribute it and/or
136 modify it under the same terms as Perl itself.
137
138 See F<http://dev.perl.org/licenses/>
139
140 =cut