]> granicus.if.org Git - fortune-mod/blob - fortune-mod/tests/t/trailing-space-and-CRs.t
Fix tidyall tests.
[fortune-mod] / fortune-mod / tests / t / trailing-space-and-CRs.t
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use File::Find::Object ();
7 use Path::Tiny         qw/ path /;
8 use Test::More tests => 3;
9 use Test::Differences (qw( eq_or_diff ));
10
11 my $tree = File::Find::Object->new( {}, $ENV{SRC_DIR} );
12
13 my %do_not_check = (
14     map { $_ => 1 }
15         qw(
16         fortune/fortune
17         util/rot
18         util/strfile
19         util/unstr
20         )
21 );
22
23 my @cr_results;
24 my @trailing_whitespace_results;
25 my @tabs_results;
26 while ( my $r = $tree->next_obj() )
27 {
28     if ( $r->is_file )
29     {
30         my $fn = $r->path;
31         if (
32             not(   $r->basename =~ /\A\..*?\.swp\z/
33                 or $r->basename =~ /\.(o|dat|valgrind-log)\z/
34                 or
35                 exists( $do_not_check{ join '/', @{ $r->full_components } } ) )
36             )
37         {
38             my $contents = path($fn)->slurp_raw;
39
40             if ( $contents =~ /\r/ )
41             {
42                 push @cr_results, $fn;
43             }
44             elsif ( $contents =~ /[ \t]$/ms )
45             {
46                 push @trailing_whitespace_results, $fn;
47             }
48             elsif ( $r->basename =~ /\.[ch]\z/ and $contents =~ /\t/ )
49             {
50                 push @tabs_results, $fn;
51             }
52         }
53     }
54     else
55     {
56         if ( ( $r->dir_components->[-1] // '' ) eq '.git' )
57         {
58             $tree->prune;
59         }
60     }
61 }
62
63 # TEST
64 eq_or_diff( \@cr_results, [], "Files containing carriage returns." );
65
66 # TEST
67 eq_or_diff( \@trailing_whitespace_results,
68     [], "Files containing trailing whitespace." );
69
70 # TEST
71 eq_or_diff( \@tabs_results, [], "Source files containing tabs." );
72
73 __END__
74
75 =head1 COPYRIGHT & LICENSE
76
77 Copyright 2016 by Shlomi Fish
78
79 This program is distributed under the MIT (X11) License:
80 L<http://www.opensource.org/licenses/mit-license.php>
81
82 Permission is hereby granted, free of charge, to any person
83 obtaining a copy of this software and associated documentation
84 files (the "Software"), to deal in the Software without
85 restriction, including without limitation the rights to use,
86 copy, modify, merge, publish, distribute, sublicense, and/or sell
87 copies of the Software, and to permit persons to whom the
88 Software is furnished to do so, subject to the following
89 conditions:
90
91 The above copyright notice and this permission notice shall be
92 included in all copies or substantial portions of the Software.
93
94 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
95 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
96 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
97 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
98 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
99 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
100 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
101 OTHER DEALINGS IN THE SOFTWARE.
102
103 =cut