OSDN Git Service

add binmode and some changes.
[nkf/nkf.git] / test.pl
1 #!/usr/bin/perl
2 #
3 # nkf test program for nkf 2.0
4 #    Shinji KONO <kono@ie.u-ryukyu.ac.jp>
5 # Sun Aug 18 12:25:40 JST 1996
6 # Sun Nov  8 00:16:06 JST 1998
7 # Sun Sep  8 14:04:02 JST 2002
8 #
9 # This is useful when you add new patch on nkf.
10 # Since this test is too strict, faileurs may not mean
11 # wrong conversion. 
12 #
13 # nkf 2.0 utf8
14 # nkf 1.5 differs on MIME decoding
15 # nkf 1.4 passes Basic Conversion tests
16 # nkf PDS version passes Basic Conversion tests  using "nkf -iB -oB "
17 #
18
19 $nkf = 'MSWin32' eq $^O ? ".\\nkf" : "./nkf";
20 # $nkf = "doscmd nkf.exe";
21
22 # If you want to see the testing process, set next flag.
23
24 $detail_all = 0;
25 $error_count=1;
26 $diff=1;
27
28 # &library_test0();
29 sub test {
30     &command_test(@_);
31 }
32
33 sub command_test {
34     local ($nkf,$in,@ans) = @_;
35     local ($result);
36
37     $result = '';
38     open(OUT,"> nkf.in");
39     print OUT $in;
40     close(OUT);
41     system("$nkf <nkf.in >nkf.out");   # easy
42     open(IN,"< nkf.out");
43     while(<IN>) {
44         $result .= $_;
45     }
46
47     if( $nkf =~ /-\S*m/) {
48         $result =~ s/ //g;
49     }
50     $i = 0;
51     foreach $ans (@ans) {
52         if( $nkf =~ /-\S*m/) {
53             $ans =~ s/ //g;
54         }
55         if ($result eq $ans) {
56             print "Ok\n";
57             return $result;
58         }
59         $i++;
60     }
61     $ans = $ans[0];
62     print "Fail\n";
63     system "mv nkf.in nkf.in.$error_count.bad";
64     system "mv nkf.out nkf.out.$error_count.bad";
65     open(OUT,"> nkf.expect.$error_count.bad");
66     print OUT $ans;
67     close(OUT);
68     $error_count++;
69     if ($diff) {
70         open(R,"|od -c >tmp.result.bad"); print R $result; close(R);
71         open(R,"|od -c >tmp.expect.bad"); print R $ans; close(R);
72         system "diff -c tmp.result.bad tmp.expect.bad";
73     }
74     return $result;
75 }
76
77 do "nkf_test.pl";
78
79 unlink "nkf.in";
80 unlink "nkf.out";