1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use Test::More tests => 7; 7use Parse::ErrorString::Perl; 8 9my $parser = Parse::ErrorString::Perl->new; 10 11# use strict; 12# use warnings; 13# use diagnostics; 14# 15# my $empty; 16# my $length = length($empty); 17# 18# my $zero = 0; 19# my $result = 5 / 0; 20 21my $msg_split = <<'ENDofMSG'; 22Use of uninitialized value $empty in length at 23 c:\my\very\long\path\to\this\perl\script\called\error.pl line 6 (#1) 24 (W uninitialized) An undefined value was used as if it were already 25 defined. It was interpreted as a "" or a 0, but maybe it was a mistake. 26 To suppress this warning assign a defined value to your variables. 27 28 To help you figure out what was undefined, perl will try to tell you the 29 name of the variable (if any) that was undefined. In some cases it cannot 30 do this, so it also tells you what operation you used the undefined value 31 in. Note, however, that perl optimizes your program and the operation 32 displayed in the warning may not necessarily appear literally in your 33 program. For example, "that $foo" is usually optimized into "that " 34 . $foo, and the warning will refer to the concatenation (.) operator, 35 even though there is no . in your program. 36 37Illegal division by zero at 38 c:\my\very\long\path\to\this\perl\script\called\error.pl line 9 (#2) 39 (F) You tried to divide a number by 0. Either something was wrong in 40 your logic, or you need to put a conditional in to guard against 41 meaningless input. 42 43Uncaught exception from user code: 44 Illegal division by zero at 45 c:\my\very\long\path\to\this\perl\script\called\error.pl line 9. 46 at c:\my\very\long\path\to\this\perl\script\called\error.pl line 9 47ENDofMSG 48 49my @errors_split = $parser->parse_string($msg_split); 50is( scalar(@errors_split), 2, 'msg_split results' ); 51is( $errors_split[0]->message, 'Use of uninitialized value $empty in length', 'msg_split 1 message' ); 52is( $errors_split[0]->file_msgpath, 'c:\my\very\long\path\to\this\perl\script\called\error.pl', 'msg_split 1 file' ); 53is( $errors_split[0]->line, 6, 'msg_split 1 line' ); 54is( $errors_split[1]->message, 'Illegal division by zero', 'msg_split 2 message' ); 55is( $errors_split[1]->file_msgpath, 'c:\my\very\long\path\to\this\perl\script\called\error.pl', 'msg_split 2 file' ); 56is( $errors_split[1]->line, 9, 'msg_split 2 line' ); 57