[BUG] bug 2598
[bioperl-live.git] / t / Variation_IO.t
blob770bfedef630101fa3cec353eedb9d2b965ec90a
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN { 
7     use lib 't/lib';
8     use BioperlTest;
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         local *BEFORE;
28         open(BEFORE, "$t_name.$o_ext") || die "couldn't open $t_name.$o_ext\n";;
29         $before = <BEFORE>;
30         close BEFORE;
31     }
33     ok $before;#"Error in reading input file [$t_name.$o_ext]";
35     my $in = Bio::Variation::IO->new( -file => $t_file);
36     my  @entries ;
37     while (my $e = $in->next) {
38         push @entries, $e;
39     }
40     my $count = scalar @entries;
41     cmp_ok @entries, '>', 0;# "No SeqDiff objects [$count]";
43     my $out = Bio::Variation::IO->new( -FILE => ">$o_file", 
44                                        -FORMAT => $o_format);
45     my $out_ok = 1;
46     foreach my $e (@entries) {
47         $out->write($e) or $out_ok = 0;
48     }
49     undef($out);  # Flush to disk
50     ok $out_ok;#  "error writing variants";
52     my( $after );
53     {
54         local $/ = undef;
55         local *AFTER;
56         open AFTER, $o_file;
57         $after = <AFTER>;
58         close AFTER;
59     }
61     ok $after;# "Error in reading in again the output file [$o_file]";
62     is $before, $after, "test output file compared to input";
63     print STDERR `diff $t_file $o_file` if $before ne $after;
66 io  (test_input_file('mutations.dat'), 
67      test_output_file(), 'flat'); #1..5
68 io  (test_input_file('polymorphism.dat'), 
69      test_output_file(), 'flat'); #6..10
71 SKIP: {
72         test_skip(-tests => 15, -requires_modules => [qw(XML::Twig
73                                                                                                      XML::Writer
74                                                                                                      IO::String)]);
76         eval {
77                 if( $XML::Writer::VERSION >= 0.5 ) { 
78                 io  (test_input_file('mutations.xml'), 
79                          test_output_file(), 'xml'); #10..12
80                 } else { 
81                 io  (test_input_file('mutations.old.xml'), 
82                          test_output_file(), 'xml'); #10..12
83                 }
84         };
85         
86         eval {
87                 if( $XML::Writer::VERSION >= 0.5 ) { 
88                 io  (test_input_file('polymorphism.xml'), 
89                          test_output_file(), 'xml'); #13..14
90                 } else { 
91                 io  (test_input_file('polymorphism.old.xml'), 
92                          test_output_file(), 'xml'); #13..14
93         
94                 }
95         };
96         
97         eval { 
98                 if( $XML::Writer::VERSION >= 0.5 ) { 
99                 io  (test_input_file('mutations.dat'), 
100                          test_output_file(), 'xml'); #15..25
101                 } else { 
102                 io  (test_input_file('mutations.old.dat'), 
103                          test_output_file(), 'xml'); #15..25
104                 }
105         };