File: Exception.pm

package info (click to toggle)
libtest-unit-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,312 kB
  • sloc: perl: 4,297; makefile: 5
file content (103 lines) | stat: -rw-r--r-- 1,789 bytes parent folder | download | duplicates (6)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package Test::Unit::Exception;

use strict;

use Carp;
use Error;

use base 'Error';

sub throw_new {
    my $self = shift;
    my $class = ref $self;
    $class->throw(%{$self || {}},@_);
}

sub stacktrace {
    my $self = shift;
    warn "Stacktrace is deprecated and no longer works"
}

sub get_message {
    my $self = shift;
    $self->text;
}

sub hide_backtrace {
    my $self = shift;
    $self->{_hide_backtrace} = 1;
}

sub stringify {
    my $self = shift;
    my $file = $self->file;
    my $line = $self->line;
    my $message = $self->text || 'Died';
    my $object = $self->object;

    my $str = "$file:$line";
    $str .= ' - ' . $object->to_string() if $object && $object->can('to_string');
    $str .= "\n" . $message;
    return $str;
}

sub to_string {
    my $self = shift;
    $self->stringify;
}

sub failed_test {
    carp "Test::Unit::Exception::failed_test called";
    return $_[0]->object;
}

sub thrown_exception {
    carp "Test::Unit::Exception::thrown_exception called";
    return $_[0]->object;
}

1;
__END__

=head1 NAME

Test::Unit::Exception - unit testing framework exception class

=head1 SYNOPSIS

This class is not intended to be used directly 

=head1 DESCRIPTION

This class is used by the framework to communicate the result of
assertions, which will throw an instance of a subclass of this class
in case of errors or failures.

=head1 AUTHOR

Copyright (c) 2000-2002, 2005 the PerlUnit Development Team
(see L<Test::Unit> or the F<AUTHORS> file included in this
distribution).

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=head1 SEE ALSO

=over 4

=item *

L<Test::Unit::Assert>

=item *

L<Test::Unit::Error>

=item *

L<Test::Unit::Failure>

=back

=cut