977c8aa67d463a909a2fcc3fb9641277bf0cef10
[vuplus_webkit] / Websites / bugs.webkit.org / t / 010dependencies.t
1 # -*- Mode: perl; indent-tabs-mode: nil -*-
2 #
3 # The contents of this file are subject to the Mozilla Public
4 # License Version 1.1 (the "License"); you may not use this file
5 # except in compliance with the License. You may obtain a copy of
6 # the License at http://www.mozilla.org/MPL/
7 #
8 # Software distributed under the License is distributed on an "AS
9 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 # implied. See the License for the specific language governing
11 # rights and limitations under the License.
12 #
13 # The Original Code are the Bugzilla Tests.
14 #
15 # Contributor(s): David Miller <justdave@bugzilla.org>
16 #                 Frédéric Buclin <LpSolit@gmail.com>
17
18
19 ##################
20 #Bugzilla Test 10#
21 ## dependencies ##
22
23 use strict;
24
25 use lib 't';
26
27 use Support::Files;
28 use Test::More qw(no_plan);
29
30 my %mods;
31 my %deps;
32
33 # Extract all Perl modules.
34 foreach my $file (@Support::Files::testitems) {
35   if ($file =~ /^(.*)\.pm$/) {
36     my $module = $1;
37     $module =~ s#/#::#g;
38     $mods{$module} = $file;
39   }
40 }
41
42 foreach my $module (keys %mods) {
43     my $reading = 1;
44     my @use;
45
46     open(SOURCE, $mods{$module});
47     while (my $line = <SOURCE>) {
48       last if ($line =~ /^__END__/);
49       if ($line =~ /^=cut/) {
50         $reading = 1;
51         next;
52       }
53       next unless $reading;
54       if ($line =~ /^=(head|over|item|back|pod|begin|end|for)/) {
55         $reading = 0;
56         next;
57       }
58       if ($line =~ /^package\s+([^;]);/) {
59         $module = $1;
60       }
61       elsif ($line =~ /^\s*(?:use|^require) *"?(Bugzilla.*?)"?(?:;|\s+qw[\(\{]|\s+\(\))/) {
62         my $used = $1;
63         $used =~ s#/#::#g;
64         $used =~ s#\.pm$##;
65         $used =~ s#\$module#[^:]+#;
66         $used =~ s#\${[^}]+}#[^:]+#;
67         $used =~ s#[" ]##g;
68         my $exclude = "";
69         if    ($used eq 'Bugzilla::Auth::Login::[^:]+' ) { $exclude = 'Bugzilla::Auth::Login::Stack'  }
70         elsif ($used eq 'Bugzilla::Auth::Verify::[^:]+') { $exclude = 'Bugzilla::Auth::Verify::Stack' }
71         elsif ($used eq 'Bugzilla::Config::[^:]+'      ) { $exclude = 'Bugzilla::Config::Common'      }
72         push(@use, grep(/^$used$/, grep(!/^$exclude$/, keys %mods)));
73       }
74     }
75     close (SOURCE);
76
77     foreach my $u (@use) {
78       if (!grep {$_ eq $u} @{$deps{$module}}) {
79         push(@{$deps{$module}}, $u);
80       }
81     }
82 }
83
84 sub creates_loop {
85   my ($module, $used_module) = @_;
86   my @list = ($used_module);
87   my %seen;
88   while (my $next = shift @list) {
89     if ($module eq $next) {
90       ok(0, "Dependency on $used_module from $module causes loop. --ERROR");
91       return;
92     }
93     if (!$seen{$next}) {
94       push(@list, @{$deps{$next}}) if defined $deps{$next};
95     }
96     $seen{$next} = 1;
97   }
98   ok(1, "No dependency loop between $module and $used_module");
99 }
100
101
102 foreach my $module (keys %deps) {
103   foreach my $used_module (@{$deps{$module}}) {
104     creates_loop($module, $used_module);
105   }
106 }
107
108 exit 0;