diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-02-10 11:14:23 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-02-10 11:14:23 +0000 |
commit | d47bdea7d8909b1e611d287c190124657af11c76 (patch) | |
tree | 86f1f65bf0507be6d290c17d36d13046230dc476 /t/test.pl | |
parent | 17a3df4c6a07533e2c03c46fdd27e3ee295d61d0 (diff) | |
download | perl-d47bdea7d8909b1e611d287c190124657af11c76.tar.gz |
In test.pl, validate that require_ok() and use_ok() are called correctly.
It only provides a subset of the Test::More functionality, but could
inadvertently be used in a way which is not compatible with Test::More, which
is not the intent.
Diffstat (limited to 't/test.pl')
-rw-r--r-- | t/test.pl | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -413,20 +413,29 @@ sub eq_hash { !$fail; } +# We only provide a subset of the Test::More functionality. sub require_ok ($) { my ($require) = @_; - eval <<REQUIRE_OK; + if ($require =~ tr/[A-Za-z0-9:.]//c) { + fail("Invalid character in \"$require\", passed to require_ok"); + } else { + eval <<REQUIRE_OK; require $require; REQUIRE_OK - _ok(!$@, _where(), "require $require"); + is($@, '', _where(), "require $require"); + } } sub use_ok ($) { my ($use) = @_; - eval <<USE_OK; + if ($use =~ tr/[A-Za-z0-9:.]//c) { + fail("Invalid character in \"$use\", passed to use"); + } else { + eval <<USE_OK; use $use; USE_OK - _ok(!$@, _where(), "use $use"); + is($@, '', _where(), "use $use"); + } } # runperl - Runs a separate perl interpreter. |