diff --git a/t/syntaxCheck.t b/t/syntaxCheck.t index 2a605c188..8f49dfc98 100644 --- a/t/syntaxCheck.t +++ b/t/syntaxCheck.t @@ -18,27 +18,55 @@ use WebGUI::Session; use Test::More; use File::Spec; -plan skip_all => 'set TEST_SYNTAX to enable this test' unless $ENV{TEST_SYNTAX}; - -my @modules; my $wgLib = WebGUI::Test->lib; -my $wgRoot = WebGUI::Test->root; -#diag("Checking modules in $wgLib"); -File::Find::find( \&getWebGUIModules, $wgLib, File::Spec->join($wgRoot, 'sbin'), File::Spec->join($wgRoot, 'docs', 'upgrades') ); +my @modules = findModules($wgLib); +my @scripts = findScripts(WebGUI::Test->root . '/docs/upgrades', WebGUI::Test->root . '/sbin'); -my $numTests = scalar @modules; +plan tests => 2 * (scalar @modules + scalar @scripts); -plan tests => $numTests; +foreach my $library (@modules) { + my $warnings = ''; + local $^W = 1; + local $SIG{__WARN__} = sub { + $warnings .= shift; + }; + eval { + require $library; + }; + chomp $warnings; + is($@, '', "$library compiles successfully"); + is($warnings, '', "$library compiles without warnings"); +} -#diag("Planning on $numTests tests"); - -foreach my $package (@modules) { - my $command = "$^X -I$wgLib -wc $package 2>&1"; - my $output = `$command`; - is($?, 0, "syntax check for $package"); +for my $script (@scripts) { + my $cmd = "$^X -wcI'$wgLib' $script 2>&1"; + my $output = `$cmd`; + is($?, 0, "$script compiles successfully"); + chomp $output; + $output =~ s/^\Q$script\E (?:had compilation errors\.|syntax OK)$//m; + is($output, '', "$script compiles without warnings"); } #---------------------------------------- -sub getWebGUIModules { - push( @modules, $File::Find::name ) if /\.p[ml]$/; +sub findModules { + my $libDir = shift; + my @modules; + File::Find::find( { + no_chdir => 1, + wanted => sub { + next 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; +} +