| 1 | package | ||||||||||||||||||||
| 2 | RandomLine; | ||||||||||||||||||||
| 3 | 1 | ▶ | use base qw/Test::Class/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use Test::More; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Test::Exception; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use File::Temp qw/tempfile/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use Set::Scalar; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Test::Warn; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use Test::ManyParams; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | ▶ | use File::Random qw/random_line/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | ▶ | use constant LINES => <<'EOF'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | Random | ||||||||||||||||||||
| 19 | Lines | ||||||||||||||||||||
| 20 | can | ||||||||||||||||||||
| 21 | contain | ||||||||||||||||||||
| 22 | randomly | ||||||||||||||||||||
| 23 | appearing things like | ||||||||||||||||||||
| 24 | PI = 3.1415926535 | ||||||||||||||||||||
| 25 | but of course that's not neccessary | ||||||||||||||||||||
| 26 | EOF | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | ▶ | use constant WRONG_PARAMS => (undef, '', '&'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 1 | ▶ | use constant SAMPLE_SIZE => 200; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | sub fill_tempfile : Test(setup) { | ||||||||||||||||||||
| 33 | 10 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
fill_tempfile: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 34 | 10 | (my $normal_fh, $self->{normal_file}) = tempfile(); | |||||||||||||||||||
| 35 | 10 | (undef, $self->{empty_file}) = tempfile(); | |||||||||||||||||||
| 36 | 10 | print $normal_fh LINES; | |||||||||||||||||||
| 37 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | sub clear_tempfile : Test(teardown) { | ||||||||||||||||||||
| 40 | 10 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
clear_tempfile: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 41 | 10 | close $self->{'normal_file'}; | |||||||||||||||||||
| 42 | 10 | close $self->{'empty_file'}; | |||||||||||||||||||
| 43 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | sub empty_file_returns_undef : Test(1) { | ||||||||||||||||||||
| 46 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
empty_file_returns_undef: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 47 | 1 | is random_line($self->{empty_file}), undef, "random_file( Empty file )"; | |||||||||||||||||||
| 48 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub lines_are_the_expected_ones : Test(1) { | ||||||||||||||||||||
| 51 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
lines_are_the_expected_ones: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 52 | 1 | my $exp = Set::Scalar->new( map {"$_\n"} split /\n/, LINES); | |||||||||||||||||||
| 53 | 1 | my $got = Set::Scalar->new(); | |||||||||||||||||||
| 54 | 1 | $got->insert( scalar random_line($self->{normal_file}) ) for (1 .. SAMPLE_SIZE); | |||||||||||||||||||
| 55 | 1 | is $got, $exp, "random_line( Normal File )"; | |||||||||||||||||||
| 56 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | sub multiple_lines_are_the_expected_ones : Test(2) { | ||||||||||||||||||||
| 59 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
multiple_lines_are_the_expected_ones: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 60 | 1 | my $exp = Set::Scalar->new( map {"$_\n"} split /\n/, LINES); | |||||||||||||||||||
| 61 | 1 | my $got = Set::Scalar->new(); | |||||||||||||||||||
| 62 | 1 | $got->insert( random_line($self->{normal_file},3) ) for (1 .. SAMPLE_SIZE()/3); | |||||||||||||||||||
| 63 | 1 | is $got, $exp, "random_line( Normal File, 3 ) [expected files]"; | |||||||||||||||||||
| 64 | 1 | $got->clear; | |||||||||||||||||||
| 65 | 1 | for (1 .. SAMPLE_SIZE()/3) { | |||||||||||||||||||
| 66 | 66 | my ($line1, $line2, $line3) = random_line($self->{normal_file}); | |||||||||||||||||||
| 67 | 66 | $got->insert($line1, $line2, $line3); | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 1 | is $got, $exp, '($line1, $line2, $line3) = random_line $fname [expected files]'; | |||||||||||||||||||
| 70 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | sub multiple_lines_are_the_expected_ones_random_line_with_sample_size : Test(1) { | ||||||||||||||||||||
| 73 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
multiple_lines_are_the_expected_ones_random_line_with_sample_size: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 74 | 1 | my $exp = Set::Scalar->new( map {"$_\n"} split /\n/, LINES); | |||||||||||||||||||
| 75 | 1 | my $got = Set::Scalar->new(random_line($self->{normal_file}, SAMPLE_SIZE())); | |||||||||||||||||||
| 76 | 1 | is $got, $exp, "random_line( Normal File, 3 ) [expected files]"; | |||||||||||||||||||
| 77 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub get_really_lines : Test(8) { | ||||||||||||||||||||
| 80 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
get_really_lines: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||
| 81 | SIZE_IS_KNOWN: { | ||||||||||||||||||||
| 82 | 1 | my ($line1, $line2, $line3) = random_line($self->{normal_file},3); | |||||||||||||||||||
| 83 | 1 | ok defined($line1), "1st returned line of random_line should be defined"; | |||||||||||||||||||
| 84 | 1 | ok defined($line2), "2nd returned line of random_line should be defined"; | |||||||||||||||||||
| 85 | 1 | ok defined($line3), "3rd returned line of random_line should be defined"; | |||||||||||||||||||
| 86 | 1 | ▶ | ok( ($line1 ne $line2 or $line1 ne $line3), | ||||||||||||||||||
|
Condition33%1/3
$line1 ne $line2 || $line1 ne $line3
MC/DC0%0/2
$line1 ne $line2 || $line1 ne $line3
$line1 ne $line2
$line1 ne $line3
Truth table33%1/3
A || B
A= $line1 ne $line2B= $line1 ne $line3
| |||||||||||||||||||||
| 87 | "3 random lines should be a bit different" ); | ||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | SIZE_IS_UNKNOWN: { | ||||||||||||||||||||
| 91 | 1 | my ($line1, $line2, $line3) = random_line($self->{normal_file}); | |||||||||||||||||||
| 92 | 1 | ok defined($line1), "1st returned line of random_line should be defined"; | |||||||||||||||||||
| 93 | 1 | ok defined($line2), "2nd returned line of random_line should be defined"; | |||||||||||||||||||
| 94 | 1 | ok defined($line3), "3rd returned line of random_line should be defined"; | |||||||||||||||||||
| 95 | 1 | ▶ | ok( ($line1 ne $line2 or $line1 ne $line3), | ||||||||||||||||||
|
Condition33%1/3
$line1 ne $line2 || $line1 ne $line3
MC/DC0%0/2
$line1 ne $line2 || $line1 ne $line3
$line1 ne $line2
$line1 ne $line3
Truth table33%1/3
A || B
A= $line1 ne $line2B= $line1 ne $line3
| |||||||||||||||||||||
| 96 | "3 random lines should be a bit different" ); | ||||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | sub warns_if_called_with_line_nr_in_scalar_context : Test(1) { | ||||||||||||||||||||
| 101 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
warns_if_called_with_line_nr_in_scalar_context: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 102 | 1 | ▶ | warning_like {scalar random_line($self->{normal_file},3)} | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 103 | 1 | {carped => qr/called in scalar context/}, | |||||||||||||||||||
| 104 | "should give a warning random_line(fname,3) is called in scalar context"; | ||||||||||||||||||||
| 105 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub warns_if_zero_random_lines : Test(1) { | ||||||||||||||||||||
| 108 | 1 | ▶ | my $self = shift(); | ||||||||||||||||||
|
Subroutine
warns_if_zero_random_lines: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 109 | 1 | ▶ | warning_like { (random_line($self->{normal_file},0)) } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 110 | 1 | {carped => qr/0 random lines/}, | |||||||||||||||||||
| 111 | "should give a warning random_line(fname,0)"; | ||||||||||||||||||||
| 112 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | sub warns_not_if_called_in_list_context_without_line_nr_specification : Test(1) { | ||||||||||||||||||||
| 115 | 1 | ▶ | my $self = shift(); | ||||||||||||||||||
|
Subroutine
warns_not_if_called_in_list_context_without_line_nr_specification: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 116 | 1 | ▶ | warnings_are { [ random_line($self->{normal_file}) ] } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 117 | 1 | [], | |||||||||||||||||||
| 118 | "should give a warning if random_line(fname) in list context"; | ||||||||||||||||||||
| 119 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | sub nr_of_lines_greater_than_lines_in_file : Test(2) { | ||||||||||||||||||||
| 122 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
nr_of_lines_greater_than_lines_in_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 123 | 1 | my @line = random_line($self->{normal_file},100); | |||||||||||||||||||
| 124 | 1 | ok @line == 100, "random_line(file, 100) should return a list of 100 elements"; | |||||||||||||||||||
| 125 | 1 | ▶ | all_ok {defined($_[0])} \@line, "random_line(file, 100) - all lines should be defined"; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 126 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | sub wrong_parameters : Test(5) { | ||||||||||||||||||||
| 129 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
wrong_parameters: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 130 | 1 | ▶ | no warnings; # $_ shall be undefined for a moment ! | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 131 | 1 | foreach (WRONG_PARAMS) { | |||||||||||||||||||
| 132 | 3 | ▶ | dies_ok(sub {random_line($_)}, "random_line( '$_' ) should die"); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 133 | 3 | ▶ | next unless defined; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | 2 | ▶ | dies_ok(sub {(random_line($self->{normal_file},$_))}, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 135 | 2 | "random_line(fname, '$_' ) should die"); | |||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | 1 | ▶ | use warnings; # warnings back | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 138 | 1 | ▶ | } | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 1 | 1; | |||||||||||||||||||