1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use Test::More tests => 25; 7use Parse::ErrorString::Perl; 8 9my $parser = Parse::ErrorString::Perl->new; 10 11# use strict; 12# use warnings; 13# use diagnostics; 14# 15# $kaboom; 16 17my $msg_compile = <<'ENDofMSG'; 18Global symbol "$kaboom" requires explicit package name at error.pl line 5. 19Execution of error.pl aborted due to compilation errors (#1) 20 (F) You've said "use strict" or "use strict vars", which indicates 21 that all variables must either be lexically scoped (using "my" or "state"), 22 declared beforehand using "our", or explicitly qualified to say 23 which package the global variable is in (using "::"). 24 25Uncaught exception from user code: 26 Global symbol "$kaboom" requires explicit package name at error.pl line 5. 27Execution of error.pl aborted due to compilation errors. 28 at error.pl line 5 29 30ENDofMSG 31 32my @errors_compile = $parser->parse_string($msg_compile); 33is( scalar(@errors_compile), 1, 'msg_compile results' ); 34is( $errors_compile[0]->message, 'Global symbol "$kaboom" requires explicit package name', 'msg_compile message' ); 35is( $errors_compile[0]->file_msgpath, 'error.pl', 'msg_compile file' ); 36is( $errors_compile[0]->line, 5, 'msg_compile line' ); 37 38 39# use strict; 40# use warnings; 41# use diagnostics; 42# 43# my $empty; 44# my $length = length($empty); 45# 46# my $zero = 0; 47# my $result = 5 / 0; 48 49my $msg_runtime = <<'ENDofMSG'; 50Use of uninitialized value $empty in length at error.pl line 6 (#1) 51 (W uninitialized) An undefined value was used as if it were already 52 defined. It was interpreted as a "" or a 0, but maybe it was a mistake. 53 To suppress this warning assign a defined value to your variables. 54 55 To help you figure out what was undefined, perl will try to tell you the 56 name of the variable (if any) that was undefined. In some cases it cannot 57 do this, so it also tells you what operation you used the undefined value 58 in. Note, however, that perl optimizes your program and the operation 59 displayed in the warning may not necessarily appear literally in your 60 program. For example, "that $foo" is usually optimized into "that " 61 . $foo, and the warning will refer to the concatenation (.) operator, 62 even though there is no . in your program. 63 64Illegal division by zero at error.pl line 9 (#2) 65 (F) You tried to divide a number by 0. Either something was wrong in 66 your logic, or you need to put a conditional in to guard against 67 meaningless input. 68 69Uncaught exception from user code: 70 Illegal division by zero at error.pl line 9. 71 at error.pl line 9 72ENDofMSG 73 74my @errors_runtime = $parser->parse_string($msg_runtime); 75is( scalar(@errors_runtime), 2, 'msg_runtime results' ); 76is( $errors_runtime[0]->message, 'Use of uninitialized value $empty in length', 'msg_runtime 1 message' ); 77is( $errors_runtime[0]->file_msgpath, 'error.pl', 'msg_runtime 1 file' ); 78is( $errors_runtime[0]->line, 6, 'msg_runtime 1 line' ); 79is( $errors_runtime[1]->message, 'Illegal division by zero', 'msg_runtime 2 message' ); 80is( $errors_runtime[1]->file_msgpath, 'error.pl', 'msg_runtime 2 file' ); 81is( $errors_runtime[1]->line, 9, 'msg_runtime 2 line' ); 82 83# use strict; 84# use warnings; 85# use diagnostics; 86# 87# my $string = 'tada'; 88# kaboom 89# 90# my $length = 5; 91 92my $msg_near = <<'ENDofMSG'; 93syntax error at error.pl line 8, near "kaboom 94 95my " 96Global symbol "$length" requires explicit package name at error.pl line 8. 97Execution of error.pl aborted due to compilation errors (#1) 98 (F) Probably means you had a syntax error. Common reasons include: 99 100 A keyword is misspelled. 101 A semicolon is missing. 102 A comma is missing. 103 An opening or closing parenthesis is missing. 104 An opening or closing brace is missing. 105 A closing quote is missing. 106 107 Often there will be another error message associated with the syntax 108 error giving more information. (Sometimes it helps to turn on -w.) 109 The error message itself often tells you where it was in the line when 110 it decided to give up. Sometimes the actual error is several tokens 111 before this, because Perl is good at understanding random input. 112 Occasionally the line number may be misleading, and once in a blue moon 113 the only way to figure out what's triggering the error is to call 114 perl -c repeatedly, chopping away half the program each time to see 115 if the error went away. Sort of the cybernetic version of S<20 116 questions>. 117 118Uncaught exception from user code: 119 syntax error at error.pl line 8, near "kaboom 120 121my " 122Global symbol "$length" requires explicit package name at error.pl line 8. 123Execution of error.pl aborted due to compilation errors. 124 at error.pl line 8 125ENDofMSG 126 127my @errors_near = $parser->parse_string($msg_near); 128is( scalar(@errors_near), 2, 'msg_near results' ); 129is( $errors_near[0]->message, 'syntax error', 'msg_near 1 message' ); 130is( $errors_near[0]->file_msgpath, 'error.pl', 'msg_near 1 file' ); 131is( $errors_near[0]->line, 8, 'msg_near 1 line' ); 132is( $errors_near[1]->message, 'Global symbol "$length" requires explicit package name', 'msg_near 2 message' ); 133is( $errors_near[1]->file_msgpath, 'error.pl', 'msg_near 2 file' ); 134is( $errors_near[1]->line, 8, 'msg_near 2 line' ); 135 136# use strict; 137# use warnings; 138# use diagnostics; 139# 140# if (1) { if (2) 141 142my $msg_at = <<'ENDofMSG'; 143syntax error at error.pl line 5, at EOF 144Missing right curly or square bracket at error.pl line 5, at end of line 145Execution of error.pl aborted due to compilation errors (#1) 146 (F) Probably means you had a syntax error. Common reasons include: 147 148 A keyword is misspelled. 149 A semicolon is missing. 150 A comma is missing. 151 An opening or closing parenthesis is missing. 152 An opening or closing brace is missing. 153 A closing quote is missing. 154 155 Often there will be another error message associated with the syntax 156 error giving more information. (Sometimes it helps to turn on -w.) 157 The error message itself often tells you where it was in the line when 158 it decided to give up. Sometimes the actual error is several tokens 159 before this, because Perl is good at understanding random input. 160 Occasionally the line number may be misleading, and once in a blue moon 161 the only way to figure out what's triggering the error is to call 162 perl -c repeatedly, chopping away half the program each time to see 163 if the error went away. Sort of the cybernetic version of S<20 164 questions>. 165 166Uncaught exception from user code: 167 syntax error at error.pl line 5, at EOF 168Missing right curly or square bracket at error.pl line 5, at end of line 169Execution of error.pl aborted due to compilation errors. 170 at error.pl line 5 171ENDofMSG 172 173my @errors_at = $parser->parse_string($msg_at); 174is( scalar(@errors_at), 2, 'msg_at results' ); 175is( $errors_at[0]->message, 'syntax error', 'msg_at 1 message' ); 176is( $errors_at[0]->file_msgpath, 'error.pl', 'msg_at 1 file' ); 177is( $errors_at[0]->line, 5, 'msg_at 1 line' ); 178is( $errors_at[1]->message, 'Missing right curly or square bracket', 'msg_at 2 message' ); 179is( $errors_at[1]->file_msgpath, 'error.pl', 'msg_at 2 file' ); 180is( $errors_at[1]->line, 5, 'msg_at 2 line' ); 181 182