Bug 135543 - @Support::Templates::testitems does not list all templates

Patch by ddkilzer@theracingworld.com (David D. Kilzer), r=gerv, justdave
parent b8465474
......@@ -1547,6 +1547,9 @@ $::template ||= Template->new(
COMPILE_DIR => 'data/',
# Functions for processing text within templates in various ways.
# IMPORTANT! When adding a filter here that does not override a
# built-in filter, please also add a stub filter to checksetup.pl
# and t/004template.t.
FILTERS =>
{
# Render text in strike-through style.
......
......@@ -19,24 +19,28 @@
#
# Contributor(s): Jacob Steenhagen <jake@acutex.net>
# Zach Lipton <zach@zachlipton.com>
# David D. Kilzer <ddkilzer@kilzer.net>
#
#################
#Bugzilla Test 4#
####Templates####
BEGIN { use lib "t/"; }
BEGIN { use Support::Templates; }
BEGIN { $tests = @Support::Templates::testitems * 3; }
BEGIN { use Test::More tests => $tests; }
use diagnostics;
use strict;
use Template;
use lib 't';
use Support::Templates;
# Bug 137589 - Disable command-line input of CGI.pm when testing
use CGI qw(-no_debug);
my @testitems = @Support::Templates::testitems;
use File::Spec 0.82;
use Template;
use Test::More tests => ( scalar(@Support::Templates::referenced_files)
+ scalar(@Support::Templates::actual_files) * 2);
my $include_path = $Support::Templates::include_path;
# Capture the TESTERR from Test::More for printing errors.
# This will handle verbosity for us automatically
......@@ -45,13 +49,12 @@ my $include_path = $Support::Templates::include_path;
# Check to make sure all templates that are referenced in
# Bugzilla exist in the proper place.
my %exists;
foreach my $file(@testitems) {
if (-e $include_path . "/" . $file) {
ok(1, "$file exists");
$exists{$file} = 1;
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, "$file does not exist --ERROR");
ok(0, "$path does not exist --ERROR");
}
}
......@@ -61,6 +64,7 @@ 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 =>
{
js => sub { return $_ } ,
......@@ -74,8 +78,9 @@ 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(@testitems) {
if ($exists{$file}) {
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");
}
......@@ -85,7 +90,7 @@ foreach my $file(@testitems) {
}
}
else {
ok(1, "$file doesn't exist, skipping test");
ok(1, "$path doesn't exist, skipping test");
}
}
open STDOUT, ">&SAVEOUT"; # redirect back to original stream
......@@ -95,8 +100,9 @@ close SAVEERR;
# check to see that all templates have a version string:
foreach my $file(@testitems) {
open(TMPL,"$include_path/$file");
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");
......
......@@ -18,34 +18,37 @@
# Rights Reserved.
#
# Contributor(s): Jacob Steenhagen <jake@acutex.net>
# David D. Kilzer <ddkilzer@kilzer.net>
#
#################
#Bugzilla Test 5#
#####no_tabs#####
BEGIN { use lib "t/"; }
BEGIN { use Support::Files; }
BEGIN { use Support::Templates; }
BEGIN { $tests = @Support::Files::testitems; }
BEGIN { $tests += @Support::Templates::testitems; }
BEGIN { use Test::More tests => $tests; }
use diagnostics;
use strict;
use lib 't';
use Support::Files;
use Support::Templates;
use File::Spec 0.82;
use Test::More tests => ( scalar(@Support::Files::testitems)
+ scalar(@Support::Templates::actual_files));
my @testitems = @Support::Files::testitems;
my @templates = map($Support::Templates::include_path . "/" . $_,
@Support::Templates::testitems);
my @templates = map(File::Spec->catfile($Support::Templates::include_path, $_),
@Support::Templates::actual_files);
push(@testitems, @templates);
foreach my $file (@testitems) {
open (FILE, "$file");
my @file = <FILE>;
close (FILE);
if (grep /\t/, @file) {
if (grep /\t/, <FILE>) {
ok(0, "$file contains tabs --WARNING");
} else {
ok(1, "$file has no tabs");
}
close (FILE);
}
......@@ -18,32 +18,73 @@
# Rights Reserved.
#
# Contributor(s): Jacob Steenhagen <jake@acutex.net>
# David D. Kilzer <ddkilzer@kilzer.net>
#
package Support::Templates;
use diagnostics;
use strict;
use lib 't';
use vars qw($include_path @referenced_files @actual_files);
use Support::Files;
$include_path = "template/en/default";
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');
@referenced_files = ();
@actual_files = ();
# Local subroutine used with File::Find
sub find_templates {
# Prune CVS directories
if (-d $_ && $_ eq 'CVS') {
$File::Find::prune = 1;
return;
}
# Only include files ending in '.tmpl'
if (-f $_ && $_ =~ m/\.tmpl$/i) {
my $filename;
my $local_dir = File::Spec->abs2rel($File::Find::dir,
$File::Find::topdir);
if ($local_dir) {
$filename = File::Spec->catfile($local_dir, $_);
} else {
$filename = $_;
}
push(@actual_files, $filename);
}
}
# Scan Bugzilla's code looking for templates used and put them
# in the @testitems array to be used by the template.t test.
# 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));
my @files = @Support::Files::testitems;
my %t;
# 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.
my %seen;
foreach my $file (@files) {
foreach my $file (@Support::Files::testitems) {
open (FILE, $file);
my @lines = <FILE>;
close (FILE);
foreach my $line (@lines) {
if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) {
$template = $1;
my $template = $1;
# Ignore templates with $ in the name, since they're
# probably vars, not real files
next if $template =~ m/\$/;
push (@testitems, $template) unless $t{$template};
$t{$template} = 1;
next if $seen{$template};
push (@referenced_files, $template);
$seen{$template} = 1;
}
}
}
......
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