File: 096_characters.t

package info (click to toggle)
libtest-pod-content-perl 0.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 116 kB
  • ctags: 8
  • sloc: perl: 166; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
use strict;
use warnings;

use Test::More;
use English qw(-no_match_vars);
use File::Find;
use IO::File;


if ( not $ENV{RELEASE_TESTING} ) {
    my $msg = 'Author test.  Set $ENV{RELEASE_TESTING} to a true value to run.';
    plan( skip_all => $msg );
}
my $dir = 'blib/lib';
if (-d '../t') {
    $dir = '../lib';
}

my @filelist = ();
find( \&filelist, $dir);

sub filelist {
    my $name = $_;
    return if -d $name;
    return if $File::Find::name =~ m{\.(?:c|o|svn)$}x;

    push @filelist, $File::Find::name;
}

plan tests => scalar @filelist;

for my $file (sort @filelist) {

    check_file($file);
}

sub check_file {
    my $file = shift;
    my $fh = IO::File->new($file, O_RDONLY) or die "Cannot open $file";
    my $line_nr = 0;
    my $error_count = 0;

    while (my $line = $fh->getline() ) {
        # check for trailing whitespace
        # allow single whitespace on line to allow
        # pod source blocks with empty lines
        #
        $line_nr++;
        if ($line =~m{ (:?[^\s]+|\s)\s\r?\n$ }x) {
            $error_count++;
            print "# trailing whitespace in $file line $line_nr at end of line\n"
        }

        # check for tabs and report their position
        my @tab_pos_from = ();
        my $pos = -1;
        while (1) {
            $pos = index($line, "\t", $pos + 1);
            last if $pos <0;
            push @tab_pos_from, $pos + 1;
        }
        if (@tab_pos_from) {
            print "# tab found in $file line $line_nr cols ${ \join(', ', @tab_pos_from) }\n";
            $error_count += scalar(@tab_pos_from);
        }

        if ($line=~m{\r}) {
            print "# CR (\\r) found in $file line $line_nr. Convert to LF only.\n";
            $error_count++;
        }
    }
    is $error_count, 0 , "$file characters";
}