-
Notifications
You must be signed in to change notification settings - Fork 70
/
strip2.t
executable file
·126 lines (108 loc) · 2.9 KB
/
strip2.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/perl -T
use lib '.'; use lib 't';
use SATest; sa_t_init("strip2");
use Test::More;
plan skip_all => 'Long running tests disabled' if conf_bool('run_long_tests');
plan tests => 98;
# ---------------------------------------------------------------------------
use File::Copy;
use File::Compare qw(compare_text);
my @files = qw(
data/nice/crlf-endings
data/nice/no_body
data/spam/002
data/spam/004
data/spam/011
data/spam/badmime2.txt
data/spam/015
data/spam/016
data/spam/017
);
my $input;
# Make sure all the files can do "report_safe 0" and "report_safe 1"
foreach $input (@files) {
tstprefs ("
$default_cf_lines
report_safe 0
body TEST_ALWAYS /./
score TEST_ALWAYS 100
");
# create report_safe 0 output
my $test_number = test_number();
my $d_input = "log/d.$testname/$test_number";
unlink $d_input;
ok sarun ("-L < $input");
# test for existence; compare_text() will _create_ files! wtf
ok (-f $d_input);
{
print "output: $d_input\n";
$test_number = test_number();
my $d_output = "log/d.$testname/$test_number";
unlink $d_output;
ok sarun ("-d < $d_input");
ok (-f $d_output);
ok(!compare_text($input,$d_output))
or diffwarn( $input, $d_output );
}
tstprefs ("
$default_cf_lines
report_safe 1
body TEST_ALWAYS /./
score TEST_ALWAYS 100
");
# create report_safe 1 and -t output
$test_number = test_number();
$d_input = "log/d.$testname/$test_number";
unlink $d_input;
ok sarun ("-L -t < $input");
ok (-f $d_input);
{
print "output: $d_input\n";
$test_number = test_number();
my $d_output = "log/d.$testname/$test_number";
unlink $d_output;
ok sarun ("-d < $d_input");
ok (-f $d_output);
ok(!compare_text($input,$d_output))
or diffwarn( $input, $d_output );
}
}
# "report_safe 2" will work if "report_safe 1" works.
# normal mode should always work, do not test multiple files.
$input = $files[0];
tstprefs ("
$default_cf_lines
report_safe 2
body TEST_ALWAYS /./
score TEST_ALWAYS 100
");
# create report_safe 2 output
my $test_number = test_number();
$d_input = "log/d.$testname/$test_number";
unlink $d_input;
ok sarun ("-L < $input");
ok (-f $d_input);
{
print "output: $d_input\n";
$test_number = test_number();
my $d_output = "log/d.$testname/$test_number";
unlink $d_output;
ok sarun ("-d < $d_input");
ok (-f $d_output);
ok(!compare_text($input,$d_output))
or diffwarn( $input, $d_output );
}
# Work directly on regular message, as though it was not spam
$test_number = test_number();
my $d_output = "log/d.$testname/$test_number";
unlink $d_output;
ok sarun ("-d < $input");
ok (-f $d_output);
ok(!compare_text($input,$d_output))
or diffwarn( $input, $d_output );
sub diffwarn {
my ($f1, $f2) = @_;
print "# Diff is as follows:\n";
untaint_system "diff -u $f1 $f2";
print "\n\n";
}