File: 02file_ok.t

package info (click to toggle)
libtest-files-perl 0.14-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 184 kB
  • sloc: perl: 351; makefile: 2
file content (83 lines) | stat: -rw-r--r-- 2,648 bytes parent folder | download | duplicates (3)
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
use strict;

use Test::Builder::Tester tests => 5;
use File::Spec;

use Test::Files;

my $test_file    = File::Spec->catfile( 't', '02file_ok.t' );
my $missing_file = File::Spec->catfile( 't', 'missing' );
my $ok_pass_file = File::Spec->catfile( 't', 'ok_pass.dat' );

#-----------------------------------------------------------------
# Compare text to a file with same text.
#-----------------------------------------------------------------

test_out("ok 1 - passing text");
file_ok($ok_pass_file, <<"EOF", "passing text");
This file
is for 03ok_pass.t
EOF
test_test("passing text");

#-----------------------------------------------------------------
# Compare text to a missing file.
#-----------------------------------------------------------------

test_out("not ok 1 - absent file");
my $line = line_num(+3);
test_diag("    Failed test ($test_file at line $line)",
          "$missing_file absent");
file_ok("$missing_file", "This file is really absent", "absent file");
test_test("absent file");

#-----------------------------------------------------------------
# Compare text to a file with different text.
#-----------------------------------------------------------------

test_out("not ok 1 - failing text");
$line = line_num(+9);
test_diag("    Failed test ($test_file at line $line)",
'+---+----------------------+-----------+',
'|   |Got                   |Expected   |',
'| Ln|                      |           |',
'+---+----------------------+-----------+',
'|  1|This file             |This file  |',
'*  2|is for 03ok_pass.t\n  |is wrong   *',
'+---+----------------------+-----------+'  );
file_ok($ok_pass_file, "This file\nis wrong", "failing text");
test_test("failing text");

#-----------------------------------------------------------------
# file_filter_ok with missing file
#-----------------------------------------------------------------

test_out("not ok 1 - absent filtered file");
$line = line_num(+3);
test_diag("    Failed test ($test_file at line $line)",
          "$missing_file absent");
file_filter_ok(
        "$missing_file",
        "This file is really absent",
        \&stip_num,
        "absent filtered file",
);
test_test("absent filtered file");

#-----------------------------------------------------------------
# Compare file to string with filter.
#-----------------------------------------------------------------

test_out("ok 1 - passing filtered text");
file_filter_ok($ok_pass_file, <<"EOF", \&strip_num, "passing filtered text");
This file
is for ok_pass.t
EOF
test_test("passing filtered text");

sub strip_num {
    my $line = shift;
    $line    =~ s/\d+//;

    return $line;
}