- Tools?
-
What are tools?
In Test2, Tools are functions that produce testing events.
What is a "testing event"?
Events are generated whenever you make an assertions, set a plan, or
produce diagnostics.
Where can I find tools?
Test2 makes the Test2::Tools::* mamespaces available to anyone
who wants to write new tools.
Please note: not all tools are listed here.
- Basic
-
Test2::Tools::Basic
These are the 'essential' tools you always want handy.
See the module documentation for more.
- Class
-
Test2::Tools::Class
These are tools to help you verify your classes.
* Note: isa_ok() takes different arguments compared to Test::More::isa_ok()
- All 3 functions are consistent.
- First argument is always a class or instance.
- All additional arguments are items to check.
- Each calls the object method you expect.
- NEW!If the second argument is an array it is taken as a list of things to check, allowing a name as the third argument.
See the module documentation for more.
-
- Compare
-
Test2::Tools::Compare
This has been moved to its own section above, see the "compare" section.
-
- Defer
-
Test2::Tools::Defer
Record values now, but run test later.
- def() stores the function name, and all arguments to run later.
- do_def() will run the stored functions and arguments.
- Useful if you need to test conditions before loading Test2.
-
- Encoding
-
Test2::Tools::Encoding
Correctly set the output encoding for the test.
This seems trivial, but it is something that was very hard to do with Test::Builder.
-
- Exception
-
Test2::Tools::Exception
This is similar to Test::Fatal, but it intentionally does much less.
- dies { ... } will return any exception thrown, undef if no exception is thrown.
- lives { ... } will return false and use warn to report the exception.
-
- Exports
-
Test2::Tools::Exports
This provides tools to verifiy that methods are present in your namespace. This is intended to verify exports.
- Will not look in parent namespaces.
- Subs must be present in current package symbol table.
- People used to use can_ok() for this, but that is not correct.
-
- Ref
-
Test2::Tools::Ref
Tools for validating and comparing references.
Setup:
ref_ok() can check that something is a ref, or a ref of a specific type:
ref_is() can check that 2 refs are the same exact ref:
ref_is_not() is the opposite:
-
- Subtest
-
Test2::Tools::Subtest
This provides tools for writing buffered or unbuffered subtests.
'Buffered' is the new Test2 style. The old Test::More style is 'streamed':
Note: Test2::V0 provides subtest() which is buffered.
-
- Warnings
-
Test2::Tools::Warnings
This is a collection of tools that can be used to test code that issues
warnings.
- warns() returns the number of warnings (and silences them)
- warning() returns a single warning (more than 1 is an error)
- warnings() return an arrayref with all warnings (always an arrayref)
- no_warnings() returns false if there is a warning (warnings are not silenced)
-