Created
September 21, 2014 01:10
-
-
Save barefootcoder/76f3a390d5ee2ef344e8 to your computer and use it in GitHub Desktop.
t/more_line_numbers.t - more rigorous testing for Devel::Declare throwing off your line numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Test::More; | |
#use Test::Exception; | |
use Method::Signatures; | |
my %examples; | |
$examples{81361} = # example from RT/81361; thx MAUKE | |
q{ #!perl # line 1 | |
use Method::Signatures; # line 2 | |
# line 3 | |
func foo1( # line 4 | |
$x, # first # line 5 | |
$y # second # line 6 | |
) { # line 7 | |
} # this is line 8 # line 8 | |
# line 9 | |
my $aref = []; # line 10 | |
__LINE__ # line 11 | |
}; | |
$examples{81363} = # example from RT/81363; thx MAUKE | |
q{ #!perl # line 1 | |
use warnings; # line 2 | |
use strict; # line 3 | |
# line 4 | |
use Method::Signatures; # line 5 | |
# line 6 | |
{ # line 7 | |
my $uniq = 0; # line 8 | |
# line 9 | |
method fresh_name() { # line 10 | |
$self->prefix . $uniq++ # line 11 | |
} # line 12 | |
} # this is line 13 # line 13 | |
# line 14 | |
method prefix() { # line 15 | |
$self->{prefix} # line 16 | |
} # line 17 | |
# line 18 | |
my $aref = []; # line 19 | |
__LINE__ # line 20 | |
}; | |
$examples{87544} = # example from RT/87544; thx Brad from bereft.net | |
q{ #!/usr/bin/perl # line 1 | |
# line 2 | |
use strict; # line 3 | |
use warnings; # line 4 | |
# line 5 | |
use Method::Signatures; # line 6 | |
# line 7 | |
my $m # line 8 | |
= # line 9 | |
method la () { # line 10 | |
die; # line 11 | |
}; # line 12 | |
# line 13 | |
__LINE__ # line 14 | |
}; | |
$examples{BF01} = # example from barefootcoder; make sure newline before ( works | |
q{ #!/usr/bin/perl # line 1 | |
# line 2 | |
use strict; # line 3 | |
use warnings; # line 4 | |
# line 5 | |
use Method::Signatures; # line 6 | |
# line 7 | |
func foo2 # line 8 | |
($x) { # line 9 | |
print $x; # line 10 | |
} # line 11 | |
# line 12 | |
my $x = "hey!"; # line 13 | |
# line 14 | |
__LINE__ # line 15 | |
}; | |
$examples{BF02} = # example from barefootcoder; how about before the name, even? | |
q{ #!/usr/bin/perl # line 1 | |
# line 2 | |
use strict; # line 3 | |
use warnings; # line 4 | |
# line 5 | |
use Method::Signatures; # line 6 | |
# line 7 | |
func # line 8 | |
foo3 # line 9 | |
($x) { # line 10 | |
print $x; # line 11 | |
} # line 12 | |
# line 13 | |
my $x = "hey!"; # line 14 | |
# line 15 | |
__LINE__ # line 16 | |
}; | |
$examples{BF03} = # example from barefootcoder; between closing parend and open brace | |
q{ #!/usr/bin/perl # line 1 | |
# line 2 | |
use strict; # line 3 | |
use warnings; # line 4 | |
# line 5 | |
use Method::Signatures; # line 6 | |
# line 7 | |
func foo4 ($x) # line 8 | |
{ # line 9 | |
print $x; # line 10 | |
} # line 11 | |
# line 12 | |
my $x = "hey!"; # line 13 | |
# line 14 | |
__LINE__ # line 15 | |
}; | |
$examples{BF04} = # example from barefootcoder; maximum newlineage! | |
q{ #!/usr/bin/perl # line 1 | |
# line 2 | |
use strict; # line 3 | |
use warnings; # line 4 | |
# line 5 | |
use Method::Signatures; # line 6 | |
# line 7 | |
func # line 8 | |
foo5 # line 9 | |
( # line 10 | |
$x # line 11 | |
) # line 12 | |
{ # line 13 | |
print $x; # line 14 | |
} # line 15 | |
# line 16 | |
my $x = "hey!"; # line 17 | |
# line 18 | |
__LINE__ # line 19 | |
}; | |
foreach (sort keys %examples) | |
{ | |
my $code = $examples{$_}; | |
# since `__LINE__` is always on the last line of the snippet, the proper | |
# line number is equivalent to how many newlines there are in the code | |
# so let's count them | |
my $lines = $code =~ s/\n/\n/g; | |
is eval $code, $lines, "line number bug is fixed for RT/$_"; | |
} | |
done_testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment