.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Test2::Manual::Anatomy::Context 3pm" .TH Test2::Manual::Anatomy::Context 3pm "2019-05-06" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test2::Manual::Anatomy::Context \- Internals documentation for the Context objects. .SH "DESCRIPTION" .IX Header "DESCRIPTION" This document explains how the Test2::API::Context object works. .SH "WHAT IS THE CONTEXT OBJECT?" .IX Header "WHAT IS THE CONTEXT OBJECT?" The context object is one of the key components of Test2, and makes many features possible that would otherwise be impossible. Every test tool starts by getting a context, and ends by releasing the context. A test tool does all its work between getting and releasing the context. The context instance is the primary interface for sending events to the Test2 stack. Finally the context system is responsible for tracking what file and line number a tool operates on, which is critical for debugging. .SS "\s-1PRIMARY INTERFACE FOR TEST TOOLS\s0" .IX Subsection "PRIMARY INTERFACE FOR TEST TOOLS" Nearly every Test2 based tool should start by calling \f(CW\*(C`$ctx = Test2::API::context()\*(C'\fR in order to get a context object, and should end by calling \f(CW\*(C`$ctx\->release()\*(C'\fR. Once a tool has its context object it can call methods on the object to send events or have other effects. Nearly everything a test tool needs to do should be done through the context object. .SS "\s-1TRACK FILE AND LINE NUMBERS FOR ERROR REPORTING\s0" .IX Subsection "TRACK FILE AND LINE NUMBERS FOR ERROR REPORTING" When you call \f(CW\*(C`Test2::API::Context\*(C'\fR a new context object will be returned. If there is already a context object in effect (from a different point in the stack) you will get a clone of the existing one. If there is not already a current context then a completely new one will be generated. When a new context is generated Test2 will determine the file name and line number for your test code, these will be used when reporting any failures. .PP Typically the file and line number will be determined using \f(CW\*(C`caller()\*(C'\fR to look at your tools caller. The \f(CW$Test::Builder::Level\fR will be respected if detected, but is discouraged in favor of just using context objects at every level. .PP When calling \f(CW\*(C`Test2::API::Context()\*(C'\fR you can specify the \&\f(CW\*(C`level => $count\*(C'\fR arguments if you need to look at a deeper caller. .SS "\s-1PRESERVE $\s0?, $!, $^E \s-1AND\s0 $@" .IX Subsection "PRESERVE $?, $!, $^E AND $@" When you call \f(CW\*(C`Test2::API::context()\*(C'\fR the current values of \f(CW$?\fR, \f(CW$!\fR, \&\f(CW$^E\fR, and \f(CW$@\fR are stored in the context object itself. Whenever the context is released the original values of these variables will be restored. This protects the variables from any side effects caused by testing tools. .SS "\s-1FINALIZE THE API STATE\s0" .IX Subsection "FINALIZE THE API STATE" Test2::API works via a hidden singleton instance of Test2::API::Instance. The singleton has some state that is not set in stone until the last possible minute. The last possible minute happens to be the first time a context is acquired. State includes \s-1IPC\s0 instance, Formatter class, Root \s-1PID,\s0 etc. .SS "\s-1FIND/CREATE THE CURRENT/ROOT HUB\s0" .IX Subsection "FIND/CREATE THE CURRENT/ROOT HUB" Test2 has a stack of hubs, the stack can be accessed via Test2::API::test2_stack. When you get a context it will find the current hub, if there is no current hub then the root one will be initialized. .SS "\s-1PROVIDE HOOKS\s0" .IX Subsection "PROVIDE HOOKS" There are hooks that run when contexts are created, found, and released. See Test2::API for details on these hooks and how to use them. .SH "SEE ALSO" .IX Header "SEE ALSO" Test2::Manual \- Primary index of the manual. .SH "SOURCE" .IX Header "SOURCE" The source code repository for Test2\-Manual can be found at \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. .SH "MAINTAINERS" .IX Header "MAINTAINERS" .IP "Chad Granum " 4 .IX Item "Chad Granum " .SH "AUTHORS" .IX Header "AUTHORS" .PD 0 .IP "Chad Granum " 4 .IX Item "Chad Granum " .PD .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2018 Chad Granum . .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See \fIhttp://dev.perl.org/licenses/\fR