Debian Codegraph @

upstream/debian-unstable/man3/Test2::Tools::Exception.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Test2::Tools::Exception 3perl"
58 .TH Test2::Tools::Exception 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Test2::Tools::Exception \- Test2 based tools for checking exceptions
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 This is the Test2 implementation of code used to test exceptions. This is
68 similar to Test::Fatal, but it intentionally does much less.
69 .SH SYNOPSIS
70 .IX Header "SYNOPSIS"
71 .Vb 1
72 \& use Test2::Tools::Exception qw/dies lives/;
73 \&
74 \& like(
75 \& dies { die \*(Aqxxx\*(Aq },
76 \& qr/xxx/,
77 \& "Got exception"
78 \& );
79 \&
80 \& ok(lives { ... }, "did not die") or note($@);
81 .Ve
82 .SH EXPORTS
83 .IX Header "EXPORTS"
84 All subs are exported by default.
85 .ie n .IP "$e = dies { ... }" 4
86 .el .IP "\f(CW$e\fR = dies { ... }" 4
87 .IX Item "$e = dies { ... }"
88 This will trap any exception the codeblock throws. If no exception is thrown
89 the sub will return undef. If an exception is thrown it will be returned. This
90 function preserves \f(CW$@\fR, it will not be altered from its value before the sub
91 is called.
92 .ie n .IP "$bool = lives { ... }" 4
93 .el .IP "\f(CW$bool\fR = lives { ... }" 4
94 .IX Item "$bool = lives { ... }"
95 This will trap any exception thrown in the codeblock. It will return true when
96 there is no exception, and false when there is. \f(CW$@\fR is preserved from before
97 the sub is called when there is no exception. When an exception is trapped
98 \&\f(CW$@\fR will have the exception so that you can look at it.
99 .ie n .IP "$bool = try_ok { ... }" 4
100 .el .IP "\f(CW$bool\fR = try_ok { ... }" 4
101 .IX Item "$bool = try_ok { ... }"
102 .PD 0
103 .ie n .IP "$bool = try_ok { ... } ""Test Description""" 4
104 .el .IP "\f(CW$bool\fR = try_ok { ... } ""Test Description""" 4
105 .IX Item "$bool = try_ok { ... } ""Test Description"""
106 .PD
107 This will run the code block trapping any exception. If there is no exception a
108 passing event will be issued. If the test fails a failing event will be issued,
109 and the exception will be reported as diagnostics.
110 .Sp
111 \&\fBNote:\fR This function does not preserve \f(CW$@\fR on failure, it will be set to
112 the exception the codeblock throws, this is by design so that you can obtain
113 the exception if desired.
114 .SH "DIFFERENCES FROM TEST::FATAL"
115 .IX Header "DIFFERENCES FROM TEST::FATAL"
116 Test::Fatal sets \f(CW$Test::Builder::Level\fR such that failing tests inside the
117 exception block will report to the line where \f(CWexception()\fR is called. I
118 disagree with this, and think the actual line of the failing test is
119 more important. Ultimately, though Test::Fatal cannot be changed, people
120 probably already depend on that behavior.
121 .SH SOURCE
122 .IX Header "SOURCE"
123 The source code repository for Test2\-Suite can be found at
124 \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
125 .SH MAINTAINERS
126 .IX Header "MAINTAINERS"
127 .IP "Chad Granum <[email protected]>" 4
128 .IX Item "Chad Granum <[email protected]>"
129 .SH AUTHORS
130 .IX Header "AUTHORS"
131 .PD 0
132 .IP "Chad Granum <[email protected]>" 4
133 .IX Item "Chad Granum <[email protected]>"
134 .PD
135 .SH COPYRIGHT
136 .IX Header "COPYRIGHT"
137 Copyright 2018 Chad Granum <[email protected]>.
138 .PP
139 This program is free software; you can redistribute it and/or
140 modify it under the same terms as Perl itself.
141 .PP
142 See \fIhttp://dev.perl.org/licenses/\fR