-
Notifications
You must be signed in to change notification settings - Fork 42
/
00_compile.t
110 lines (96 loc) · 3.07 KB
/
00_compile.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use warnings;
# We don't load WebGUI::Test, because we want to test the
# loading of WebGUI::Session ourselves
use Test::More;
use File::Find;
use File::Spec;
use File::Spec::Functions;
use File::Basename;
use Cwd qw(realpath);
my $wgRoot = realpath catdir(dirname(__FILE__), updir);
my $wgLib = catdir($wgRoot, 'lib');
unshift @INC, $wgLib;
my @modules = findModules($wgLib);
my @scripts = findScripts(catdir($wgRoot, 'docs', 'upgrades'), catdir($wgRoot, 'sbin'));
plan tests => 2 * (scalar @modules + scalar @scripts);
my $failed_compile = 0;
foreach my $library (@modules) {
my $warnings = '';
local $^W = 1;
local $SIG{__WARN__} = sub {
my $warn = shift;
# file the warning occurred in
my $caller = caller;
my $warning_file = realpath( (caller(0))[1] );
# only care about it if it is within the WebGUI lib directory or is an explicit warning
if ($warning_file =~ /^\Q$wgLib/ || $caller eq 'Carp') {
$warnings .= $warn;
}
};
eval {
require $library;
};
chomp $warnings;
is($@, '', "$library compiles successfully")
|| $failed_compile++;
is($warnings, '', "$library compiles without warnings");
}
my $script_compiler = <<'END_SCRIPT';
return 1;
package WebGUI::Test::ScriptTest::%s;
use warnings;
# line 1 "%s"
%s
END_SCRIPT
for my $script (@scripts) {
open my $fh, '<', $script;
my $script_content = do { local $/; <$fh> };
close $fh;
my $short_name = File::Spec->abs2rel($script, $wgRoot);
my $package_name = $script;
$package_name =~ s{.*/}{}msx;
$package_name =~ s/\W//msxg;
my $to_compile = sprintf $script_compiler, $package_name, $short_name, $script_content;
my $warnings = '';
local $SIG{__WARN__} = sub {
$warnings .= shift;
};
eval $to_compile;
chomp $warnings;
is($@, '', "$short_name compiles successfully");
is($warnings, '', "$short_name compiles without warnings");
}
if ($failed_compile) {
BAIL_OUT("Failed to compile $failed_compile modules!");
}
#----------------------------------------
sub findModules {
my $libDir = shift;
my @modules;
File::Find::find( {
no_chdir => 1,
wanted => sub {
return unless $File::Find::name =~ /\.pm$/;
my $lib = File::Spec->abs2rel($File::Find::name, $libDir);
push @modules, $lib;
},
}, $libDir);
return @modules;
}
sub findScripts {
my @scripts;
for my $dir (@_) {
push @scripts, glob("$dir/*.pl");
}
return @scripts;
}