Cleanup, fix tests, add script
Script will process all files (recursively) from PWD and write output to './output'
This commit is contained in:
parent
f5b68b2b9a
commit
0aa3153879
|
@ -0,0 +1,93 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use 5.006;
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
#if ( $^O eq 'MSWin32' ) {
|
||||
#die "AnyEvent::Sway cannot be used on win32 (unix sockets are missing)";
|
||||
#}
|
||||
|
||||
my %meta = (
|
||||
name => 'Mail-SpamAssassin-KeywordRuleGenerator',
|
||||
author => 'John Mertz, C<< <git at john.me.tz> >>',
|
||||
license => ['apache_2_0'],
|
||||
'meta-spec' => { version => 2 },
|
||||
resources => {
|
||||
repository => {
|
||||
url => 'git://git.john.me.tz:233/jpm/Mail-SpamAssassin-KeywordRuleGenerator',
|
||||
web => 'https://git.john.me.tz/jpm/Mail-SpamAssassin-KeywordRuleGenerator',
|
||||
type => 'git',
|
||||
},
|
||||
bugtracker => {
|
||||
web => 'https://git.john.me.tz/jpm/Mail-SpamAssassin-KeywordRuleGenerator/issues',
|
||||
},
|
||||
homepage => 'https://john.me.tz/projects/article.php?topic=Mail-SpamAssassin-KeywordRuleGenerator',
|
||||
license => ['https://www.apache.org/licenses/LICENSE-2.0.html'],
|
||||
},
|
||||
);
|
||||
|
||||
my %requirements = (
|
||||
configure_requires => {
|
||||
'ExtUtils::MakeMaker' => 6.36,
|
||||
},
|
||||
build_requires => {
|
||||
'ExtUtils::MakeMaker' => 6.36
|
||||
},
|
||||
runtime_requires => {
|
||||
'Mail::SpamAssassin' => 0,
|
||||
},
|
||||
test_requires => {
|
||||
'Test::More' => 0.80,
|
||||
},
|
||||
);
|
||||
|
||||
my %merged_requirements = (
|
||||
'Mail::SpamAssassin' => 0,
|
||||
'Test::More' => 0.80,
|
||||
);
|
||||
|
||||
$meta{prereqs}{configure}{requires} = $requirements{configure_requires};
|
||||
$meta{prereqs}{build}{requires} = $requirements{build_requires};
|
||||
$meta{prereqs}{runtime}{requires} = $requirements{runtime_requires};
|
||||
$meta{prereqs}{test}{requires} = $requirements{test_requires};
|
||||
|
||||
my %MM_Args = (
|
||||
AUTHOR => 'John Mertz',
|
||||
NAME => 'Mail::SpamAssassin::KeywordRuleGenerator',
|
||||
DISTNAME => 'Mail-SpamAssassin-KeywordRuleGenerator',
|
||||
EXE_FILES => [],
|
||||
MIN_PERL_VERSION => '5.006',
|
||||
VERSION_FROM => 'lib/Mail/SpamAssassin/KeywordRuleGenerator.pm',
|
||||
ABSTRACT_FROM => 'lib/Mail/SpamAssassin/KeywordRuleGenerator.pm',
|
||||
test => {
|
||||
TESTS => 't/*.t',
|
||||
},
|
||||
);
|
||||
|
||||
sub is_eumm {
|
||||
eval { ExtUtils::MakeMaker->VERSION( $_[0] ) };
|
||||
}
|
||||
|
||||
is_eumm(6.30) and $MM_Args{LICENSE} = $meta{license}[0];
|
||||
is_eumm(6.47_01) or delete $MM_Args{MIN_PERL_VERSION};
|
||||
is_eumm(6.52)
|
||||
and $MM_Args{CONFIGURE_REQUIRES} = $requirements{configure_requires};
|
||||
|
||||
is_eumm(6.57_02) and !is_eumm(6.57_07) and $MM_Args{NO_MYMETA} = 1;
|
||||
|
||||
if ( is_eumm(6.63_03) ) {
|
||||
%MM_Args = (
|
||||
%MM_Args,
|
||||
TEST_REQUIRES => $requirements{test_requires},
|
||||
BUILD_REQUIRES => $requirements{build_requires},
|
||||
PREREQ_PM => $requirements{runtime_requires},
|
||||
);
|
||||
}
|
||||
else {
|
||||
$MM_Args{PREREQ_PM} = \%merged_requirements;
|
||||
}
|
||||
unless ( -f 'META.yml' ) {
|
||||
$MM_Args{META_ADD} = \%meta;
|
||||
}
|
||||
WriteMakefile(%MM_Args);
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
# Create a directory called 'output' with generated files for all config files in the $PWD
|
||||
|
||||
use lib '../lib/';
|
||||
use Mail::SpamAssassin::KeywordRuleGenerator;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $id = 'MC';
|
||||
my $dir = 'output';
|
||||
|
||||
# setup
|
||||
my $kw = Mail::SpamAssassin::KeywordRuleGenerator->new( { 'id' =>$id, 'debug' => 0, 'joinScores' => 0 , 'dir' => $dir } );
|
||||
|
||||
# clean
|
||||
unlink(glob("$dir/*"));
|
||||
rmdir($dir);
|
||||
|
||||
# get files in PWD
|
||||
my @files = glob("./*");
|
||||
my @clean;
|
||||
|
||||
$kw->createDir($dir);
|
||||
|
||||
my @failed = $kw->readAll( @files );
|
||||
die scalar(@failed)." error(s) - ".join(', ', @failed)."\n" if (scalar(@failed));
|
||||
$kw->writeAll();
|
||||
|
||||
use Mail::SpamAssassin;
|
||||
my $sa = Mail::SpamAssassin->new( { 'site_rules_filename' => "./$dir", 'pre_config_text' => "loadplugin Mail::SpamAssassin::Plugin::Check" } );
|
||||
my $fail = $sa->lint_rules();
|
||||
die "Failed to verify with SpamAssassin: $fail" if ($fail);
|
File diff suppressed because it is too large
Load Diff
|
@ -16,7 +16,7 @@ my $defaults = {
|
|||
};
|
||||
|
||||
my $args = {
|
||||
'id' => '01',
|
||||
'id' => 'TEST',
|
||||
'priority' => 10,
|
||||
'debug' => 1,
|
||||
'singleOutfile' => 1,
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
/home/jpm/KeywordRuleGenerator/t/02_files.cf
|
|
@ -0,0 +1 @@
|
|||
word
|
12
t/02_files.t
12
t/02_files.t
|
@ -18,26 +18,26 @@ ok ($kw->getFile($file) == $file, "Get current working file");
|
|||
ok (scalar(keys(%{$kw->{'rules'}})) == 2, "Fetched correct number of files in rules");
|
||||
ok ($kw->{'rules'}->{$file}, "Loaded correct hash key");
|
||||
ok ($kw->{'filemap'}->{$file} =~ m/50_02_T_02_FILES.cf$/, "Loaded correct output name");
|
||||
ok (!$kw->clearFiles(), "Clear 'rules' hash");
|
||||
ok (!$kw->{'rules'}, "Fetched none after clearing");
|
||||
ok (!$kw->clearAll(), "Clear 'rules' hash");
|
||||
ok (!scalar(keys(%{$kw->{'rules'}})), "Fetched none after clearing");
|
||||
|
||||
# Read a directory
|
||||
my $dir = 't/02_files.dir';
|
||||
ok (!$kw->readAll($dir), "Run file on dir");
|
||||
ok (scalar(keys(%{$kw->{'rules'}})) == 3, "Fetched correct number of files from dir");
|
||||
ok (!$kw->clearFiles(), "Clear dir files");
|
||||
ok (!$kw->clearAll(), "Clear dir files");
|
||||
|
||||
# Read a symlink
|
||||
my $link = 't/02_files.lnk';
|
||||
ok (!$kw->readAll($link), "Run file on link");
|
||||
ok ($kw->getFile() == $file, "Fetched correct name ($file) from link ($link)");
|
||||
ok (scalar(keys(%{$kw->{'rules'}})) == 2, "Fetched correct number of files from link");
|
||||
ok (!$kw->clearFiles(), "Clear link files");
|
||||
ok (!$kw->clearAll(), "Clear link files");
|
||||
|
||||
# Read multiple mixed
|
||||
ok (!$kw->readAll($file, $dir, $link), "Run readAll on multiple/mixed");
|
||||
ok (scalar(keys(%{$kw->{'rules'}})) == 4, "Fetched correct number of files from all");
|
||||
ok (!$kw->clearFiles(), "Clear dir files");
|
||||
ok (scalar(keys(%{$kw->{'rules'}})) == 5, "Fetched correct number of files from all");
|
||||
ok (!$kw->clearAll(), "Clear dir files");
|
||||
|
||||
|
||||
ok ($kw->readFile('does_not_exist'), "Correctly failed for non-existent file");
|
||||
|
|
|
@ -17,7 +17,6 @@ ok(!scalar(@failed), "Load 'rules' hash with readAll");
|
|||
|
||||
my $expected = getExpected();
|
||||
my ( $missing, $extra, $incorrect ) = 0;
|
||||
use Data::Dump;
|
||||
foreach my $file (keys(%{$expected})) {
|
||||
if ($file eq 'GLOBAL') {
|
||||
my ($m, $e) = compareValues(
|
||||
|
|
|
@ -46,10 +46,8 @@ foreach (@files) {
|
|||
}
|
||||
ok (!scalar(keys(%remaining)), "All expected output files found");
|
||||
|
||||
use Mail::SpamAssassin;
|
||||
my $sa = Mail::SpamAssassin->new( { 'site_rules_filename' => $testdir } );
|
||||
$failed = $sa->lint_rules();
|
||||
ok (!$failed, "Verified by spamassassin".($res ? "\n$failed" : ""));
|
||||
$failed = $kw->verifyOutput();
|
||||
ok (!$failed, "Verified by spamassassin".($failed ? "\n$failed" : ""));
|
||||
|
||||
$kw->cleanDir();
|
||||
|
||||
|
|
Loading…
Reference in New Issue