Mailing List Archive

svn commit: r169680 - /spamassassin/trunk/t/uri_text.t
Author: felicity
Date: Wed May 11 12:27:59 2005
New Revision: 169680

URL: http://svn.apache.org/viewcvs?rev=169680&view=rev
Log:
change t/uri_text.t to not need temp files, a full SA run, etc. Just use functions to get the uri list and test, etc.

Modified:
spamassassin/trunk/t/uri_text.t

Modified: spamassassin/trunk/t/uri_text.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/uri_text.t?rev=169680&r1=169679&r2=169680&view=diff
==============================================================================
--- spamassassin/trunk/t/uri_text.t (original)
+++ spamassassin/trunk/t/uri_text.t Wed May 11 12:27:59 2005
@@ -21,7 +21,6 @@
use SATest; sa_t_init("uri_text");
use Test;
use Mail::SpamAssassin;
-use IO::File;
use vars qw(%patterns %anti_patterns);

# settings
@@ -33,32 +32,28 @@
$sa->init(0); # parse rules

# load tests and write mail
-my $mail = 'log/uri_text.eml';
%patterns = ();
%anti_patterns = ();
-write_mail();
+my $message = write_mail();

-# test message
-my $fh = IO::File->new_tmpfile();
-open(STDERR, ">&=".fileno($fh)) || die "Cannot reopen STDERR";
-ok(sarun("-t --debug=uri < log/uri_text.eml"));
-seek($fh, 0, 0);
-my $error = do {
- local $/;
- <$fh>;
-};
-$error =~ s/^.*dbg: uri: parsed uri found: //mg;
+my $mail = $sa->parse($message);
+my $msg = Mail::SpamAssassin::PerMsgStatus->new($sa, $mail);
+
+my $uris = join("\n", $msg->get_uri_list(), "");

# run patterns and anti-patterns
my $failures = 0;
for my $pattern (keys %patterns) {
- if ($error !~ /${pattern}/m) {
+ if ($uris !~ /${pattern}/m) {
print "did not find $pattern\n";
$failures++;
}
}
+ok(!$failures);
+$failures = 0;
+
for my $anti_pattern (keys %anti_patterns) {
- if ($error =~ /${anti_pattern}/m) {
+ if ($uris =~ /${anti_pattern}/m) {
print "did find $anti_pattern\n";
$failures++;
}
@@ -67,8 +62,7 @@

# function to write test email
sub write_mail {
- if (open(MAIL, ">$mail")) {
- print MAIL <<'EOF';
+ my $message = <<'EOF';
Message-ID: <clean.1010101@example.com>
Date: Mon, 07 Oct 2002 09:00:00 +0000
From: Sender <sender@example.com>
@@ -79,30 +73,28 @@
Content-Transfer-Encoding: 7bit

EOF
- while (<DATA>) {
- chomp;
- next if /^#/;
- if (/^(.*?)\t+(.*?)\s*$/) {
- my $string = $1;
- my @patterns = split(' ', $2);
- if ($string && @patterns) {
- print MAIL "$string\n";
- for my $pattern (@patterns) {
- if ($pattern =~ /^\!(.*)/) {
- $anti_patterns{$1} = 1;
- }
- else {
- $patterns{$pattern} = 1;
- }
- }
- }
+
+ while (<DATA>) {
+ chomp;
+ next if /^#/;
+ if (/^(.*?)\t+(.*?)\s*$/) {
+ my $string = $1;
+ my @patterns = split(' ', $2);
+ if ($string && @patterns) {
+ $message .= "$string\n";
+ for my $pattern (@patterns) {
+ if ($pattern =~ /^\!(.*)/) {
+ $anti_patterns{$1} = 1;
+ }
+ else {
+ $patterns{$pattern} = 1;
+ }
+ }
}
}
- close(MAIL);
- }
- else {
- die "can't open output file: $!";
}
+
+ return $message;
}

# <line> : <string><tabs><matches>