kivitendo/t/structure/globals.t @ 5d6e7d01
914c56f4 | Sven Schöling | #!/usr/bin/perl
|
||
use strict;
|
||||
use lib 't';
|
||||
use Support::Files;
|
||||
cc849a74 | Sven Schöling | use Support::CanonialGlobals ();
|
||
914c56f4 | Sven Schöling | |||
my (@globals, $testcount);
|
||||
BEGIN {
|
||||
b56d9999 | Sven Schöling | @globals = map { s/[^a-z_]//g; $_ } @Support::CanonialGlobals::globals;
|
||
914c56f4 | Sven Schöling | $testcount = scalar(@Support::Files::testitems);
|
||
}
|
||||
b56d9999 | Sven Schöling | |||
914c56f4 | Sven Schöling | 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 = <FILE>) { # 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 {
|
||||
b56d9999 | Sven Schöling | ok(1,$file);
|
||
914c56f4 | Sven Schöling | }
|
||
} else {
|
||||
ok(0,"could not open $file for globals check --WARNING");
|
||||
}
|
||||
}
|
||||
exit 0;
|