test/lib/RandomLine.pm

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