I'm currently working on building a library to implement in Project Euler puzzles. I've gotten to the point of building tests but at some point my tests fail. Everything imports okay but as soon is I test for the existence of a subroutine my newly created test fails. I initially started Test::More but to simplify things I switched to Test::Simple. With each run, even after simplifying to less complex functions for testing, I get the same error output. Is there some error in my code that I'm overlooking or is there some aspect of my system or environment that is affecting this?
NOTE: I have reviewed Test::Tutorial several times in addition to Test::Simple and Test::More docs. I also made sure to review the Perl Docs for the relevant functions (defined and exists). Using Perl 5.18.2 on Ubuntu 14.04.
Here's the output:
t/00-load.t ....... 1/? # Testing EulerUtils 0.01, Perl 5.018002, /usr/bin/perl
t/00-load.t ....... ok
t/Qual.t .......... 1/2
# Failed test 'isEven() exists'
# at t/Qual.t line 8.
# Looks like you failed 1 test of 2.
t/Qual.t .......... Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests
t/boilerplate.t ... ok
t/manifest.t ...... skipped: Author tests not required for installation
t/pod-coverage.t .. ok
t/pod.t ........... ok
Test Summary Report
-------------------
t/Qual.t (Wstat: 256 Tests: 2 Failed: 1)
Failed test: 2
Non-zero exit status: 1
Files=6, Tests=10, 0 wallclock secs ( 0.06 usr 0.01 sys + 0.23 cusr 0.04 csys = 0.34 CPU)
Result: FAIL
Failed 1/6 test programs. 1/10 subtests failed.
Nothing object oriented, by the way...at least so far. I made a dummy test too, which explains the 2 subtests.
The test itself (updated to make the library location explicit):
use v5.18.2;
use strict;
use warnings;
use diagnostics;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::Simple tests => 1;
use Qual;
ok( defined(&isEven), 'isEven() exists' );
The subroutine from the module itself, made with module-starter:
...
sub isEven {
my $n = shift;
return 1 if ($n % 2 == 0);
}
...
Let me know if there's something needed.
If that test is failing, you apparently aren't exporting isEven from Qual. Assuming you are using Exporter, if it is in
@EXPORT_OK
, you need to explicitly request it in Qual.t:or move it to
@EXPORT
(though nowadays it is recommended that nothing be exported by default).