From 4afae456014ff01ee01e11279fc5a9b5f4f7b5bf Mon Sep 17 00:00:00 2001 From: "bbaetz%student.usyd.edu.au" <> Date: Tue, 7 May 2002 16:45:28 +0000 Subject: Bug 135543 - @Support::Templates::testitems does not list all templates Patch by ddkilzer@theracingworld.com (David D. Kilzer), r=gerv, justdave --- t/Support/Templates.pm | 59 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) (limited to 't/Support') 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 +# David D. Kilzer # 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 = ; 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; } } } -- cgit v1.2.3-24-g4f1b