| 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::Transition 3perl" |
| 58 |
.TH Test2::Transition 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::Transition \- Transition notes when upgrading to Test2 |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
This is where gotchas and breakages related to the Test2 upgrade are |
| 68 |
documented. The upgrade causes Test::Builder to defer to Test2 under the hood. |
| 69 |
This transition is mostly transparent, but there are a few cases that can trip |
| 70 |
you up. |
| 71 |
.SH "THINGS THAT BREAK" |
| 72 |
.IX Header "THINGS THAT BREAK" |
| 73 |
This is the list of scenarios that break with the new internals. |
| 74 |
.SS "Test::Builder1.5/2 conditionals" |
| 75 |
.IX Subsection "Test::Builder1.5/2 conditionals" |
| 76 |
\fIThe Problem\fR |
| 77 |
.IX Subsection "The Problem" |
| 78 |
.PP |
| 79 |
a few years back there were two attempts to upgrade/replace Test::Builder. |
| 80 |
Confusingly these were called Test::Builder2 and Test::Builder1.5, in that |
| 81 |
order. Many people put conditionals in their code to check the Test::Builder |
| 82 |
version number and adapt their code accordingly. |
| 83 |
.PP |
| 84 |
The Test::Builder2/1.5 projects both died out. Now the conditional code people |
| 85 |
added has become a mine field. A vast majority of modules broken by Test2 fall |
| 86 |
into this category. |
| 87 |
.PP |
| 88 |
\fIThe Fix\fR |
| 89 |
.IX Subsection "The Fix" |
| 90 |
.PP |
| 91 |
The fix is to remove all Test::Builder1.5/2 related code. Either use the |
| 92 |
legacy Test::Builder API, or use Test2 directly. |
| 93 |
.SS "Replacing the Test::Builder singleton" |
| 94 |
.IX Subsection "Replacing the Test::Builder singleton" |
| 95 |
\fIThe Problem\fR |
| 96 |
.IX Subsection "The Problem" |
| 97 |
.PP |
| 98 |
Some test modules would replace the Test::Builder singleton instance with their |
| 99 |
own instance or subclass. This was usually done to intercept or modify results |
| 100 |
as they happened. |
| 101 |
.PP |
| 102 |
The Test::Builder singleton is now a simple compatibility wrapper around |
| 103 |
Test2. The Test::Builder singleton is no longer the central place for |
| 104 |
results. Many results bypass the Test::Builder singleton completely, which |
| 105 |
breaks and behavior intended when replacing the singleton. |
| 106 |
.PP |
| 107 |
\fIThe Fix\fR |
| 108 |
.IX Subsection "The Fix" |
| 109 |
.PP |
| 110 |
If you simply want to intercept all results instead of letting them go to TAP, |
| 111 |
you should look at the Test2::API docs and read about pushing a new hub onto |
| 112 |
the hub stack. Replacing the hub temporarily is now the correct way to |
| 113 |
intercept results. |
| 114 |
.PP |
| 115 |
If your goal is purely monitoring of events use the \f(CW\*(C`Test2::Hub\->listen()\*(C'\fR |
| 116 |
method exported by Test::More to watch events as they are fired. If you wish to |
| 117 |
modify results before they go to TAP look at the \f(CW\*(C`Test2::Hub\->filter()\*(C'\fR |
| 118 |
method. |
| 119 |
.SS "Directly Accessing Hash Elements" |
| 120 |
.IX Subsection "Directly Accessing Hash Elements" |
| 121 |
\fIThe Problem\fR |
| 122 |
.IX Subsection "The Problem" |
| 123 |
.PP |
| 124 |
Some modules look directly at hash keys on the Test::Builder singleton. The |
| 125 |
problem here is that the Test::Builder singleton no longer holds anything |
| 126 |
important. |
| 127 |
.PP |
| 128 |
\fIThe Fix\fR |
| 129 |
.IX Subsection "The Fix" |
| 130 |
.PP |
| 131 |
The fix is to use the API specified in Test2::API to look at or modify state |
| 132 |
as needed. |
| 133 |
.SS "Subtest indentation" |
| 134 |
.IX Subsection "Subtest indentation" |
| 135 |
\fIThe Problem\fR |
| 136 |
.IX Subsection "The Problem" |
| 137 |
.PP |
| 138 |
An early change, in fact the change that made Test2 an idea, was a change to |
| 139 |
the indentation of the subtest note. It was decided it would be more readable |
| 140 |
to outdent the subtest note instead of having it inline with the subtest: |
| 141 |
.PP |
| 142 |
.Vb 4 |
| 143 |
\& # subtest foo |
| 144 |
\& ok 1 \- blah |
| 145 |
\& 1..1 |
| 146 |
\& ok 1 \- subtest foo |
| 147 |
.Ve |
| 148 |
.PP |
| 149 |
The old style indented the note: |
| 150 |
.PP |
| 151 |
.Vb 4 |
| 152 |
\& # subtest foo |
| 153 |
\& ok 1 \- blah |
| 154 |
\& 1..1 |
| 155 |
\& ok 1 \- subtest foo |
| 156 |
.Ve |
| 157 |
.PP |
| 158 |
This breaks tests that do string comparison of TAP output. |
| 159 |
.PP |
| 160 |
\fIThe Fix\fR |
| 161 |
.IX Subsection "The Fix" |
| 162 |
.PP |
| 163 |
.Vb 1 |
| 164 |
\& my $indent = $INC{\*(AqTest2/API.pm\*(Aq} ? \*(Aq\*(Aq : \*(Aq \*(Aq; |
| 165 |
\& |
| 166 |
\& is( |
| 167 |
\& $subtest_output, |
| 168 |
\& "${indent}# subtest foo", |
| 169 |
\& "Got subtest note" |
| 170 |
\& ); |
| 171 |
.Ve |
| 172 |
.PP |
| 173 |
Check if \f(CW$INC{\*(AqTest2/API.pm\*(Aq}\fR is set, if it is then no indentation should be |
| 174 |
expected. If it is not set, then the old Test::Builder is in use, indentation |
| 175 |
should be expected. |
| 176 |
.SH "DISTRIBUTIONS THAT BREAK OR NEED TO BE UPGRADED" |
| 177 |
.IX Header "DISTRIBUTIONS THAT BREAK OR NEED TO BE UPGRADED" |
| 178 |
This is a list of cpan modules that have been known to have been broken by the |
| 179 |
upgrade at one point. |
| 180 |
.SS "WORKS BUT TESTS WILL FAIL" |
| 181 |
.IX Subsection "WORKS BUT TESTS WILL FAIL" |
| 182 |
These modules still function correctly, but their test suites will not pass. If |
| 183 |
you already have these modules installed then you can continue to use them. If |
| 184 |
you are trying to install them after upgrading Test::Builder you will need to |
| 185 |
force installation, or bypass the broken tests. |
| 186 |
.IP Test::DBIx::Class::Schema 4 |
| 187 |
.IX Item "Test::DBIx::Class::Schema" |
| 188 |
This module has a test that appears to work around a Test::Builder bug. The bug |
| 189 |
appears to have been fixed by Test2, which means the workaround causes a |
| 190 |
failure. This can be easily updated, but nobody has done so yet. |
| 191 |
.Sp |
| 192 |
Known broken in versions: 1.0.9 and older |
| 193 |
.IP Device::Chip 4 |
| 194 |
.IX Item "Device::Chip" |
| 195 |
Tests break due to subtest indentation. |
| 196 |
.Sp |
| 197 |
Known broken in version 0.07. Apparently works fine in 0.06 though. Patch has |
| 198 |
been submitted to fix the issue. |
| 199 |
.SS "UPGRADE SUGGESTED" |
| 200 |
.IX Subsection "UPGRADE SUGGESTED" |
| 201 |
These are modules that did not break, but had broken test suites that have |
| 202 |
since been fixed. |
| 203 |
.IP Test::Exception 4 |
| 204 |
.IX Item "Test::Exception" |
| 205 |
Old versions work fine, but have a minor test name behavior that breaks with |
| 206 |
Test2. Old versions will no longer install because of this. The latest version |
| 207 |
on CPAN will install just fine. Upgrading is not required, but is recommended. |
| 208 |
.Sp |
| 209 |
Fixed in version: 0.43 |
| 210 |
.IP Data::Peek 4 |
| 211 |
.IX Item "Data::Peek" |
| 212 |
Some tests depended on \f(CW$!\fR and \f(CW$?\fR being modified in subtle ways. A patch |
| 213 |
was applied to correct things that changed. |
| 214 |
.Sp |
| 215 |
The module itself works fine, there is no need to upgrade. |
| 216 |
.Sp |
| 217 |
Fixed in version: 0.45 |
| 218 |
.IP circular::require 4 |
| 219 |
.IX Item "circular::require" |
| 220 |
Some tests were fragile and required base.pm to be loaded at a late stage. |
| 221 |
Test2 was loading base.pm too early. The tests were updated to fix this. |
| 222 |
.Sp |
| 223 |
The module itself never broke, you do not need to upgrade. |
| 224 |
.Sp |
| 225 |
Fixed in version: 0.12 |
| 226 |
.IP Test::Module::Used 4 |
| 227 |
.IX Item "Test::Module::Used" |
| 228 |
A test worked around a now-fixed planning bug. There is no need to upgrade if |
| 229 |
you have an old version installed. New versions install fine if you want them. |
| 230 |
.Sp |
| 231 |
Fixed in version: 0.2.5 |
| 232 |
.IP Test::Moose::More 4 |
| 233 |
.IX Item "Test::Moose::More" |
| 234 |
Some tests were fragile, but have been fixed. The actual breakage was from the |
| 235 |
subtest comment indentation change. |
| 236 |
.Sp |
| 237 |
No need to upgrade, old versions work fine. Only new versions will install. |
| 238 |
.Sp |
| 239 |
Fixed in version: 0.025 |
| 240 |
.IP Test::FITesque 4 |
| 241 |
.IX Item "Test::FITesque" |
| 242 |
This was broken by a bugfix to how planning is done. The test was updated after |
| 243 |
the bugfix. |
| 244 |
.Sp |
| 245 |
Fixed in version: 0.04 |
| 246 |
.IP Test::Kit 4 |
| 247 |
.IX Item "Test::Kit" |
| 248 |
Old versions work fine, but would not install because Test::Aggregate was in |
| 249 |
the dependency chain. An upgrade should not be needed. |
| 250 |
.Sp |
| 251 |
Fixed in version: 2.15 |
| 252 |
.IP autouse 4 |
| 253 |
.IX Item "autouse" |
| 254 |
A test broke because it depended on Scalar::Util not being loaded. Test2 loads |
| 255 |
Scalar::Util. The test was updated to load Test2 after checking Scalar::Util's |
| 256 |
load status. |
| 257 |
.Sp |
| 258 |
There is no need to upgrade if you already have it installed. |
| 259 |
.Sp |
| 260 |
Fixed in version: 1.11 |
| 261 |
.SS "NEED TO UPGRADE" |
| 262 |
.IX Subsection "NEED TO UPGRADE" |
| 263 |
.IP Test::SharedFork 4 |
| 264 |
.IX Item "Test::SharedFork" |
| 265 |
Old versions need to directly access Test::Builder singleton hash elements. The |
| 266 |
latest version on CPAN will still do this on old Test::Builder, but will defer |
| 267 |
to Test2::IPC on Test2. |
| 268 |
.Sp |
| 269 |
Fixed in version: 0.35 |
| 270 |
.IP Test::Builder::Clutch 4 |
| 271 |
.IX Item "Test::Builder::Clutch" |
| 272 |
This works by doing overriding methods on the singleton, and directly accessing |
| 273 |
hash values on the singleton. A new version has been released that uses the |
| 274 |
Test2 API to accomplish the same result in a saner way. |
| 275 |
.Sp |
| 276 |
Fixed in version: 0.07 |
| 277 |
.IP Test::Dist::VersionSync 4 |
| 278 |
.IX Item "Test::Dist::VersionSync" |
| 279 |
This had Test::Builder2 conditionals. This was fixed by removing the |
| 280 |
conditionals. |
| 281 |
.Sp |
| 282 |
Fixed in version: 1.1.4 |
| 283 |
.IP Test::Modern 4 |
| 284 |
.IX Item "Test::Modern" |
| 285 |
This relied on \f(CW\*(C`Test::Builder\->_try()\*(C'\fR which was a private method, |
| 286 |
documented as something nobody should use. This was fixed by using a different |
| 287 |
tool. |
| 288 |
.Sp |
| 289 |
Fixed in version: 0.012 |
| 290 |
.IP Test::UseAllModules 4 |
| 291 |
.IX Item "Test::UseAllModules" |
| 292 |
Version 0.14 relied on \f(CW\*(C`Test::Builder\->history\*(C'\fR which was available in |
| 293 |
Test::Builder 1.5. Versions 0.12 and 0.13 relied on other Test::Builder |
| 294 |
internals. |
| 295 |
.Sp |
| 296 |
Fixed in version: 0.15 |
| 297 |
.IP Test::More::Prefix 4 |
| 298 |
.IX Item "Test::More::Prefix" |
| 299 |
Worked by applying a role that wrapped \f(CW\*(C`Test::Builder\->_print_comment\*(C'\fR. |
| 300 |
Fixed by adding an event filter that modifies the message instead when running |
| 301 |
under Test2. |
| 302 |
.Sp |
| 303 |
Fixed in version: 0.007 |
| 304 |
.SS "STILL BROKEN" |
| 305 |
.IX Subsection "STILL BROKEN" |
| 306 |
.IP Test::Aggregate 4 |
| 307 |
.IX Item "Test::Aggregate" |
| 308 |
This distribution directly accesses the hash keys in the Test::Builder |
| 309 |
singleton. It also approaches the problem from the wrong angle, please consider |
| 310 |
using Test2::Aggregate for similar functionality and Test2::Harness |
| 311 |
which allows module preloading at the harness level. |
| 312 |
.Sp |
| 313 |
Still broken as of version: 0.373 |
| 314 |
.IP Test::Wrapper 4 |
| 315 |
.IX Item "Test::Wrapper" |
| 316 |
This module directly uses hash keys in the Test::Builder singleton. This |
| 317 |
module is also obsolete thanks to the benefits of Test2. Use \f(CWintercept()\fR |
| 318 |
from Test2::API to achieve a similar result. |
| 319 |
.Sp |
| 320 |
Still broken as of version: 0.3.0 |
| 321 |
.IP Test::ParallelSubtest 4 |
| 322 |
.IX Item "Test::ParallelSubtest" |
| 323 |
This module overrides \f(CWTest::Builder::subtest()\fR and |
| 324 |
\&\f(CWTest::Builder::done_testing()\fR. It also directly accesses hash elements of |
| 325 |
the singleton. It has not yet been fixed. |
| 326 |
.Sp |
| 327 |
Alternatives: Test2::AsyncSubtest and Test2::Workflow (not stable). |
| 328 |
.Sp |
| 329 |
Still broken as of version: 0.05 |
| 330 |
.IP Test::Pretty 4 |
| 331 |
.IX Item "Test::Pretty" |
| 332 |
See <https://github.com/tokuhirom/Test\-Pretty/issues/25> |
| 333 |
.Sp |
| 334 |
The author admits the module is crazy, and he is awaiting a stable release of |
| 335 |
something new (Test2) to completely rewrite it in a sane way. |
| 336 |
.Sp |
| 337 |
Still broken as of version: 0.32 |
| 338 |
.IP Net::BitTorrent 4 |
| 339 |
.IX Item "Net::BitTorrent" |
| 340 |
The tests for this module directly access Test::Builder hash keys. Most, if |
| 341 |
not all of these hash keys have public API methods that could be used instead |
| 342 |
to avoid the problem. |
| 343 |
.Sp |
| 344 |
Still broken in version: 0.052 |
| 345 |
.IP Test::Group 4 |
| 346 |
.IX Item "Test::Group" |
| 347 |
It monkeypatches Test::Builder, and calls it "black magic" in the code. |
| 348 |
.Sp |
| 349 |
Still broken as of version: 0.20 |
| 350 |
.IP Test::Flatten 4 |
| 351 |
.IX Item "Test::Flatten" |
| 352 |
This modifies the Test::Builder internals in many ways. A better was to |
| 353 |
accomplish the goal of this module is to write your own subtest function. |
| 354 |
.Sp |
| 355 |
Still broken as of version: 0.11 |
| 356 |
.IP Log::Dispatch::Config::TestLog 4 |
| 357 |
.IX Item "Log::Dispatch::Config::TestLog" |
| 358 |
Modifies Test::Builder internals. |
| 359 |
.Sp |
| 360 |
Still broken as of version: 0.02 |
| 361 |
.IP Test::Able 4 |
| 362 |
.IX Item "Test::Able" |
| 363 |
Modifies Test::Builder internals. |
| 364 |
.Sp |
| 365 |
Still broken as of version: 0.11 |
| 366 |
.SH "MAKE ASSERTIONS \-> SEND EVENTS" |
| 367 |
.IX Header "MAKE ASSERTIONS -> SEND EVENTS" |
| 368 |
.SS LEGACY |
| 369 |
.IX Subsection "LEGACY" |
| 370 |
.Vb 1 |
| 371 |
\& use Test::Builder; |
| 372 |
\& |
| 373 |
\& # A majority of tools out there do this: |
| 374 |
\& # my $TB = Test::Builder\->new; |
| 375 |
\& # This works, but has always been wrong, forcing Test::Builder to implement |
| 376 |
\& # subtests as a horrific hack. It also causes problems for tools that try |
| 377 |
\& # to replace the singleton (also discouraged). |
| 378 |
\& |
| 379 |
\& sub my_ok($;$) { |
| 380 |
\& my ($bool, $name) = @_; |
| 381 |
\& my $TB = Test::Builder\->new; |
| 382 |
\& $TB\->ok($bool, $name); |
| 383 |
\& } |
| 384 |
\& |
| 385 |
\& sub my_diag($) { |
| 386 |
\& my ($msg) = @_; |
| 387 |
\& my $TB = Test::Builder\->new; |
| 388 |
\& $TB\->diag($msg); |
| 389 |
\& } |
| 390 |
.Ve |
| 391 |
.SS TEST2 |
| 392 |
.IX Subsection "TEST2" |
| 393 |
.Vb 1 |
| 394 |
\& use Test2::API qw/context/; |
| 395 |
\& |
| 396 |
\& sub my_ok($;$) { |
| 397 |
\& my ($bool, $name) = @_; |
| 398 |
\& my $ctx = context(); |
| 399 |
\& $ctx\->ok($bool, $name); |
| 400 |
\& $ctx\->release; |
| 401 |
\& } |
| 402 |
\& |
| 403 |
\& sub my_diag($) { |
| 404 |
\& my ($msg) = @_; |
| 405 |
\& my $ctx = context(); |
| 406 |
\& $ctx\->diag($msg); |
| 407 |
\& $ctx\->release; |
| 408 |
\& } |
| 409 |
.Ve |
| 410 |
.PP |
| 411 |
The context object has API compatible implementations of the following methods: |
| 412 |
.ie n .IP "ok($bool, $name)" 4 |
| 413 |
.el .IP "ok($bool, \f(CW$name\fR)" 4 |
| 414 |
.IX Item "ok($bool, $name)" |
| 415 |
.PD 0 |
| 416 |
.IP diag(@messages) 4 |
| 417 |
.IX Item "diag(@messages)" |
| 418 |
.IP note(@messages) 4 |
| 419 |
.IX Item "note(@messages)" |
| 420 |
.ie n .IP "subtest($name, $code)" 4 |
| 421 |
.el .IP "subtest($name, \f(CW$code\fR)" 4 |
| 422 |
.IX Item "subtest($name, $code)" |
| 423 |
.PD |
| 424 |
.PP |
| 425 |
If you are looking for helpers with \f(CW\*(C`is\*(C'\fR, \f(CW\*(C`like\*(C'\fR, and others, see |
| 426 |
Test2::Suite. |
| 427 |
.SH "WRAP EXISTING TOOLS" |
| 428 |
.IX Header "WRAP EXISTING TOOLS" |
| 429 |
.SS LEGACY |
| 430 |
.IX Subsection "LEGACY" |
| 431 |
.Vb 1 |
| 432 |
\& use Test::More; |
| 433 |
\& |
| 434 |
\& sub exclusive_ok { |
| 435 |
\& my ($bool1, $bool2, $name) = @_; |
| 436 |
\& |
| 437 |
\& # Ensure errors are reported 1 level higher |
| 438 |
\& local $Test::Builder::Level = $Test::Builder::Level + 1; |
| 439 |
\& |
| 440 |
\& $ok = $bool1 || $bool2; |
| 441 |
\& $ok &&= !($bool1 && $bool2); |
| 442 |
\& ok($ok, $name); |
| 443 |
\& |
| 444 |
\& return $bool; |
| 445 |
\& } |
| 446 |
.Ve |
| 447 |
.PP |
| 448 |
Every single tool in the chain from this, to \f(CW\*(C`ok\*(C'\fR, to anything \f(CW\*(C`ok\*(C'\fR calls |
| 449 |
needs to increment the \f(CW$Level\fR variable. When an error occurs Test::Builder |
| 450 |
will do a trace to the stack frame determined by \f(CW$Level\fR, and report that |
| 451 |
file+line as the one where the error occurred. If you or any other tool you use |
| 452 |
forgets to set \f(CW$Level\fR then errors will be reported to the wrong place. |
| 453 |
.SS TEST2 |
| 454 |
.IX Subsection "TEST2" |
| 455 |
.Vb 1 |
| 456 |
\& use Test::More; |
| 457 |
\& |
| 458 |
\& sub exclusive_ok { |
| 459 |
\& my ($bool1, $bool2, $name) = @_; |
| 460 |
\& |
| 461 |
\& # Grab and store the context, even if you do not need to use it |
| 462 |
\& # directly. |
| 463 |
\& my $ctx = context(); |
| 464 |
\& |
| 465 |
\& $ok = $bool1 || $bool2; |
| 466 |
\& $ok &&= !($bool1 && $bool2); |
| 467 |
\& ok($ok, $name); |
| 468 |
\& |
| 469 |
\& $ctx\->release; |
| 470 |
\& return $bool; |
| 471 |
\& } |
| 472 |
.Ve |
| 473 |
.PP |
| 474 |
Instead of using \f(CW$Level\fR to perform a backtrace, Test2 uses a context |
| 475 |
object. In this sample you create a context object and store it. This locks the |
| 476 |
context (errors report 1 level up from here) for all wrapped tools to find. You |
| 477 |
do not need to use the context object, but you do need to store it in a |
| 478 |
variable. Once the sub ends the \f(CW$ctx\fR variable is destroyed which lets future |
| 479 |
tools find their own. |
| 480 |
.SH "USING UTF8" |
| 481 |
.IX Header "USING UTF8" |
| 482 |
.SS LEGACY |
| 483 |
.IX Subsection "LEGACY" |
| 484 |
.Vb 3 |
| 485 |
\& # Set the mode BEFORE anything loads Test::Builder |
| 486 |
\& use open \*(Aq:std\*(Aq, \*(Aq:encoding(utf8)\*(Aq; |
| 487 |
\& use Test::More; |
| 488 |
.Ve |
| 489 |
.PP |
| 490 |
Or |
| 491 |
.PP |
| 492 |
.Vb 5 |
| 493 |
\& # Modify the filehandles |
| 494 |
\& my $builder = Test::More\->builder; |
| 495 |
\& binmode $builder\->output, ":encoding(utf8)"; |
| 496 |
\& binmode $builder\->failure_output, ":encoding(utf8)"; |
| 497 |
\& binmode $builder\->todo_output, ":encoding(utf8)"; |
| 498 |
.Ve |
| 499 |
.SS TEST2 |
| 500 |
.IX Subsection "TEST2" |
| 501 |
.Vb 1 |
| 502 |
\& use Test2::API qw/test2_stack/; |
| 503 |
\& |
| 504 |
\& test2_stack\->top\->format\->encoding(\*(Aqutf8\*(Aq); |
| 505 |
.Ve |
| 506 |
.PP |
| 507 |
Though a much better way is to use the Test2::Plugin::UTF8 plugin, which is |
| 508 |
part of Test2::Suite. |
| 509 |
.SH "AUTHORS, CONTRIBUTORS AND REVIEWERS" |
| 510 |
.IX Header "AUTHORS, CONTRIBUTORS AND REVIEWERS" |
| 511 |
The following people have all contributed to this document in some way, even if |
| 512 |
only for review. |
| 513 |
.IP "Chad Granum (EXODIST) <[email protected]>" 4 |
| 514 |
.IX Item "Chad Granum (EXODIST) <[email protected]>" |
| 515 |
.SH SOURCE |
| 516 |
.IX Header "SOURCE" |
| 517 |
The source code repository for Test2 can be found at |
| 518 |
<https://github.com/Test\-More/test\-more/>. |
| 519 |
.SH MAINTAINER |
| 520 |
.IX Header "MAINTAINER" |
| 521 |
.IP "Chad Granum <[email protected]>" 4 |
| 522 |
.IX Item "Chad Granum <[email protected]>" |
| 523 |
.SH COPYRIGHT |
| 524 |
.IX Header "COPYRIGHT" |
| 525 |
Copyright 2020 Chad Granum <[email protected]>. |
| 526 |
.PP |
| 527 |
This program is free software; you can redistribute it and/or |
| 528 |
modify it under the same terms as Perl itself. |
| 529 |
.PP |
| 530 |
See <https://dev.perl.org/licenses/> |