001compile.t 3.03 KB
Newer Older
1 2
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
3 4 5 6 7 8 9 10 11 12 13 14 15
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
# 
# The Original Code are the Bugzilla Tests.
# 
# The Initial Developer of the Original Code is Zach Lipton
16 17
# Portions created by Zach Lipton are Copyright (C) 2001 Zach Lipton.
# All Rights Reserved.
18 19
# 
# Contributor(s): Zach Lipton <zach@zachlipton.com>
20
#                 Max Kanat-Alexander <mkanat@bugzilla.org>
21

22 23 24 25 26

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

27
use strict;
28
use 5.008001;
29
use lib qw(. lib t);
30
use Config;
31 32
use Support::Files;
use Test::More tests => scalar(@Support::Files::testitems);
33

34 35
BEGIN { 
    use_ok('Bugzilla::Constants');
36
    use_ok('Bugzilla::Install::Requirements');
37 38
    use_ok('Bugzilla');
}
39

40 41
sub compile_file {
    my ($file) = @_;
42

43 44 45 46 47
    # 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;

48 49 50 51
    if ($file =~ s/\.pm$//) {
        $file =~ s{/}{::}g;
        use_ok($file);
        return;
52 53
    }

54 55 56
    open(my $fh, $file);
    my $bang = <$fh>;
    close $fh;
57

58 59 60 61
    my $T = "";
    if ($bang =~ m/#!\S*perl\s+-.*T/) {
        $T = "T";
    }
62

63 64 65 66
    my $libs = '';
    if ($ENV{PERL5LIB}) {
       $libs = join " ", map { "-I$_" } split /$Config{path_sep}/, $ENV{PERL5LIB};
    }
67
    my $perl = qq{"$^X"};
68
    my $output = `$perl $libs -wc$T $file 2>&1`;
69 70 71 72 73 74 75 76
    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;
77
my $file_features = map_files_to_features();
78 79 80 81

# Test the scripts by compiling them
foreach my $file (@testitems) {
    # These were already compiled, above.
82 83 84
    next if ($file eq 'Bugzilla.pm' 
             or $file eq 'Bugzilla/Constants.pm'
             or $file eq 'Bugzilla/Install/Requirements.pm');
85 86 87
    SKIP: {
        if ($file eq 'mod_perl.pl') {
            skip 'mod_perl.pl cannot be compiled from the command line', 1;
88
        }
89 90 91
        my $feature = $file_features->{$file};
        if ($feature and !Bugzilla->feature($feature)) {
            skip "$file: $feature not enabled", 1;
92
        }
93 94 95 96 97 98 99 100 101

        # 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;
102
        }
103 104

        compile_file($file);
105 106
    }
}