summaryrefslogtreecommitdiff
path: root/regress/message/basic_io.pl
blob: 87d3fd385e048408033e8ba0f120aeb22f862d3b (plain)
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
#!/usr/bin/env perl
#-*- perl -*-
#
#  Copyright (C) 2001,2002,2004 Ken'ichi Fukamachi
#   All rights reserved. This program is free software; you can
#   redistribute it and/or modify it under the same terms as Perl itself. 
#
# $FML: basic_io.pl,v 1.6 2004/12/08 07:26:15 fukachan Exp $
#

use strict;
use Carp;
use lib qw(../../cpan/lib);
use Mail::Message;

my $debug = $ENV{ debug } ? 1 : 0;

use FML::Test::Utils;
my $tool = new FML::Test::Utils;
$tool->set_title("message basic io test");

my $test_mode = $ENV{'test_mode'} ? 1 : 0;

my $tmp = "/tmp/buf$$";

for my $f (@ARGV) {
    my $fh  = new FileHandle $f;
    my $wh  = new FileHandle "> $tmp";
    my $obj = Mail::Message->parse( { fd => $fh } );

    $wh->autoflush(1);
    $obj->print($wh);
    $wh->close;

    unless ($test_mode) {
	print "\n<< $f\n";
	my $h = $obj->data_type_list;
	for (@$h) { print "  ", $_, "\n";}
	print "\n";
    }

    use IO::Handle;
    my $fd = new IO::Handle;
    my $i  = 0;
    open($fd, "diff -ub $f $tmp|");
    while (<$fd>) {
	$i++;
	if ($debug) {
	    print "      ", $_ if $i > 3;
	}
    }
    close($fd);

    use File::Basename;
    $tool->set_title(basename($f));
    if ($i) {
	$tool->print_error();
    }
    else {
	$tool->print_ok();
    }
}

unlink $tmp;

exit 0;