Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test exception (#28)
  • Loading branch information
davorg committed Oct 17, 2016
1 parent c4409b0 commit ac5f303
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
1 change: 1 addition & 0 deletions Build.PL
Expand Up @@ -17,6 +17,7 @@ my $build = Module::Build->new(
},
build_requires => {
Test::More => 0,
Test::Exception => 0,
String::Approx => 0,
Text::Metaphone => 0,
Text::Soundex => 0,
Expand Down
4 changes: 2 additions & 2 deletions t/basic.t
@@ -1,4 +1,5 @@
use Test::More;
use Test::Exception;

use_ok('Symbol::Approx::Sub');

Expand All @@ -10,7 +11,6 @@ is(a(), 'aa', 'a() calls aa()');

is(b(), 'bb', 'b() calls bb()');

eval { c() };
like($@, qr/^REALLY/, 'Correct exception thrown');
throws_ok { c() } qr/^REALLY/, 'Correct exception thrown';

done_testing;
42 changes: 13 additions & 29 deletions t/invalid.t
@@ -1,52 +1,36 @@
use Test::More;
use Test::Exception;

require Symbol::Approx::Sub;

note('Hashref transformer');
eval {
throws_ok {
Symbol::Approx::Sub->import(xform => {});
};

ok($@, 'Got an exception');
like($@, qr/^Invalid transformer/, 'Got the right exception');
} qr/^Invalid transformer/, 'Got the right exception';

note('Hashref transformer in an arrayref');
eval {
throws_ok {
Symbol::Approx::Sub->import(xform => [{}]);
};

ok($@, 'Got an exception');
like($@, qr/^Invalid transformer/, 'Got the right exception');
} qr/^Invalid transformer/, 'Got the right exception';

note('Hashref matcher');
eval {
throws_ok {
Symbol::Approx::Sub->import(match => {});
};

ok($@, 'Got an exception');
like($@, qr/^Invalid matcher/, 'Got the right exception');
} qr/^Invalid matcher/, 'Got the right exception';

note('Arrayref matcher');
eval {
throws_ok {
Symbol::Approx::Sub->import(match => []);
};

ok($@, 'Got an exception');
like($@, qr/^Invalid matcher/, 'Got the right exception');
} qr/^Invalid matcher/, 'Got the right exception';

note('Hashref chooser');
eval {
throws_ok {
Symbol::Approx::Sub->import(choose => {});
};

ok($@, 'Got an exception');
like($@, qr/^Invalid chooser/, 'Got the right exception');
} qr/^Invalid chooser/, 'Got the right exception';

note('Arrayref chooser');
eval {
throws_ok {
Symbol::Approx::Sub->import(choose => []);
};
} qr/^Invalid chooser/, 'Got the right exception';

ok($@, 'Got an exception');
like($@, qr/^Invalid chooser/, 'Got the right exception');
done_testing;
5 changes: 2 additions & 3 deletions t/string_approx.t
@@ -1,4 +1,5 @@
use Test::More;
use Test::Exception;

use_ok('Symbol::Approx::Sub', match => 'String::Approx');

Expand All @@ -10,8 +11,6 @@ is(a(), 'aa', 'a() calls aa()');

is(test_it(), 'test', 'test_it() calls test()');

eval { zzz_not_there() };
ok($@, 'Exception thrown');
like($@, qr/^REALLY/, 'Correct exception thrown');
throws_ok { zzz_not_there() } qr/^REALLY/, 'Correct exception thrown';

done_testing;

0 comments on commit ac5f303

Please sign in to comment.