Commit 4b2c9f0f authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 527505: Make 001compile.t use Bugzilla->feature to determine which modules to compile

Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=mkanat
parent 2f804027
...@@ -43,7 +43,6 @@ use Bugzilla::CGI; ...@@ -43,7 +43,6 @@ use Bugzilla::CGI;
use Bugzilla::DB; use Bugzilla::DB;
use Bugzilla::Install::Localconfig qw(read_localconfig); use Bugzilla::Install::Localconfig qw(read_localconfig);
use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES); use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES);
use Bugzilla::JobQueue;
use Bugzilla::Template; use Bugzilla::Template;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Error; use Bugzilla::Error;
...@@ -379,6 +378,7 @@ sub logout_request { ...@@ -379,6 +378,7 @@ sub logout_request {
sub job_queue { sub job_queue {
my $class = shift; my $class = shift;
require Bugzilla::JobQueue;
$class->request_cache->{job_queue} ||= Bugzilla::JobQueue->new(); $class->request_cache->{job_queue} ||= Bugzilla::JobQueue->new();
return $class->request_cache->{job_queue}; return $class->request_cache->{job_queue};
} }
......
...@@ -271,8 +271,7 @@ EOT ...@@ -271,8 +271,7 @@ EOT
} }
# List of abstract methods we are checking the derived class implements # List of abstract methods we are checking the derived class implements
our @_abstract_methods = qw(REQUIRED_VERSION PROGRAM_NAME DBD_VERSION our @_abstract_methods = qw(new sql_regexp sql_not_regexp sql_limit sql_to_days
new sql_regexp sql_not_regexp sql_limit sql_to_days
sql_date_format sql_interval bz_explain sql_date_format sql_interval bz_explain
sql_group_concat); sql_group_concat);
...@@ -287,7 +286,7 @@ sub import { ...@@ -287,7 +286,7 @@ sub import {
# make sure all abstract methods are implemented # make sure all abstract methods are implemented
foreach my $meth (@_abstract_methods) { foreach my $meth (@_abstract_methods) {
$pkg->can($meth) $pkg->can($meth)
or croak("Class $pkg does not define method $meth"); or die("Class $pkg does not define method $meth");
} }
} }
......
...@@ -27,7 +27,7 @@ use strict; ...@@ -27,7 +27,7 @@ use strict;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Install::Util qw(install_string); use Bugzilla::Install::Util qw(install_string);
BEGIN { eval "use base qw(TheSchwartz)"; } use base qw(TheSchwartz);
# This maps job names for Bugzilla::JobQueue to the appropriate modules. # This maps job names for Bugzilla::JobQueue to the appropriate modules.
# If you add new types of jobs, you should add a mapping here. # If you add new types of jobs, you should add a mapping here.
......
...@@ -64,7 +64,7 @@ package Bugzilla::XMLRPC::Deserializer; ...@@ -64,7 +64,7 @@ package Bugzilla::XMLRPC::Deserializer;
use strict; use strict;
# We can't use "use base" because XMLRPC::Serializer doesn't return # We can't use "use base" because XMLRPC::Serializer doesn't return
# a true value. # a true value.
eval { require XMLRPC::Lite; }; use XMLRPC::Lite;
our @ISA = qw(XMLRPC::Deserializer); our @ISA = qw(XMLRPC::Deserializer);
use Bugzilla::Error; use Bugzilla::Error;
...@@ -141,7 +141,7 @@ sub _validation_subs { ...@@ -141,7 +141,7 @@ sub _validation_subs {
package Bugzilla::XMLRPC::SOM; package Bugzilla::XMLRPC::SOM;
use strict; use strict;
eval { require XMLRPC::Lite; }; use XMLRPC::Lite;
our @ISA = qw(XMLRPC::SOM); our @ISA = qw(XMLRPC::SOM);
use Bugzilla::WebService::Util qw(taint_data); use Bugzilla::WebService::Util qw(taint_data);
...@@ -165,7 +165,7 @@ use Scalar::Util qw(blessed); ...@@ -165,7 +165,7 @@ use Scalar::Util qw(blessed);
use strict; use strict;
# We can't use "use base" because XMLRPC::Serializer doesn't return # We can't use "use base" because XMLRPC::Serializer doesn't return
# a true value. # a true value.
eval { require XMLRPC::Lite; }; use XMLRPC::Lite;
our @ISA = qw(XMLRPC::Serializer); our @ISA = qw(XMLRPC::Serializer);
sub new { sub new {
......
...@@ -27,12 +27,12 @@ use Bugzilla; ...@@ -27,12 +27,12 @@ use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::WebService::Constants; use Bugzilla::WebService::Constants;
if (!Bugzilla->feature('jsonrpc')) { BEGIN {
if (!Bugzilla->feature('jsonrpc')) {
ThrowCodeError('feature_disabled', { feature => 'jsonrpc' }); ThrowCodeError('feature_disabled', { feature => 'jsonrpc' });
}
} }
use Bugzilla::WebService::Server::JSONRPC;
# This eval allows runtests.pl to pass.
eval { require Bugzilla::WebService::Server::JSONRPC; };
Bugzilla->usage_mode(USAGE_MODE_JSON); Bugzilla->usage_mode(USAGE_MODE_JSON);
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
# The Original Code are the Bugzilla Tests. # The Original Code are the Bugzilla Tests.
# #
# The Initial Developer of the Original Code is Zach Lipton # The Initial Developer of the Original Code is Zach Lipton
# Portions created by Zach Lipton are # Portions created by Zach Lipton are Copyright (C) 2001 Zach Lipton.
# Copyright (C) 2001 Zach Lipton. All # All Rights Reserved.
# Rights Reserved.
# #
# Contributor(s): Zach Lipton <zach@zachlipton.com> # Contributor(s): Zach Lipton <zach@zachlipton.com>
# Max Kanat-Alexander <mkanat@bugzilla.org>
################# #################
...@@ -25,91 +25,97 @@ ...@@ -25,91 +25,97 @@
###Compilation### ###Compilation###
use strict; use strict;
use 5.008001;
use lib qw(. lib t); use lib qw(. lib t);
use Bugzilla::Constants;
use Support::Files; use Support::Files;
use Test::More tests => scalar(@Support::Files::testitems); use Test::More tests => scalar(@Support::Files::testitems);
# Need this to get the available driver information BEGIN {
use DBI; use_ok('Bugzilla::Constants');
my @DBI_drivers = DBI->available_drivers; use_ok('Bugzilla');
}
# Bugzilla requires Perl 5.8.1 now. Checksetup will tell you this if you run it, but use constant FEATURE_FILES => (
# it tests it in a polite/passive way that won't make it fail at compile time. We'll jsonrpc => ['Bugzilla/WebService/Server/JSONRPC.pm', 'jsonrpc.cgi'],
# slip in a compile-time failure if it's missing here so a tinderbox on < 5.8.1 won't xmlrpc => ['Bugzilla/WebService/Server/XMLRPC.pm', 'xmlrpc.cgi',
# pass and mistakenly let people think Bugzilla works on any perl below 5.8.1. 'Bugzilla/WebService.pm', 'Bugzilla/WebService/*.pm'],
require 5.008001; moving => ['importxml.pl'],
auth_ldap => ['Bugzilla/Auth/Verify/LDAP.pm'],
auth_radius => ['Bugzilla/Auth/Verify/RADIUS.pm'],
inbound_email => ['email_in.pl'],
jobqueue => ['Bugzilla/Job/*', 'Bugzilla/JobQueue.pm',
'Bugzilla/JobQueue/*', 'jobqueue.pl'],
patch_viewer => ['Bugzilla/Attachment/PatchReader.pm'],
updates => ['Bugzilla/Update.pm'],
);
# Capture the TESTOUT from Test::More or Test::Builder for printing errors. sub map_files_to_feature {
# This will handle verbosity for us automatically. my %features = FEATURE_FILES;
my $fh; my %files;
{ foreach my $feature (keys %features) {
local $^W = 0; # Don't complain about non-existent filehandles my @my_files = @{ $features{$feature} };
if (-e \*Test::More::TESTOUT) { foreach my $pattern (@my_files) {
$fh = \*Test::More::TESTOUT; foreach my $file (glob $pattern) {
} elsif (-e \*Test::Builder::TESTOUT) { $files{$file} = $feature;
$fh = \*Test::Builder::TESTOUT; }
} else { }
$fh = \*STDOUT;
} }
return \%files;
} }
my @testitems = @Support::Files::testitems; sub compile_file {
my $perlapp = "\"$^X\""; my ($file) = @_;
# Test the scripts by compiling them
foreach my $file (@testitems) { if ($file =~ s/\.pm$//) {
$file =~ s/\s.*$//; # nuke everything after the first space (#comment) $file =~ s{/}{::}g;
next if (!$file); # skip null entries use_ok($file);
return;
# Skip mod_perl.pl in all cases. It doesn't compile correctly from the command line.
if ($file eq 'mod_perl.pl') {
ok(1, "Skipping mod_perl.pl");
next;
} }
# Check that we have a DBI module to support the DB, if this is a database open(my $fh, $file);
# module (but not Schema) my $bang = <$fh>;
if ($file =~ m#Bugzilla/DB/([^/]+)\.pm$# && $file ne "Bugzilla/DB/Schema.pm") { close $fh;
if (!grep(lc($_) =~ /$1/i, @DBI_drivers)) {
ok(1,$file." - Skipping, as the DBD module not installed");
next;
}
}
open (FILE,$file);
my $bang = <FILE>;
close (FILE);
my $T = ""; my $T = "";
if ($bang =~ m/#!\S*perl\s+-.*T/) { if ($bang =~ m/#!\S*perl\s+-.*T/) {
$T = "T"; $T = "T";
} }
my $command = "$perlapp -c$T $file 2>&1";
my $loginfo=`$command`; my $perl = qq{"$^X"};
#print '@@'.$loginfo.'##'; my $output = `$perl -wc$T $file 2>&1`;
if ($loginfo =~ /syntax ok$/im) { chomp($output);
# Special hack due to CPAN.pm on Windows with Cygwin installed throwing my $return_val = $?;
# strings of the form "Set up gcc environment - 3.4.4 (cygming special, $output =~ s/^\Q$file\E syntax OK$//ms;
# gdc 0.12, using dmd 0.125)". See bug 416047 for details. diag($output) if $output;
if (ON_WINDOWS ok(!$return_val, $file) or diag('--ERROR');
&& grep($_ eq $file, 'install-module.pl', 'Bugzilla/Install/CPAN.pm')) }
{
$loginfo =~ s/^Set up gcc environment.*?\n//; my @testitems = @Support::Files::testitems;
} my $file_features = map_files_to_feature();
if ($loginfo ne "$file syntax OK\n") {
ok(0,$file." --WARNING"); # Test the scripts by compiling them
print $fh $loginfo; foreach my $file (@testitems) {
# These were already compiled, above.
next if ($file eq 'Bugzilla.pm' or $file eq 'Bugzilla/Constants.pm');
SKIP: {
if ($file eq 'mod_perl.pl') {
skip 'mod_perl.pl cannot be compiled from the command line', 1;
} }
else { my $feature = $file_features->{$file};
ok(1,$file); if ($feature and !Bugzilla->feature($feature)) {
skip "$file: $feature not enabled", 1;
} }
# 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;
} }
else {
ok(0,$file." --ERROR"); compile_file($file);
print $fh $loginfo;
} }
} }
exit 0;
...@@ -25,44 +25,14 @@ package Support::Files; ...@@ -25,44 +25,14 @@ package Support::Files;
use File::Find; use File::Find;
# exclude_deps is a hash of arrays listing the files to be excluded
# if a module is not available
#
@additional_files = (); @additional_files = ();
%exclude_deps = (
'XML::Twig' => ['importxml.pl'],
'Net::LDAP' => ['Bugzilla/Auth/Verify/LDAP.pm'],
'Authen::Radius' => ['Bugzilla/Auth/Verify/RADIUS.pm'],
'Email::Reply' => ['email_in.pl'],
'Email::MIME::Attachment::Stripper' => ['email_in.pl'],
'JSON::RPC' => ['Bugzilla/WebService/Server/JSONRPC.pm']
);
@files = glob('*'); @files = glob('*');
find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$/;}, 'Bugzilla'); find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$/;}, 'Bugzilla');
sub have_pkg {
my ($pkg) = @_;
my ($msg, $vnum, $vstr);
no strict 'refs';
eval { my $p; ($p = $pkg . ".pm") =~ s!::!/!g; require $p; };
return !($@);
}
@exclude_files = ();
foreach $dep (keys(%exclude_deps)) {
if (!have_pkg($dep)) {
push @exclude_files, @{$exclude_deps{$dep}};
}
}
sub isTestingFile { sub isTestingFile {
my ($file) = @_; my ($file) = @_;
my $exclude; my $exclude;
foreach $exclude (@exclude_files) {
if ($file eq $exclude) { return undef; } # get rid of excluded files.
}
if ($file =~ /\.cgi$|\.pl$|\.pm$/) { if ($file =~ /\.cgi$|\.pl$|\.pm$/) {
return 1; return 1;
......
...@@ -22,12 +22,12 @@ use Bugzilla; ...@@ -22,12 +22,12 @@ use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::WebService::Constants; use Bugzilla::WebService::Constants;
if (!Bugzilla->feature('xmlrpc')) { BEGIN {
if (!Bugzilla->feature('xmlrpc')) {
ThrowCodeError('feature_disabled', { feature => 'xmlrpc' }); ThrowCodeError('feature_disabled', { feature => 'xmlrpc' });
}
} }
# Use an eval here so that runtests.pl accepts this script even if SOAP-Lite use Bugzilla::WebService::Server::XMLRPC;
# is not installed.
eval { require Bugzilla::WebService::Server::XMLRPC; };
Bugzilla->usage_mode(USAGE_MODE_XMLRPC); Bugzilla->usage_mode(USAGE_MODE_XMLRPC);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment