Skip to content

Instantly share code, notes, and snippets.

@petdance
Created May 15, 2017 22:14
Show Gist options
  • Save petdance/709b179c5b8887339fe91ba3841fb67b to your computer and use it in GitHub Desktop.
Save petdance/709b179c5b8887339fe91ba3841fb67b to your computer and use it in GitHub Desktop.
$ cat foo.t
#!/var/perl/bin/perl
use strict;
use warnings;
use lib '/home/alester/Test-Simple-1.302085/blib/lib';
use Test::Tester;
use Test::More tests => 1;
diag $Test::Tester::VERSION;
check_test( sub { is_fs_custnum( 'GARBAGECRAP', 'Garbage!' ) }, { ok => 0 }, 'Garbage should fail' );
sub is_fs_custnum : prototype($;$) {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $fs_custnum = shift;
my $msg = shift;
return subtest "is_fs_custnum($msg)" => sub {
plan tests => 3;
my $num = substr($fs_custnum, 0, 7); # First seven digits.
my $ext = substr($fs_custnum, 7); # Everything after.
like( $num, qr/^[A-Z0-9-]{1,7}$/, $msg );
like( $ext, qr/^\d{3}$/, 'Last part is exactly three digits...' );
isnt( $ext, '000', '... and is not 000.' );
};
}
[17:12:55] (trunk) football:~/tw $ prove -v foo.t
[17:13:03] foo.t ..
1..1
# 1.302085
# Subtest: is_fs_custnum(Garbage!)
not ok 1 - Test 'Garbage should fail' completed
# Failed test 'Test 'Garbage should fail' completed'
# at foo.t line 12.
# Can't call method "top" on an undefined value at /home/alester/Test-Simple-1.302085/blib/lib/Test/Builder.pm line 45.
ok 2 - Test 'Garbage should fail' no premature diagnostication
not ok 3 - Test 'Garbage should fail' result count
# Failed test 'Test 'Garbage should fail' result count'
# at foo.t line 12.
# got: 0
# expected: 1
not ok 4 - subtest '' of 'Garbage should fail' compare ok
# Failed test 'subtest '' of 'Garbage should fail' compare ok'
# at foo.t line 12.
# got: undef
# expected: '0'
not ok 5 - checking depth
# Failed test 'checking depth'
# at foo.t line 12.
# got: undef
# expected: '1'
# You need to change $Test::Builder::Level
# Test ended with extra hubs on the stack!
# No tests run!
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 1/1 subtests
[17:13:04]
Test Summary Report
-------------------
foo.t (Wstat: 65280 Tests: 0 Failed: 0)
Non-zero exit status: 255
Parse errors: Bad plan. You planned 1 tests but ran 0.
Files=1, Tests=0, 1 wallclock secs ( 0.02 usr 0.00 sys + 0.06 cusr 0.00 csys = 0.08 CPU)
Result: FAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment