- About
-
Comparison Testing Library
- The comparison library is used by 'is()', 'like()', and 'is_deeply()'
- The Test::Stream::Plugin::Compare plugin is the primary interface
- Does deep structure comparisons
- Very flexible
- Very powerful
- Easy to extend
- Helpful diagnostics
- Advanced
-
Advanced comparisons
- The '$expect' structure can be simple values or references
- With like() a regex in '$expect' will be used to verify the value in '$got'
- when a tool encounters a custom check it will use it
- Some common check types have shortcuts you can use.
- Shortcut
-
Shortcuts
Shortcuts for some common types of checks:
- T()
- Check for a True value
- F()
- Check for a false (but existant) value
- D()
- Check for a defined value
- DNE()
- Check that no value exists
- FDNE()
- Check for either false or DNE
These are most useful for checking bounds in a 'like', or
ensuring something is present, but not caring what it is.
- Pattern
-
Pattern Matching
- match
- Check that the value matches the pattern
- mismatch
- Check that the value does not match the pattern
- 'like()' will convert any regexes into 'match' checks for you.
- 'is()' will compare regexes in their string representation.
- Both will use pattern matching when given a 'match' or
'mismatch' check.
- Custom
-
Custom Checks
- string
- Explicit string compare
- number
- Explicit number compare
- validator
- Custom sub as a check
- exact_ref
- Check for an exact reference
- Sets
-
Set Checks
- in_set
- Check that the value is in the set
- not_in_set
- Check that the value is not in the set
- check_set
- Check that the value matches everything in the set
- Arrays
-
Array Checks
- array
- Declare an array check
- item
- Declare an array item
- filter_items
- Apply a filter to the remaining array items
- end
- Declare the end of the array
- Hashes
-
Hash Checks
- hash
- Declare a hash
- field
- Declare a hash field
- end
- Declare that there are no more fields
- Meta
-
Meta Checks
- meta
- Declare a meta check
- prop
- Declare a meta property to check
- Objects
-
Object Checks
- object
- Declare an object check
- call
- Declare an object method result
- prop
- Declare a meta property
- field
- Declare a hash field (if object is a hash)
- item
- Declare an array item (if object is an array)
Note: methods are called in scalar context
- Events
-
Event Checks
- Used to validate Test::Stream events.
- Has everything object checks do.
- Tells you event generation line numbers.
- Extra meta-checks (line number, file, etc)
This is best when combined with intercept: