Skip to content

Commit 2feb137

Browse files
committed
Refactor the syntax checker
1 parent d53a787 commit 2feb137

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

t/100-syntax.t

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
#!/usr/bin/perl -w
22
#
3-
# Copyright (C) 2010, Nick Andrew <nick@nick-andrew.net>
4-
# Licensed under the terms of the GNU General Public License, Version 3
3+
# Copyright (C) 2014, Nick Andrew <nick@nick-andrew.net>
4+
# Licensed under the terms of the GNU General Public License, Version 3
55
#
6-
# Syntax-check all modules and scripts
6+
# Syntax-check all modules, scripts and test scripts
7+
8+
use strict;
9+
use warnings;
710

811
use Test::More qw(no_plan);
912

10-
checkDir('lib');
11-
checkDir('bin');
12-
checkDir('scripts');
13+
test_dir('bin');
14+
test_dir('lib');
15+
test_dir('perllib');
16+
test_dir('scripts');
17+
test_dir('t');
1318

1419
exit(0);
1520

16-
sub checkDir {
21+
sub test_dir {
1722
my ($dir) = @_;
1823

1924
if (! -d $dir) {
@@ -30,26 +35,33 @@ sub checkDir {
3035
foreach my $f (@files) {
3136
my $path = "$dir/$f";
3237

33-
if (-f $path && $f =~ /\.(pl|pm|t)$/) {
34-
open(P, "perl -Mstrict -wc $path 2>&1 |");
35-
my $lines;
36-
while (<P>) {
37-
$lines .= $_;
38-
}
39-
if (! close(P)) {
40-
warn "Error closing pipe from perl syntax check $path";
41-
}
42-
my $rc = $?;
43-
44-
if ($rc) {
45-
diag($lines);
46-
fail("$path failed - code $rc");
47-
} else {
48-
pass($path);
49-
}
38+
if (-d $path) {
39+
test_dir($path);
5040
}
51-
elsif (-d $path) {
52-
checkDir($path);
41+
elsif (-f $path && $f =~ /\.(pl|pm|t)$/) {
42+
test_file($path);
5343
}
5444
}
5545
}
46+
47+
sub test_file {
48+
my ($path) = @_;
49+
50+
open(P, "perl -Mstrict -wc $path 2>&1 |");
51+
my $lines;
52+
53+
while (<P>) {
54+
$lines .= $_;
55+
}
56+
57+
close(P);
58+
59+
my $rc = $?;
60+
61+
if ($rc) {
62+
diag($lines);
63+
fail("$path failed - code $rc");
64+
} else {
65+
pass($path);
66+
}
67+
}

0 commit comments

Comments
 (0)