package Assert; require Exporter; our @ISA = 'Exporter'; our @EXPORT = qw[ assertOk assert ]; my $nTests = 0; sub assertOk (&$;) { my( $package, $file, $line ) = caller; my( $code, $desc ) = @_; warn sprintf "%s %d # %s [%s(%d)]\n", ( $code->() ? 'ok' : 'not ok' ), ++$nTests, $desc, $file, $line ; } 1; #### #! perl -slw use strict; use Assert; my $fred = 1; assertOk { $fred eq 'fred' } 'Check $fred'; assertOk { 2 == 1 } 'Check math'; $fred = 'fred'; assertOk { $fred eq 'fred' } 'Check $fred'; assertOk { 2 == 2 } 'Check math'; __END__ [ 3:14:54.52]C:\test>t-Assert.pl not ok 1 # Check $fred [C:\test\t-Assert.pl(7)] not ok 2 # Check math [C:\test\t-Assert.pl(8)] ok 3 # Check $fred [C:\test\t-Assert.pl(12)] ok 4 # Check math [C:\test\t-Assert.pl(13)] #### /path/file(23): Error: some relevant error text here /path/file(32): Warning: some other relevant text here /path/file(64): Passed: more text