22c610cbda2563d813b9258db1dfa61ce730491e
[awesomized/libmemcached] / memcached / t / whitespace.t
1 #!/usr/bin/perl
2 use strict;
3 use FindBin qw($Bin);
4 our @files;
5
6 BEGIN {
7 chdir "$Bin/.." or die;
8
9 my @exempted = qw(Makefile.am ChangeLog doc/Makefile.am);
10 push(@exempted, glob("doc/*.xml"));
11 push(@exempted, glob("doc/xml2rfc/*.xsl"));
12 push(@exempted, glob("m4/*backport*m4"));
13 my %exempted_hash = map { $_ => 1 } @exempted;
14
15 my @stuff = split /\0/, `git ls-files -z -c -m -o --exclude-standard`;
16 @files = grep { ! $exempted_hash{$_} } @stuff;
17
18 # We won't find any files if git isn't installed. If git isn't
19 # installed, they're probably not doing any useful development, or
20 # at the very least am will clean up whitespace when we receive
21 # their patch.
22 unless (@files) {
23 use Test::More;
24 plan skip_all => "Skipping tests probably because you don't have git.";
25 exit 0;
26 }
27 }
28
29 use Test::More tests => scalar(@files);
30
31 foreach my $f (@files) {
32 open(my $fh, $f) or die;
33 my $before = do { local $/; <$fh>; };
34 close ($fh);
35 my $after = $before;
36 $after =~ s/\t/ /g;
37 $after =~ s/ +$//mg;
38 $after .= "\n" unless $after =~ /\n$/;
39 ok ($after eq $before, "$f (see devtools/clean-whitespace.pl)");
40 }