001compile.t 2.53 KB
Newer Older
1 2 3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
#
5 6
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
7

8 9 10 11 12

#################
#Bugzilla Test 1#
###Compilation###

13
use strict;
14
use 5.008001;
15
use lib qw(. lib t);
16
use Config;
17 18
use Support::Files;
use Test::More tests => scalar(@Support::Files::testitems);
19

20 21
BEGIN { 
    use_ok('Bugzilla::Constants');
22
    use_ok('Bugzilla::Install::Requirements');
23 24
    use_ok('Bugzilla');
}
25

26 27
sub compile_file {
    my ($file) = @_;
28

29 30 31 32 33
    # Don't allow CPAN.pm to modify the global @INC, which the version
    # shipped with Perl 5.8.8 does. (It gets loaded by 
    # Bugzilla::Install::CPAN.)
    local @INC = @INC;

34 35 36 37
    if ($file =~ s/\.pm$//) {
        $file =~ s{/}{::}g;
        use_ok($file);
        return;
38 39
    }

40 41 42
    open(my $fh, $file);
    my $bang = <$fh>;
    close $fh;
43

44 45 46 47
    my $T = "";
    if ($bang =~ m/#!\S*perl\s+-.*T/) {
        $T = "T";
    }
48

49 50
    my $libs = '';
    if ($ENV{PERL5LIB}) {
51
       $libs = join " ", map { "-I\"$_\"" } split /$Config{path_sep}/, $ENV{PERL5LIB};
52
    }
53
    my $perl = qq{"$^X"};
54
    my $output = `$perl $libs -wc$T $file 2>&1`;
55 56 57 58 59 60 61 62
    chomp($output);
    my $return_val = $?;
    $output =~ s/^\Q$file\E syntax OK$//ms;
    diag($output) if $output;
    ok(!$return_val, $file) or diag('--ERROR');
}

my @testitems = @Support::Files::testitems;
63
my $file_features = map_files_to_features();
64 65 66 67

# Test the scripts by compiling them
foreach my $file (@testitems) {
    # These were already compiled, above.
68 69 70
    next if ($file eq 'Bugzilla.pm' 
             or $file eq 'Bugzilla/Constants.pm'
             or $file eq 'Bugzilla/Install/Requirements.pm');
71 72 73
    SKIP: {
        if ($file eq 'mod_perl.pl') {
            skip 'mod_perl.pl cannot be compiled from the command line', 1;
74
        }
75 76 77
        my $feature = $file_features->{$file};
        if ($feature and !Bugzilla->feature($feature)) {
            skip "$file: $feature not enabled", 1;
78
        }
79 80 81 82 83 84 85 86 87

        # Check that we have a DBI module to support the DB, if this 
        # is a database module (but not Schema)
        if ($file =~ m{Bugzilla/DB/([^/]+)\.pm$}
            and $file ne "Bugzilla/DB/Schema.pm") 
        {
            my $module = lc($1);
            my $dbd = DB_MODULE->{$module}->{dbd}->{module};
            eval("use $dbd; 1") or skip "$file: $dbd not installed", 1;
88
        }
89 90

        compile_file($file);
91 92
    }
}