/
TestResult.pm
63 lines (52 loc) · 1.26 KB
/
TestResult.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package TAP::Spec::TestResult;
# ABSTRACT: The results of a single test
use Moose;
use Moose::Util::TypeConstraints;
use namespace::autoclean;
enum 'TAP::Spec::TestStatus' => ('ok', 'not ok');
enum 'TAP::Spec::Directive' => qw(SKIP TODO);
subtype 'TAP::Spec::TestNumber' => as 'Int', where { $_ > 0 };
has 'status' => (
is => 'rw',
isa => 'TAP::Spec::TestStatus',
required => 1,
);
has 'number' => (
is => 'rw',
isa => 'TAP::Spec::TestNumber',
predicate => 'has_number',
);
has 'description' => (
is => 'rw',
isa => 'Str',
predicate => 'has_description',
);
has 'directive' => (
is => 'rw',
isa => 'TAP::Spec::Directive',
predicate => 'has_directive',
);
has 'reason' => (
is => 'rw',
isa => 'Str',
predicate => 'has_reason',
);
sub passed {
my $self = shift;
return 1 if $self->status eq 'ok';
return 1 if $self->directive and $self->directive eq 'TODO';
return '';
}
sub as_tap {
my ($self) = @_;
my $tap = $self->status;
$tap .= " " . $self->number if $self->has_number;
$tap .= " " . $self->description if $self->has_description;
if ($self->has_directive) {
$tap .= " # " . $self->directive;
$tap .= " " . $self->reason if $self->has_reason;
}
$tap .= "\n";
return $tap;
}
__PACKAGE__->meta->make_immutable;