diff options
author | gerv%gerv.net <> | 2003-11-09 02:09:22 +0000 |
---|---|---|
committer | gerv%gerv.net <> | 2003-11-09 02:09:22 +0000 |
commit | 090dae01f8ab1810120276d48d265a19588be664 (patch) | |
tree | 2f774d89434428b171610aaa76b9d5dbd2bda3ff /t | |
parent | fc7ebc28b0859d7ddecd704001ff1adc54856d47 (diff) | |
download | bugs-090dae01f8ab1810120276d48d265a19588be664.tar bugs-090dae01f8ab1810120276d48d265a19588be664.tar.gz bugs-090dae01f8ab1810120276d48d265a19588be664.tar.bz2 bugs-090dae01f8ab1810120276d48d265a19588be664.tar.xz bugs-090dae01f8ab1810120276d48d265a19588be664.zip |
Bug 224913 - Need tests to check whether any templates uses the bareword "bug" or variations. Patch by gerv; r,a=justdave.
Diffstat (limited to 't')
-rw-r--r-- | t/009bugwords.t | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/t/009bugwords.t b/t/009bugwords.t new file mode 100644 index 000000000..564e7f67a --- /dev/null +++ b/t/009bugwords.t @@ -0,0 +1,118 @@ +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code are the Bugzilla tests. +# +# The Initial Developer of the Original Code is Jacob Steenhagen. +# Portions created by Jacob Steenhagen are +# Copyright (C) 2001 Jacob Steenhagen. All +# Rights Reserved. +# +# Contributor(s): Gervase Markham <gerv@gerv.net> +# + +################# +#Bugzilla Test 9# +####bugwords##### + +# Bugzilla has a mechanism for taking various words, including "bug", "bugs", +# and "a bug" and automatically replacing them in the templates with the local +# terminology. It does this by using the 'terms' hash, so "bug" becomes +# "[% terms.bug %]". This test makes sure the relevant words aren't used +# bare. + +use strict; + +use lib 't'; + +use Support::Files; +use Support::Templates; +use Bugzilla::Util; + +use File::Spec 0.82; + +# We have a list of templates to exclude, if present. This allows us to exclude +# sample and b.m.o.-specific templates. Do _not_ add a template to this list +# without checking with developers@bugzilla.org first. +my @exclude; + +BEGIN { + @exclude = ( + 'template/en/default/pages/etiquette.html.tmpl' + ); +} + +use Test::More tests => ($Support::Templates::num_actual_files - + scalar(@exclude)); + +# Find all the templates (except those in @exclude) +my @testitems; +for my $path (@Support::Templates::include_paths) { + my @items = map(File::Spec->catfile($path, $_), + Support::Templates::find_actual_files($path)); + foreach my $item (@items) { + if (lsearch(\@exclude, $item) == -1) { + push(@testitems, $item); + } + } +} + +foreach my $file (@testitems) { + my @errors; + + # Read the entire file into a string + local $/; + open (FILE, "<$file") || die "Can't open $file: $!\n"; + my $slurp = <FILE>; + close (FILE); + + # /g means we execute this loop for every match + # /s means we ignore linefeeds in the regexp matches + # This extracts everything which is _not_ a directive. + while ($slurp =~ /%\](.*?)(\[%|$)/gs) { + my $text = $1; + + my @lineno = ($` =~ m/\n/gs); + my $lineno = scalar(@lineno) + 1; + + # "a bug", "bug", "bugs" + if (grep /(a?[\s>]bugs?[\s.:;])/i, $text) { + # Exclude variable assignment. + unless (grep /bugs =/, $text) { + push(@errors, [$lineno, $text]); + next; + } + } + + # "Bugzilla" + if (grep /Bugzilla[^_]/, $text) { + # Exclude JS comments, hyperlinks, USE and variable assignment. + unless (grep /(\/\/.*|org.*>|USE |= )Bugzilla/, $text) { + push(@errors, [$lineno, $text]); + next; + } + } + } + + if (scalar(@errors)) { + ok(0, "$file contains invalid bare words (e.g. 'bug') --WARNING"); + + foreach my $error (@errors) { + print "$error->[0]: $error->[1]\n"; + } + } + else { + ok(1, "$file has no invalid barewords"); + } +} + +exit 0; |