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( ...@@ -1547,6 +1547,9 @@ $::template ||= Template->new(
COMPILE_DIR => 'data/', COMPILE_DIR => 'data/',
# Functions for processing text within templates in various ways. # 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 => FILTERS =>
{ {
# Render text in strike-through style. # Render text in strike-through style.
......
...@@ -19,24 +19,28 @@ ...@@ -19,24 +19,28 @@
# #
# Contributor(s): Jacob Steenhagen <jake@acutex.net> # Contributor(s): Jacob Steenhagen <jake@acutex.net>
# Zach Lipton <zach@zachlipton.com> # Zach Lipton <zach@zachlipton.com>
# David D. Kilzer <ddkilzer@kilzer.net>
# #
################# #################
#Bugzilla Test 4# #Bugzilla Test 4#
####Templates#### ####Templates####
BEGIN { use lib "t/"; } use diagnostics;
BEGIN { use Support::Templates; }
BEGIN { $tests = @Support::Templates::testitems * 3; }
BEGIN { use Test::More tests => $tests; }
use strict; use strict;
use Template;
use lib 't';
use Support::Templates;
# Bug 137589 - Disable command-line input of CGI.pm when testing # Bug 137589 - Disable command-line input of CGI.pm when testing
use CGI qw(-no_debug); 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; my $include_path = $Support::Templates::include_path;
# Capture the TESTERR from Test::More for printing errors. # Capture the TESTERR from Test::More for printing errors.
# This will handle verbosity for us automatically # This will handle verbosity for us automatically
...@@ -45,13 +49,12 @@ my $include_path = $Support::Templates::include_path; ...@@ -45,13 +49,12 @@ my $include_path = $Support::Templates::include_path;
# Check to make sure all templates that are referenced in # Check to make sure all templates that are referenced in
# Bugzilla exist in the proper place. # Bugzilla exist in the proper place.
my %exists; foreach my $file(@Support::Templates::referenced_files) {
foreach my $file(@testitems) { my $path = File::Spec->catfile($include_path, $file);
if (-e $include_path . "/" . $file) { if (-e $path) {
ok(1, "$file exists"); ok(1, "$path exists");
$exists{$file} = 1;
} else { } else {
ok(0, "$file does not exist --ERROR"); ok(0, "$path does not exist --ERROR");
} }
} }
...@@ -61,6 +64,7 @@ my $template = Template->new( ...@@ -61,6 +64,7 @@ my $template = Template->new(
INCLUDE_PATH => $include_path , INCLUDE_PATH => $include_path ,
# Need to define filters used in the codebase, they don't # Need to define filters used in the codebase, they don't
# actually have to function in this test, just be defined. # actually have to function in this test, just be defined.
# See globals.pl for the actual codebase definitions.
FILTERS => FILTERS =>
{ {
js => sub { return $_ } , js => sub { return $_ } ,
...@@ -74,8 +78,9 @@ open SAVEOUT, ">&STDOUT"; # stash the original output stream ...@@ -74,8 +78,9 @@ open SAVEOUT, ">&STDOUT"; # stash the original output stream
open SAVEERR, ">&STDERR"; open SAVEERR, ">&STDERR";
open STDOUT, "> /dev/null"; # discard all output open STDOUT, "> /dev/null"; # discard all output
open STDERR, "> /dev/null"; open STDERR, "> /dev/null";
foreach my $file(@testitems) { foreach my $file(@Support::Templates::actual_files) {
if ($exists{$file}) { my $path = File::Spec->catfile($include_path, $file);
if (-e $path) {
if ($template->process($file)) { if ($template->process($file)) {
ok(1, "$file syntax ok"); ok(1, "$file syntax ok");
} }
...@@ -85,7 +90,7 @@ foreach my $file(@testitems) { ...@@ -85,7 +90,7 @@ foreach my $file(@testitems) {
} }
} }
else { 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 open STDOUT, ">&SAVEOUT"; # redirect back to original stream
...@@ -95,8 +100,9 @@ close SAVEERR; ...@@ -95,8 +100,9 @@ close SAVEERR;
# check to see that all templates have a version string: # check to see that all templates have a version string:
foreach my $file(@testitems) { foreach my $file(@Support::Templates::actual_files) {
open(TMPL,"$include_path/$file"); my $path = File::Spec->catfile($include_path, $file);
open(TMPL, $path);
my $firstline = <TMPL>; my $firstline = <TMPL>;
if ($firstline =~ /\d+\.\d+\@[\w\.-]+/) { if ($firstline =~ /\d+\.\d+\@[\w\.-]+/) {
ok(1,"$file has a version string"); ok(1,"$file has a version string");
......
...@@ -18,34 +18,37 @@ ...@@ -18,34 +18,37 @@
# Rights Reserved. # Rights Reserved.
# #
# Contributor(s): Jacob Steenhagen <jake@acutex.net> # Contributor(s): Jacob Steenhagen <jake@acutex.net>
# David D. Kilzer <ddkilzer@kilzer.net>
# #
################# #################
#Bugzilla Test 5# #Bugzilla Test 5#
#####no_tabs##### #####no_tabs#####
BEGIN { use lib "t/"; } use diagnostics;
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 strict; 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 @testitems = @Support::Files::testitems;
my @templates = map($Support::Templates::include_path . "/" . $_, my @templates = map(File::Spec->catfile($Support::Templates::include_path, $_),
@Support::Templates::testitems); @Support::Templates::actual_files);
push(@testitems, @templates); push(@testitems, @templates);
foreach my $file (@testitems) { foreach my $file (@testitems) {
open (FILE, "$file"); open (FILE, "$file");
my @file = <FILE>; if (grep /\t/, <FILE>) {
close (FILE);
if (grep /\t/, @file) {
ok(0, "$file contains tabs --WARNING"); ok(0, "$file contains tabs --WARNING");
} else { } else {
ok(1, "$file has no tabs"); ok(1, "$file has no tabs");
} }
close (FILE);
} }
...@@ -18,32 +18,73 @@ ...@@ -18,32 +18,73 @@
# Rights Reserved. # Rights Reserved.
# #
# Contributor(s): Jacob Steenhagen <jake@acutex.net> # Contributor(s): Jacob Steenhagen <jake@acutex.net>
# David D. Kilzer <ddkilzer@kilzer.net>
# #
package Support::Templates; package Support::Templates;
use diagnostics;
use strict;
use lib 't';
use vars qw($include_path @referenced_files @actual_files);
use Support::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 # Scan the template include path for templates then put them in
# in the @testitems array to be used by the template.t test. # in the @actual_files array to be used by various tests.
map(find(\&find_templates, $_), split(':', $include_path));
my @files = @Support::Files::testitems; # Scan Bugzilla's perl code looking for templates used and put them
my %t; # 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); open (FILE, $file);
my @lines = <FILE>; my @lines = <FILE>;
close (FILE); close (FILE);
foreach my $line (@lines) { foreach my $line (@lines) {
if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) { if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) {
$template = $1; my $template = $1;
# Ignore templates with $ in the name, since they're # Ignore templates with $ in the name, since they're
# probably vars, not real files # probably vars, not real files
next if $template =~ m/\$/; next if $template =~ m/\$/;
push (@testitems, $template) unless $t{$template}; next if $seen{$template};
$t{$template} = 1; 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