Fellow Monks!
I have a script in my latest distribution that I am adding unit tests for. I've gone with the simple caller approach:
bin/script:
#!/usr/bin/perl use 5.010; use strict; use warnings; main(@ARGV) unless caller; sub main { die 'main() was run' }
This script exits with no warnings and normal status when require'd via perl -Ibin -e 'require "script";', but die()s as expected when run directly from the commandline.
t/bin/load.t:
#!perl use 5.010; use strict; use lib qw(bin); use Test::More; #use Test::Warnings ':all'; # <-- BEGIN { eval { require 'script' }; BAIL_OUT("bin/script did not load: $@") if $@; } done_testing;
When run via make test, I get bin/load.t ........ skipped: (no reason given) and 255 exit status. When run via prove bin/load.t, I get the same:
t/bin/00-run.t (Wstat: 65280 Tests: 0 Failed: 0) Non-zero exit status: 255
I don't know why it's failing. Interestingly, it only failed when I started removing extraneous use lines from bin/load.t. Removing Test::Warnings was the one that stopped it from working! If the use Test::Warnings ':all'; line is uncommented, the test script succeeds.
The BEGIN block seemingly makes no difference. The results are the same if the code is run outside of BEGIN { ... }. Also, if I add a die to the top of bin/script it (correctly) fails with the BAIL_OUT() message from bin/load.t.
So the abnormal exit has me confused. Why is it failing, and how do I fix it? I guess the success under Test::Warnings should be a clue, but I would expect the tests to be more sensitive to warnings when Test::Warnings is included (due to the extra test it adds), not less sensitive.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |