1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
use strict;
use Test::Builder::Tester;
use Test::More 0.95;
use Test::File;
require "t/setup_common";
subtest subs_defined => sub {
my @subs = qw( file_line_count_between file_line_count_is file_line_count_isnt );
foreach my $sub ( @subs )
{
no strict 'refs';
ok( defined &{$sub}, "$sub is defined" );
}
};
my $file = 'min_file';
file_exists_ok( $file );
my @lines = do { local @ARGV = $file; <> };
cmp_ok( scalar @lines, ">", 1, "$file has at least one line" );
my $lines = @lines;
my $linesm = $lines - 1;
my $linesp = $lines + 1;
subtest should_work => sub {
test_out( "ok 1 - $file line count is between [$linesm] and [$linesp] lines" );
file_line_count_between( $file, $linesm, $linesp );
test_test();
test_out( "ok 1 - $file line count is between [$lines] and [$linesp] lines" );
file_line_count_between( $file, $lines, $linesp );
test_test();
test_out( "ok 1 - $file line count is between [$lines] and [$lines] lines" );
file_line_count_between( $file, $lines, $lines );
test_test();
test_out( "ok 1 - $file line count is $lines lines" );
file_line_count_is( $file, $lines );
test_test();
test_out( "ok 1 - $file line count is not $linesp lines" );
file_line_count_isnt( $file, $linesp );
test_test();
};
subtest missing_file => sub {
my $missing = 'not_there';
file_not_exists_ok( $missing );
test_out( "not ok 1 - $missing line count is between [$linesm] and [$linesp] lines" );
test_diag(
"File [$missing] does not exist!\n" .
" # Failed test '$missing line count is between [$linesm] and [$linesp] lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_between( $missing, $linesm, $linesp );
test_test();
test_out( "not ok 1 - $missing line count is between [$lines] and [$linesp] lines" );
test_diag(
"File [$missing] does not exist!\n" .
" # Failed test '$missing line count is between [$lines] and [$linesp] lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_between( $missing, $lines, $linesp );
test_test();
test_out( "not ok 1 - $missing line count is between [$lines] and [$lines] lines" );
test_diag(
"File [$missing] does not exist!\n" .
" # Failed test '$missing line count is between [$lines] and [$lines] lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_between( $missing, $lines, $lines );
test_test();
test_out( "not ok 1 - $missing line count is $lines lines" );
test_diag(
"File [$missing] does not exist!\n" .
" # Failed test '$missing line count is $lines lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_is( $missing, $lines );
test_test();
test_out( "not ok 1 - $missing line count is not $lines lines" );
test_diag(
"File [$missing] does not exist!\n" .
" # Failed test '$missing line count is not $lines lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_isnt( $missing, $lines );
test_test();
};
subtest missing_line_count => sub {
my $file = 'min_file';
file_exists_ok( $file );
test_out( "not ok 1 - $file line count is between [] and [] lines" );
test_diag(
"file_line_count_between expects positive whole numbers for the second and third arguments. Got [] and []!\n" .
" # Failed test '$file line count is between [] and [] lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_between( $file );
test_test();
test_out( "not ok 1 - $file line count is lines" );
test_diag(
"file_line_count_is expects a positive whole number for the second argument. Got []!\n" .
" # Failed test '$file line count is lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_is( $file );
test_test();
test_out( "not ok 1 - $file line count is not lines" );
test_diag(
"file_line_count_is expects a positive whole number for the second argument. Got []!\n" .
" # Failed test '$file line count is not lines'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_isnt( $file );
test_test();
};
subtest wrong_number => sub {
my $name = "$file line count is $linesp lines";
test_out( "not ok 1 - $name" );
test_diag(
"Expected [3] lines in [$file], got [$lines] lines!\n" .
" # Failed test '$name'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_is( $file, $linesp );
test_test();
test_out( "ok 1 - $file line count is not $linesp lines" );
file_line_count_isnt( $file, $linesp );
test_test();
$name = "$file line count is not $lines lines";
test_out( "not ok 1 - $name" );
test_diag(
"Expected something other than [$lines] lines in [$file], but got [$lines] lines!\n" .
" # Failed test '$name'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_isnt( $file, $lines );
test_test();
my $linespp = $linesp + 1;
$name = "$file line count is between [$linesp] and [$linespp] lines";
test_out( "not ok 1 - $name" );
test_diag(
"Expected a line count between [$linesp] and [$linespp] in [$file], but got [$lines] lines!\n" .
" # Failed test '$name'\n" .
" # at $0 line " . line_num(+5) . "."
);
file_line_count_between( $file, $linesp, $linespp );
test_test();
};
done_testing();
|