File: 03_devel_whitespace.t

package info (click to toggle)
libdatetime-format-rfc3339-perl 1.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144 kB
  • sloc: perl: 508; makefile: 2
file content (50 lines) | stat: -rwxr-xr-x 1,036 bytes parent folder | download
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
#!perl

# Expected to be run from ../ (make test) or ../blib/ (make disttest)

use strict;
use warnings;

use Test::More;

BEGIN {
   $ENV{ DEVEL_TESTS }
      or plan skip_all => "Whitespace checks are only performed when DEVEL_TESTS=1";
}

sub slurp_file {
   my $qfn = shift;
   open( my $fh, '<', $qfn )
      or die( "Can't open \"$qfn\": $!\n" );

   local $/;
   return <$fh>;
}

sub read_manifest {
   open( my $fh, '<', 'MANIFEST' )
      or die( "Can't open \"MANIFEST\": $!\n" );

   my @manifest = <$fh>;
   s/\s.*//s for @manifest;
   return @manifest;
}

{
   my @qfns = read_manifest();

   plan tests => 2*@qfns;

   for my $qfn ( @qfns ) {
      my $file = slurp_file( $qfn );
      my $rev_file = reverse( $file );

      if ( $^O eq 'MSWin32' ) {
         ok( $file !~ /\r(?!\n)/ && $rev_file !~ /\n(?!\r)/, "$qfn - Windows line endings" );
      } else {
         ok( $file !~ /\r/, "$qfn - Unix line endings" );
      }

      ok( $rev_file !~ /\n(?:\r[^\S\n]|[^\S\r\n])/, "$qfn - No trailing whitespace" );
   }
}