![]() | |
![]() |
![]() |
![]() | |
![]() | |
Minimal Example for Test::Harness | |
![]() |
package Mymodule; sub Mysub { return "This is my expected output\n"; } 1;
#!/home/toma/perl5i/bin/perl use strict; use Mymodule; my $result= &Mymodule::Mysub(); print $result;
#!/home/toma/perl5i/bin/perl use strict; use Test::Harness; my @tests; push @tests, qw ( t/tst1.t t/tst2.t ); runtests(@tests);
use strict; print "1..2\n"; print "ok 1\n"; print "ok 2\n";
#!/home/toma/perl5i/bin/perl use strict; use Mymodule; my $result= &Mymodule::Mysub(); print $result, "\n"; print "You can print all kinds of garbage in your test\n"; print "1..2\n"; if ($result =~ /This is/i) { print "ok 1\n" } else {print "not ok 1\n"} if ($result =~ /expected/i) { print "ok 2\n" } else {print "not ok 2\n"} print "Anything that makes sense at the time\n";
#!/home/toma/perl5i/bin/perl use strict; use Mymodule; my $result= &Mymodule::Mysub(); print $result, "\n"; print "You can print all kinds of garbage in your test\n"; print "1..3\n"; if ($result ne "") { print "ok 1\n" } else {print "not ok 1\n"} if ($result =~ /expected-but-not-there/i) { print "ok 2\n" } else {print "not ok 2\n"} if ($result ne "only the good stuff") { print "not " } print "ok 3\n"; print "Anything that makes sense at the time\n";
test: perl tst.pl
perl tst.pl t/tst1..............ok t/tst2..............ok t/tst3..............FAILED tests 2-3 Failed 2/2 tests, 0.00% okay Failed Test Status Wstat Total Fail Failed List of failed ------------------------------------------------------------------------------- t/tst3.t 2 2 100.00% 2-3 Failed 1/3 test scripts, 66.67% okay. 1/6 subtests failed, 83.33% okay. make: *** [test] Error 29
use FindBin; use lib "$FindBin::Bin/..";This has the effect of adding the relative path ".." to the INC variable at compile time. You might hope that the code use lib ".."; would work, but it doesn't. Ordinary use lib "/path/to/my/file/index.html"; commands add to the INC path properly, but can't handle relative paths.