fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / 99-policy.t
1 use strict;
2 use warnings;
3
4 use RT::Test nodb => 1;
5 use File::Find;
6
7 my @files;
8 find( sub { push @files, $File::Find::name if -f },
9       qw{etc lib share t bin sbin devel/tools} );
10 if ( my $dir = `git rev-parse --git-dir 2>/dev/null` ) {
11     # We're in a git repo, use the ignore list
12     chomp $dir;
13     my %ignores;
14     $ignores{ $_ }++ for grep $_, split /\n/,
15         `git ls-files -o -i --exclude-standard .`;
16     @files = grep {not $ignores{$_}} @files;
17 }
18
19 sub check {
20     my $file = shift;
21     my %check = (
22         strict   => 0,
23         warnings => 0,
24         no_tabs  => 0,
25         shebang  => 0,
26         exec     => 0,
27         bps_tag  => 0,
28         @_,
29     );
30
31     if ($check{strict} or $check{warnings} or $check{shebang} or $check{bps_tag} or $check{no_tabs}) {
32         local $/;
33         open my $fh, '<', $file or die $!;
34         my $content = <$fh>;
35
36         like(
37             $content,
38             qr/^use strict(?:;|\s+)/m,
39             "$file has 'use strict'"
40         ) if $check{strict};
41
42         like(
43             $content,
44             qr/^use warnings(?:;|\s+)/m,
45             "$file has 'use warnings'"
46         ) if $check{warnings};
47
48         if ($check{shebang} == 1) {
49             like( $content, qr/^#!/, "$file has shebang" );
50         } elsif ($check{shebang} == -1) {
51             unlike( $content, qr/^#!/, "$file has no shebang" );
52         }
53
54         $check{bps_tag} = -1 if $check{bps_tag} == 1
55             and not $content =~ /Copyright\s+\(c\)\s+\d\d\d\d-\d\d\d\d Best Practical Solutions/i
56                 and $file =~ /(?:ckeditor|scriptaculous|superfish|tablesorter|farbtastic)/i;
57         $check{bps_tag} = -1 if $check{bps_tag} == 1
58             and not $content =~ /Copyright\s+\(c\)\s+\d\d\d\d-\d\d\d\d Best Practical Solutions/i
59                 and ($content =~ /\b(copyright|GPL|Public Domain)\b/i
60                   or /\(c\)\s+\d\d\d\d(?:-\d\d\d\d)?/i);
61         if ($check{bps_tag} == 1) {
62             like( $content, qr/[B]EGIN BPS TAGGED BLOCK {{{/, "$file has BPS license tag");
63         } elsif ($check{bps_tag} == -1) {
64             unlike( $content, qr/[B]EGIN BPS TAGGED BLOCK {{{/, "$file has no BPS license tag");
65         }
66     }
67
68     my $executable = ( stat $file )[2] & 0100;
69     if ($check{exec} == 1) {
70         if ( $file =~ /\.in$/ ) {
71             ok( !$executable, "$file permission is u-x (.in will add +x)" );
72         } else {
73             ok( $executable, "$file permission is u+x" );
74         }
75     } elsif ($check{exec} == -1) {
76         ok( !$executable, "$file permission is u-x" );
77     }
78 }
79
80 check( $_, shebang => -1, exec => -1, warnings => 1, strict => 1, bps_tag => 1 )
81     for grep {m{^lib/.*\.pm$}} @files;
82
83 check( $_, shebang => -1, exec => -1, warnings => 1, strict => 1, bps_tag => -1 )
84     for grep {m{^t/.*\.t$}} @files;
85
86 check( $_, shebang => 1, exec => 1, warnings => 1, strict => 1, bps_tag => 1 )
87     for grep {m{^s?bin/}} @files;
88
89 check( $_, shebang => 1, exec => 1, warnings => 1, strict => 1, bps_tag => 1 )
90     for grep {m{^devel/tools/} and not m{/(localhost\.(crt|key)|mime\.types)$}} @files;
91
92 check( $_, exec => -1, bps_tag => not m{\.(png|gif|jpe?g)$} )
93     for grep {m{^share/html/}} @files;
94
95 check( $_, exec => -1 )
96     for grep {m{^share/(po|fonts)/}} @files;
97
98 check( $_, exec => -1 )
99     for grep {m{^t/data/}} @files;
100
101 check( $_, exec => -1, bps_tag => -1 )
102     for grep {m{^etc/[^/]+$}} @files;
103
104 check( $_, exec => -1, bps_tag => -1 )
105     for grep {m{^etc/upgrade/[^/]+/}} @files;
106
107 check( $_, warnings => 1, strict => 1, compile_perl => 1, no_tabs => 1 )
108     for grep {m{^etc/upgrade/.*/content$}} @files;
109
110 check( $_, shebang => 1, exec => 1, warnings => 1, strict => 1, bps_tag => 1, no_tabs => 1 )
111     for grep {m{^etc/upgrade/[^/]+$}} @files;
112
113 check( $_, compile_perl => 1, exec => 1 )
114     for grep{ -f $_} map {s/\.in$//; $_} grep {m{^etc/upgrade/[^/]+$}} @files;
115
116 check( $_, exec => -1 )
117     for grep {m{^(devel/)?docs/}} @files;
118
119 done_testing;