# Copyright (C) 2001 Jacob Steenhagen. All
# Rights Reserved.
#
-# Contributor(s): Jacob Steenhagen <jake@acutex.net>
+# Contributor(s): Jacob Steenhagen <jake@bugzilla.org>
# Zach Lipton <zach@zachlipton.com>
# David D. Kilzer <ddkilzer@kilzer.net>
+# Tobias Burnus <burnus@net-b.de>
#
#################
use File::Spec 0.82;
use Template;
-use Test::More tests => ( scalar(@Support::Templates::referenced_files)
- + scalar(@Support::Templates::actual_files) * 2);
+use Test::More tests => ( scalar(@referenced_files) + $num_actual_files * 2 );
# Capture the TESTOUT from Test::More or Test::Builder for printing errors.
# This will handle verbosity for us automatically.
}
}
-my $include_path = $Support::Templates::include_path;
+# Checks whether one of the passed files exists
+sub existOnce {
+ foreach my $file (@_) {
+ return $file if -e $file;
+ }
+ return 0;
+}
# Check to make sure all templates that are referenced in
# Bugzilla exist in the proper place.
-foreach my $file(@Support::Templates::referenced_files) {
- my $path = File::Spec->catfile($include_path, $file);
- if (-e $path) {
- ok(1, "$path exists");
- } else {
- ok(0, "$path does not exist --ERROR");
+foreach my $lang (@languages) {
+ foreach my $file (@referenced_files) {
+ my @path = map(File::Spec->catfile($_, $file),
+ split(':', $include_path{$lang}));
+ if (my $path = existOnce(@path)) {
+ ok(1, "$path exists");
+ } else {
+ ok(0, "$file cannot be located --ERROR");
+ print $fh "Looked in:\n " . join("\n ", @path);
+ }
}
}
-# Processes all the templates to make sure they have good syntax
-my $template = Template->new(
-{
- INCLUDE_PATH => $include_path ,
- # Need to define filters used in the codebase, they don't
- # actually have to function in this test, just be defined.
- # See globals.pl for the actual codebase definitions.
- FILTERS =>
+foreach my $include_path (@include_paths) {
+ # Processes all the templates to make sure they have good syntax
+ my $provider = Template::Provider->new(
{
- html_linebreak => sub { return $_; },
- js => sub { return $_ } ,
- strike => sub { return $_ } ,
- url_quote => sub { return $_ } ,
- },
-}
-);
-
-open SAVEOUT, ">&STDOUT"; # stash the original output stream
-open SAVEERR, ">&STDERR";
-open STDOUT, "> /dev/null"; # discard all output
-open STDERR, "> /dev/null";
-foreach my $file(@Support::Templates::actual_files) {
- my $path = File::Spec->catfile($include_path, $file);
- if (-e $path) {
- if ($template->process($file)) {
- ok(1, "$file syntax ok");
+ INCLUDE_PATH => $include_path ,
+ # Need to define filters used in the codebase, they don't
+ # actually have to function in this test, just be defined.
+ # See globals.pl for the actual codebase definitions.
+ FILTERS =>
+ {
+ html_linebreak => sub { return $_; },
+ js => sub { return $_ } ,
+ strike => sub { return $_ } ,
+ url_quote => sub { return $_ } ,
+ xml => sub { return $_ } ,
+ quoteUrls => sub { return $_ } ,
+ bug_link => [ sub { return sub { return $_; } }, 1] ,
+ csv => sub { return $_ } ,
+ time => sub { return $_ } ,
+ },
+ }
+ );
+
+ foreach my $file (@{$actual_files{$include_path}}) {
+ my $path = File::Spec->catfile($include_path, $file);
+ if (-e $path) {
+ my ($data, $err) = $provider->fetch($file);
+
+ if (!$err) {
+ ok(1, "$file syntax ok");
+ }
+ else {
+ ok(0, "$file has bad syntax --ERROR");
+ print $fh $data . "\n";
+ }
}
else {
- ok(0, "$file has bad syntax --ERROR");
- print $fh $template->error() . "\n";
+ ok(1, "$path doesn't exist, skipping test");
}
}
- else {
- ok(1, "$path doesn't exist, skipping test");
- }
-}
-open STDOUT, ">&SAVEOUT"; # redirect back to original stream
-open STDERR, ">&SAVEERR";
-close SAVEOUT;
-close SAVEERR;
-
-# check to see that all templates have a version string:
-
-foreach my $file(@Support::Templates::actual_files) {
- my $path = File::Spec->catfile($include_path, $file);
- open(TMPL, $path);
- my $firstline = <TMPL>;
- if ($firstline =~ /\d+\.\d+\@[\w\.-]+/) {
- ok(1,"$file has a version string");
- } else {
- ok(0,"$file does not have a version string --ERROR");
+
+ # check to see that all templates have a version string:
+
+ foreach my $file (@{$actual_files{$include_path}}) {
+ my $path = File::Spec->catfile($include_path, $file);
+ open(TMPL, $path);
+ my $firstline = <TMPL>;
+ if ($firstline =~ /\d+\.\d+\@[\w\.-]+/) {
+ ok(1,"$file has a version string");
+ } else {
+ ok(0,"$file does not have a version string --ERROR");
+ }
+ close(TMPL);
}
- close(TMPL);
}
exit 0;
# Rights Reserved.
#
# Contributor(s): Zach Lipton <zach@zachlipton.com>
-#
-# Alternatively, the contents of this file may be used under the
-# terms of the GNU General Public License Version 2 or later (the
-# "GPL"), in which case the provisions of the GPL are applicable
-# instead of those above. If you wish to allow use of your
-# version of this file only under the terms of the GPL and not to
-# allow others to use your version of this file under the MPL,
-# indicate your decision by deleting the provisions above and
-# replace them with the notice and other provisions required by
-# the GPL. If you do not delete the provisions above, a recipient
-# may use your version of this file under either the MPL or the
-# GPL.
-#
+# Joel Peshkin <bugreport@peshkin.net>
+
package Support::Files;
-@additional_files = ('syncshadowdb','processmail');
-@exclude_files = ('importxml.pl');
+# exclude_deps is a hash of arrays listing the files to be excluded
+# if a module is not available
+#
+@additional_files = ();
+%exclude_deps = (
+ 'XML::Parser' => ['importxml.pl'],
+);
+
+# XXX - this file should be rewritten to use File::Find or similar
$file = '*';
-@files = glob($file);
+@files = (glob($file), glob('Bugzilla/*.pm'));
+
+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 {
- my ($file) = @_;
- my $exclude;
- foreach $exclude (@exclude_files) {
+ my ($file) = @_;
+ my $exclude;
+ foreach $exclude (@exclude_files) {
if ($file eq $exclude) { return undef; } # get rid of excluded files.
- }
+ }
- if ($file =~ /\.cgi$|\.pl$|\.pm$/) {
- return 1;
- }
- my $additional;
- foreach $additional (@additional_files) {
- if ($file eq $additional) { return 1; }
- }
- return undef;
+ if ($file =~ /\.cgi$|\.pl$|\.pm$/) {
+ return 1;
+ }
+ my $additional;
+ foreach $additional (@additional_files) {
+ if ($file eq $additional) { return 1; }
+ }
+ return undef;
}
foreach $currentfile (@files) {
- if (isTestingFile($currentfile)) {
- push(@testitems,$currentfile);
- }
+ if (isTestingFile($currentfile)) {
+ push(@testitems,$currentfile);
+ }
}
# Copyright (C) 2001 Jacob Steenhagen. All
# Rights Reserved.
#
-# Contributor(s): Jacob Steenhagen <jake@acutex.net>
+# Contributor(s): Jacob Steenhagen <jake@bugzilla.org>
# David D. Kilzer <ddkilzer@kilzer.net>
+# Tobias Burnus <burnus@net-b.de>
#
package Support::Templates;
-use diagnostics;
use strict;
use lib 't';
-use vars qw($include_path @referenced_files @actual_files);
+use base qw(Exporter);
+@Support::Templates::EXPORT =
+ qw(@languages @include_paths %include_path @referenced_files
+ %actual_files $num_actual_files);
+use vars qw(@languages @include_paths %include_path @referenced_files
+ %actual_files $num_actual_files);
use Support::Files;
use File::Find;
use File::Spec 0.82;
-# Note that $include_path is assumed to only contain ONE path, not
-# a list of colon-separated paths.
-$include_path = File::Spec->catdir('template', 'en', 'default');
+# The available template languages
+@languages = ();
+
+# The colon separated includepath per language
+%include_path = ();
+
+# All include paths
+@include_paths = ();
+
+# Files which are referenced in the cgi files
@referenced_files = ();
-@actual_files = ();
+
+# All files sorted by include_path
+%actual_files = ();
+
+# total number of actual_files
+$num_actual_files = 0;
+
+# Scan for the template available languages and include paths
+{
+ opendir(DIR, "template") || die "Can't open 'template': $!";
+ my @files = grep { /^[a-z-]+$/i } readdir(DIR);
+ closedir DIR;
+
+ foreach my $langdir (@files) {
+ next if($langdir =~ /^CVS$/i);
+
+ my $path = File::Spec->catdir('template', $langdir, 'custom');
+ my @dirs = ();
+ push(@dirs, $path) if(-d $path);
+ $path = File::Spec->catdir('template', $langdir, 'default');
+ push(@dirs, $path) if(-d $path);
+
+ next if(scalar(@dirs) == 0);
+ push(@languages, $langdir);
+ push(@include_paths, @dirs);
+ $include_path{$langdir} = join(":",@dirs);
+ }
+}
+
+
+my @files;
# Local subroutine used with File::Find
sub find_templates {
$filename = $_;
}
- push(@actual_files, $filename);
+ push(@files, $filename);
}
}
-# Scan the template include path for templates then put them in
-# in the @actual_files array to be used by various tests.
-map(find(\&find_templates, $_), split(':', $include_path));
+# Scan the given template include path for templates
+sub find_actual_files {
+ my $include_path = $_[0];
+ @files = ();
+ find(\&find_templates, $include_path);
+ return @files;
+}
+
+
+foreach my $include_path (@include_paths) {
+ $actual_files{$include_path} = [ find_actual_files($include_path) ];
+ $num_actual_files += scalar(@{$actual_files{$include_path}});
+}
# Scan Bugzilla's perl code looking for templates used and put them
# in the @referenced_files array to be used by the 004template.t test.