diff options
Diffstat (limited to 't/Support')
-rw-r--r-- | t/Support/Templates.pm | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/t/Support/Templates.pm b/t/Support/Templates.pm index fb5303721..07f46f700 100644 --- a/t/Support/Templates.pm +++ b/t/Support/Templates.pm @@ -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; } } } |