Index: t/sa_compile.t =================================================================== --- t/sa_compile.t (revision 0) +++ t/sa_compile.t (revision 0) @@ -0,0 +1,104 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +$ENV{'TEST_PERL_TAINT'} = 'no'; # inhibit for this test +use SATest; sa_t_init("sa_compile"); + +use Test; plan tests => 5; + +BEGIN { + if (-e 't/test_dir') { + chdir 't'; + } + + if (-e 'test_dir') { + unshift(@INC, '../blib/lib'); + } +}; + +# ------------------------------------------------------------------- + +my $INST_FROM_SCRATCH = 1; # set to 0 to short-circuit + +use Cwd; +my $cwd = getcwd; +my $builddir = "$cwd/log/d.$testname/build"; +my $instbase = "$cwd/log/d.$testname/inst"; +$INST_FROM_SCRATCH and system("rm -rf $instbase $builddir"); +$INST_FROM_SCRATCH and system("mkdir -p $instbase $builddir"); + +sub system_or_die; +$INST_FROM_SCRATCH and system_or_die "cd .. && make tardist"; +$INST_FROM_SCRATCH and system_or_die "cd $builddir && gunzip -cd $cwd/../Mail-SpamAssassin-*.tar.gz | tar xf -"; +$INST_FROM_SCRATCH and system_or_die "cd $builddir && mv Mail-SpamAssassin-* x"; + +sub new_instdir { + $instdir = $instbase.".".(shift); + print "\nsetting new instdir: $instdir\n"; + $INST_FROM_SCRATCH and system("rm -rf $instdir; mkdir $instdir"); +} + +sub run_makefile_pl { + my $args = $_[0]; + system_or_die "cd $builddir/x && $perl_cmd Makefile.PL ". + "$args < /dev/null 2>&1"; + system_or_die "cd $builddir/x && make install 2>&1"; + print "current instdir: $instdir\n"; +} + +sub set_rules { + my $rules = shift; + open RULES, ">$instdir/foo/share/spamassassin/20_testrules.cf" + or die "cannot write $instdir/foo/share/spamassassin/20_testrules.cf"; + print RULES qq{ + + use_bayes 0 + loadplugin Mail::SpamAssassin::Plugin::Check + loadplugin Mail::SpamAssassin::Plugin::Rule2XSBody + + $rules + + }; + close RULES or die; +} + +# ------------------------------------------------------------------- +new_instdir(__LINE__); +$INST_FROM_SCRATCH and run_makefile_pl "PREFIX=$instdir/foo"; + +# we now have an "installed" version we can run sa-compile with. Ensure +# sarun() will use it appropriately +$scr = "$instdir/foo/bin/spamassassin"; +$scr_cf_args = ""; # use the default rules dir, from our "install" + +set_rules q{ + + body FOO /You have been selected to receive/ + +}; + +# ensure we don't use compiled rules +system("rm -rf $instdir/foo/var/spamassassin/compiled"); +%patterns = ( + + q{ check: tests=FOO }, 'FOO' + +); +ok sarun ("-D -Lt < $cwd/data/spam/001 2>&1", \&patterns_run_cb); +ok_all_patterns(); +clear_pattern_counters(); + +# ------------------------------------------------------------------- + +system_or_die "$instdir/foo/bin/sa-compile --debug --keep-tmps"; +%patterns = ( + + q{ able to use 1/1 'body_0' compiled rules }, 'able-to-use', + q{ check: tests=FOO }, 'FOO' + +); +ok sarun ("-D -Lt < $cwd/data/spam/001 2>&1", \&patterns_run_cb); +ok_all_patterns(); + +# ------------------------------------------------------------------- +