1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use Test::More tests => 4; 7use Parse::ErrorString::Perl; 8use Test::Differences; 9 10 11# use strict; 12# use warnings; 13# 14# $kaboom; 15 16my $msg_compile; 17 18if ( $] < 5.021004 ) { 19 $msg_compile = <<'ENDofMSG'; 20Global symbol "$kaboom" requires explicit package name at error.pl line 8. 21Execution of error.pl aborted due to compilation errors. 22ENDofMSG 23} else { 24 $msg_compile = <<'ENDofMSG'; 25Global symbol "$kaboom" requires explicit package name (did you forget to declare "my $kaboom"?) at error.pl line 8. 26Execution of error.pl aborted due to compilation errors. 27ENDofMSG 28} 29 30my $message; 31 32if ( $] < 5.021004 ) { 33 $message = q{Global symbol "$kaboom" requires explicit package name}; 34} else { 35 $message = q{Global symbol "$kaboom" requires explicit package name (did you forget to declare "my $kaboom"?)}; 36} 37 38my $diagnostics; 39 40if ( $] < 5.008009 ) { 41 42 $diagnostics = <<'ENDofMSG'; 43(F) You've said "use strict vars", which indicates that all variables 44must either be lexically scoped (using "my"), declared beforehand using 45"our", or explicitly qualified to say which package the global variable 46is in (using "::"). 47ENDofMSG 48 49} elsif ( $] < 5.010000 ) { 50 51 $diagnostics = <<'ENDofMSG'; 52(F) You've said "use strict" or "use strict vars", which indicates 53that all variables must either be lexically scoped (using "my"), 54declared beforehand using "our", or explicitly qualified to say 55which package the global variable is in (using "::"). 56ENDofMSG 57 58} else { 59 60 $diagnostics = <<'ENDofMSG'; 61(F) You've said "use strict" or "use strict vars", which indicates 62that all variables must either be lexically scoped (using "my" or "state"), 63declared beforehand using "our", or explicitly qualified to say 64which package the global variable is in (using "::"). 65ENDofMSG 66 67} 68 69 70chomp($diagnostics); 71 72$diagnostics =~ s/\s\n/\n/gs; 73 74my $parser = Parse::ErrorString::Perl->new; 75my @errors_compile = $parser->parse_string($msg_compile); 76is( $errors_compile[0]->message, $message, 'message' ); 77 78#ok($errors_compile[0]->diagnostics eq $diagnostics, 'diagnostics'); 79my $obtained_diagnostics = $errors_compile[0]->diagnostics; 80$obtained_diagnostics =~ s/\s\n/\n/gs; 81eq_or_diff( $obtained_diagnostics, $diagnostics, 'diagnostics' ); 82is( $errors_compile[0]->type, 'F', 'type' ); 83is( $errors_compile[0]->type_description, 'fatal error', 'error type' ); 84 85