Merge branch 'master' of github.com:bioperl/bioperl-live
[bioperl-live.git] / t / Variation / Variation_IO.t
blob1e8bc59e822b52e026ad6116bd0095ad1eb856d2
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN { 
7     use lib '.';
8     use Bio::Root::Test;
9     
10     test_begin(-tests => 26,
11                            -requires_modules => ['Text::Wrap 98', 'XML::Writer']);
12         
13         use_ok('Bio::Variation::IO');
16 sub io {
17     my ($t_file, $o_file, $out_format) = @_; 
18     my $res;
19         
20     my ($o_ext) = $out_format eq 'flat' ? 'dat' : 'xml';
21     my ($o_format) = $out_format;
22     my ($t_name) = $t_file =~ /(.*)....$/;
23         
24     my( $before );
25     {
26         local $/ = undef;
27         open my $BEFORE, '<', "$t_name.$o_ext" or die "Could not read file '$t_name.$o_ext': $!\n";
28         $before = <$BEFORE>;
29         close $BEFORE;
30     }
32     ok $before;#"Error in reading input file [$t_name.$o_ext]";
34     my $in = Bio::Variation::IO->new( -file => $t_file);
35     my  @entries ;
36     while (my $e = $in->next) {
37         push @entries, $e;
38     }
39     my $count = scalar @entries;
40     cmp_ok @entries, '>', 0;# "No SeqDiff objects [$count]";
42     my $out = Bio::Variation::IO->new( -FILE => ">$o_file", 
43                                        -FORMAT => $o_format);
44     my $out_ok = 1;
45     foreach my $e (@entries) {
46         $out->write($e) or $out_ok = 0;
47     }
48     undef($out);  # Flush to disk
49     ok $out_ok;#  "error writing variants";
51     my( $after );
52     {
53         local $/ = undef;
54         open my $AFTER, '<', $o_file or die "Could not read file '$o_file': $!\n";
55         $after = <$AFTER>;
56         close $AFTER;
57     }
59     ok $after;# "Error in reading in again the output file [$o_file]";
60     is $before, $after, "test output file compared to input";
61     print STDERR `diff $t_file $o_file` if $before ne $after;
64 io  (test_input_file('mutations.dat'), 
65      test_output_file(), 'flat'); #1..5
66 io  (test_input_file('polymorphism.dat'), 
67      test_output_file(), 'flat'); #6..10
69 SKIP: {
70         test_skip(-tests => 15, -requires_modules => [qw(XML::Twig
71                                                                                                      XML::Writer
72                                                                                                      IO::String)]);
74         eval {
75                 if( $XML::Writer::VERSION >= 0.5 ) { 
76                 io  (test_input_file('mutations.xml'), 
77                          test_output_file(), 'xml'); #10..12
78                 } else { 
79                 io  (test_input_file('mutations.old.xml'), 
80                          test_output_file(), 'xml'); #10..12
81                 }
82         };
83         
84         eval {
85                 if( $XML::Writer::VERSION >= 0.5 ) { 
86                 io  (test_input_file('polymorphism.xml'), 
87                          test_output_file(), 'xml'); #13..14
88                 } else { 
89                 io  (test_input_file('polymorphism.old.xml'), 
90                          test_output_file(), 'xml'); #13..14
91         
92                 }
93         };
94         
95         eval { 
96                 if( $XML::Writer::VERSION >= 0.5 ) { 
97                 io  (test_input_file('mutations.dat'), 
98                          test_output_file(), 'xml'); #15..25
99                 } else { 
100                 io  (test_input_file('mutations.old.dat'), 
101                          test_output_file(), 'xml'); #15..25
102                 }
103         };