53103a27d25e5d4a510fba72b45ef940c3326297
[kivitendo-erp.git] / t / Support / Files.pm
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 # The Initial Developer of the Original Code is Zach Lipton
16 # Portions created by Zach Lipton are
17 # Copyright (C) 2001 Zach Lipton.  All
18 # Rights Reserved.
19 #
20 # Contributor(s): Zach Lipton <zach@zachlipton.com>
21 #                 Joel Peshkin <bugreport@peshkin.net>
22
23 package Support::Files;
24
25 use strict;
26
27 use File::Find;
28
29 our @testitems;
30
31 # exclude_deps is a hash of arrays listing the files to be excluded
32 # if a module is not available
33 #
34 our @additional_files = ();
35 our %exclude_deps = (
36     'XML::Twig' => ['importxml.pl'],
37     'Net::LDAP' => ['Bugzilla/Auth/Verify/LDAP.pm'],
38     'Email::Reply' => ['email_in.pl'],
39     'Email::MIME::Attachment::Stripper' => ['email_in.pl']
40 );
41
42
43 our @files = glob('*');
44 find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$/;}, 'SL');
45 find(sub { push(@files, $File::Find::name) if $_ =~ /\.pl$/;}, qw(bin/mozilla sql/Pg-upgrade2));
46 find(sub { push(@files, $File::Find::name) if $_ =~ /\.html$/;}, qw(templates/webpages));
47
48 sub have_pkg {
49     my ($pkg) = @_;
50     my ($msg, $vnum, $vstr);
51     no strict 'refs';
52     eval { my $p; ($p = $pkg . ".pm") =~ s!::!/!g; require $p; };
53     return !($@);
54 }
55
56 our @exclude_files    = ();
57 foreach my $dep (keys(%exclude_deps)) {
58     if (!have_pkg($dep)) {
59         push @exclude_files, @{$exclude_deps{$dep}};
60     }
61 }
62
63 sub isTestingFile {
64     my ($file) = @_;
65     my $exclude;
66     foreach $exclude (@exclude_files) {
67         if ($file eq $exclude) { return undef; } # get rid of excluded files.
68     }
69
70     if ($file =~ /\.cgi$|\.pl$|\.pm$/) {
71         return 1;
72     }
73     my $additional;
74     foreach $additional (@additional_files) {
75         if ($file eq $additional) { return 1; }
76     }
77     return undef;
78 }
79
80 foreach my $currentfile (@files) {
81     if (isTestingFile($currentfile)) {
82         push(@testitems,$currentfile);
83     }
84 }
85
86
87 1;