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