From: Sven Schöling Date: Thu, 14 Apr 2011 10:53:21 +0000 (+0200) Subject: Testscript um auf globale Variablen zu testen, die bei der Umstellung auf lx_office... X-Git-Tag: release-2.6.3~33^2~11 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=914c56f424742187477b90604acfe7de93dbb5c0;p=kivitendo-erp.git Testscript um auf globale Variablen zu testen, die bei der Umstellung auf lx_office.conf vergessen wurden. --- diff --git a/t/structure/globals.t b/t/structure/globals.t new file mode 100644 index 000000000..b1b351f7a --- /dev/null +++ b/t/structure/globals.t @@ -0,0 +1,63 @@ +#!/usr/bin/perl + +use strict; +use lib 't'; +use Support::Files; + +my (@globals, $testcount); + +BEGIN { + @globals = qw(lxdebug auth myconfig form cgi lx_office_conf locale); + $testcount = scalar(@Support::Files::testitems); +} + +use Test::More tests => $testcount; + +# Capture the TESTOUT from Test::More or Test::Builder for printing errors. +# This will handle verbosity for us automatically. +my $fh; +{ + local $^W = 0; # Don't complain about non-existent filehandles + if (-e \*Test::More::TESTOUT) { + $fh = \*Test::More::TESTOUT; + } elsif (-e \*Test::Builder::TESTOUT) { + $fh = \*Test::Builder::TESTOUT; + } else { + $fh = \*STDOUT; + } +} + +my @testitems = @Support::Files::testitems; + +# at last, here we actually run the test... +my $evilwordsregexp = join('|', @globals); + +foreach my $file (@testitems) { + $file =~ s/\s.*$//; # nuke everything after the first space (#comment) + next if (!$file); # skip null entries + + if (open (FILE, $file)) { # open the file for reading + + my $found_word = ''; + + while (my $file_line = ) { # and go through the file line by line + if ($file_line =~ /([\$%@](?:main)?::(?!$evilwordsregexp)\w+\b)/i) { # found an evil word + $found_word = $1; + last; + } + } + + close (FILE); + + if ($found_word) { + ok(0,"$file: found UNREGISTERED GLOBAL $found_word --WARNING"); + } else { + ok(1,"$file does only contain registered globals"); + } + } else { + ok(0,"could not open $file for globals check --WARNING"); + } +} + +exit 0; +