Test::Should::Engine - Should it be OK?
use Test::Should::Engine; Test::Should::Engine->run('should_be_ok', 1);
Test::Should::Engine is yet another assertion library for Perl5.
You don't need to use this module directly. This module may include to other testing libraries.
This module is currently under development. API MAY change WITHOUT notice.
This method checks the $subject by $pattern with @args and return boolean value.
In this section, the code uses Test::Should.
1->should_be_ok()
Assert truthfulness.
[]->should_be_empty() ''->should_be_empty()
On ArrayRef, it doesn't have a elements.
On String, the length is zero.
[1,2,3]->should_be_equal([1,2,3])
strict equality.
MyObj->new()->should_be_a('MyObj'); MyObj->new()->should_be_an('ARRAY');
Checks type.
9->should_be_above(4)
Assert numeric value above the given value.
2->should_be_below(4)
Assert numeric value below the given value.
'hoge'->should_match(qr/h.ge/);
Assert regexp match.
'hoge'->should_have_length(4); [1,2,3]->should_have_length(3);
Assert the length has a value of the given number.
# array [1,2,3]->should_include(3) [1,2,3]->should_not_include(4) # string 'foo bar baz'.should.include('foo')
Assert the subject includes a value.
Assert an exception is thrown:
(sub { die })->should_throw();
Assert an exception is not thrown:
(sub { 1 })->should_not_throw();
Assert exception message matches regexp:
(sub { die "Foo" })->should_throw(qr/F/);
Invert the result.
You can embed this module to your code by following style :)
I'll be release this style module named by Test::Should.
You can see more details in t/01_autobox.t.
use Test::Should::Engine; use Test::More; { package UNIVERSAL; sub DESTROY { } our $AUTOLOAD; sub AUTOLOAD { $AUTOLOAD =~ s/.*:://; my $test = Test::Should::Engine->run($AUTOLOAD, @_); Test::More->builder->ok($test); } } # and test code (bless [], 'Foo')->should_be_ok(); (bless [], 'Foo')->should_be_a('Foo'); (bless [], 'Foo')->should_not_be_a('Bar'); done_testing;
Test::Should depends to autobox. autobox is not needed by some users.
Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>
Most part of features are ported from https://github.com/visionmedia/should.js, thanks!
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::Should::Engine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Should::Engine
CPAN shell
perl -MCPAN -e shell install Test::Should::Engine
For more information on module installation, please visit the detailed CPAN module installation guide.