$::request als globale Variable eingeführt.
[kivitendo-erp.git] / t / structure / globals.t
1 #!/usr/bin/perl
2
3 use strict;
4 use lib 't';
5 use Support::Files;
6
7 my (@globals, $testcount);
8
9 BEGIN {
10   @globals = qw(lxdebug auth myconfig form cgi lx_office_conf locale dispatcher instance_conf request);
11   $testcount = scalar(@Support::Files::testitems);
12 }
13
14 use Test::More tests => $testcount;
15
16 # Capture the TESTOUT from Test::More or Test::Builder for printing errors.
17 # This will handle verbosity for us automatically.
18 my $fh;
19 {
20     local $^W = 0;  # Don't complain about non-existent filehandles
21     if (-e \*Test::More::TESTOUT) {
22         $fh = \*Test::More::TESTOUT;
23     } elsif (-e \*Test::Builder::TESTOUT) {
24         $fh = \*Test::Builder::TESTOUT;
25     } else {
26         $fh = \*STDOUT;
27     }
28 }
29
30 my @testitems = @Support::Files::testitems;
31
32 # at last, here we actually run the test...
33 my $evilwordsregexp = join('|', @globals);
34
35 foreach my $file (@testitems) {
36     $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
37     next if (!$file); # skip null entries
38
39     if (open (FILE, $file)) { # open the file for reading
40
41         my $found_word = '';
42
43         while (my $file_line = <FILE>) { # and go through the file line by line
44             if ($file_line =~ /([\$%@](?:main)?::(?!$evilwordsregexp)\w+\b)/i) { # found an evil word
45                 $found_word = $1;
46                 last;
47             }
48         }
49
50         close (FILE);
51
52         if ($found_word) {
53             ok(0,"$file: found UNREGISTERED GLOBAL $found_word --WARNING");
54         } else {
55             ok(1,"$file does only contain registered globals");
56         }
57     } else {
58         ok(0,"could not open $file for globals check --WARNING");
59     }
60 }
61
62 exit 0;
63