-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pl
133 lines (122 loc) · 2.95 KB
/
test.pl
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
126
127
128
129
130
131
132
133
#!/usr/bin/perl
#
# nkf test program for nkf 2.0
# Shinji KONO <kono@ie.u-ryukyu.ac.jp>
# Sun Aug 18 12:25:40 JST 1996
# Sun Nov 8 00:16:06 JST 1998
# Sun Sep 8 14:04:02 JST 2002
#
# This is useful when you add new patch on nkf.
# Since this test is too strict, faileurs may not mean
# wrong conversion.
#
# nkf 2.0 utf8
# nkf 1.5 differs on MIME decoding
# nkf 1.4 passes Basic Conversion tests
# nkf PDS version passes Basic Conversion tests using "nkf -iB -oB "
#
if ($ARGV[0]) {
$nkf = $ARGV[0];
} else {
$nkf = 'MSWin32' eq $^O ? ".\\nkf" : "./nkf";
}
# $nkf = "doscmd nkf.exe";
# If you want to see the testing process, set next flag.
$error_count = 0;
$diff=1;
# &library_test0();
sub test {
&command_test(@_);
}
sub command_test {
local ($nkf,$in,@ans) = @_;
local ($result);
$result = '';
open(OUT,"> nkf.in");
binmode OUT;
print OUT $in;
close(OUT);
system("$nkf <nkf.in >nkf.out"); # easy
open(IN,"< nkf.out");
binmode IN;
while(<IN>) {
$result .= $_;
}
$result =~ s/ //g if $nkf =~ /-\w+m[NS]/o;
foreach $ans (@ans) {
$ans =~ s/ //g if $nkf =~ /-\w+m[NS]/o;
if ($result eq $ans) {
print "Ok\n";
return $result;
}
}
$ans = $ans[0];
print "Fail\n";
system "mv nkf.in nkf.in.$error_count.bad";
system "mv nkf.out nkf.out.$error_count.bad";
open(OUT,"> nkf.expect.$error_count.bad");
binmode OUT;
print OUT $ans;
close(OUT);
$error_count++;
if ($diff) {
open(R,"|od -c >tmp.result.bad"); binmode R; print R $result; close(R);
open(R,"|od -c >tmp.expect.bad"); binmode R; print R $ans; close(R);
system "diff -c tmp.result.bad tmp.expect.bad";
}
return $result;
}
sub command_tests {
my @tests = @_;
my ($in, $out, $ans);
for (my $i = 0; $i <= $#tests; $i += 3){
my $nkf = $tests[$i];
$in = $tests[$i+1];
$ans = $tests[$i+2];
$out = '';
open(OUT, "> nkf.in");
binmode OUT;
print OUT $in;
close(OUT);
system("$nkf <nkf.in >nkf.out"); # easy
open(IN,"< nkf.out");
binmode IN;
while (<IN>) {
$out .= $_;
}
close(IN);
$out =~ s/ //g if $nkf =~ /-\w+m[NS]/o;
$ans =~ s/ //g if $nkf =~ /-\w+m[NS]/o;
if ($out ne $ans) {
last;
}
}
if ($out eq $ans) {
print "Ok\n";
return;
}
print "Fail\n";
system "mv nkf.in nkf.in.$error_count.bad";
system "mv nkf.out nkf.out.$error_count.bad";
open(OUT,"> nkf.expect.$error_count.bad");
binmode OUT;
print OUT $ans;
close(OUT);
$error_count++;
if ($diff) {
open(R,"|od -c >tmp.result.bad"); binmode R; print R $out; close(R);
open(R,"|od -c >tmp.expect.bad"); binmode R; print R $ans; close(R);
system "diff -c tmp.result.bad tmp.expect.bad";
}
return;
}
do "./nkf_test.pl";
unlink "nkf.in";
unlink "nkf.out";
if ($error_count > 1) {
printf("%d errors were found.\n", $error_count);
} elsif ($error_count == 1) {
printf("1 error was found.\n");
} else {
printf("All tests are succeeded.\n");
}