Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
io.t 4.05 KiB
# Copyright [1999-2014] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

################################################ 
#                                              #
# io.t                                         #
#                                              #
# A set of tests to verify various subroutines #
# in the Bio::EnsEMBL::Utils::IO module        #
#                                              #
################################################

use strict;
use warnings;

use Test::More;
use File::Temp;
use Bio::EnsEMBL::Utils::IO qw/:all/;

ok(1, 'Module compiles');

my $tmpdir = File::Temp->newdir();
my $dirname = $tmpdir->dirname;

#
# test working with bzip2 and zip files
#
# create a dummy file
my $tmpfile = File::Temp->new(DIR => $dirname, SUFFIX => '.txt');
my $tmpfilename = $tmpfile->filename;
print $tmpfile "test data\n";
print $tmpfile "some more data.";
$tmpfile->close;

my $BZIP2_OK = 0;
eval {
  require IO::Compress::Bzip2;
  require IO::Uncompress::Bunzip2;
  $BZIP2_OK = 1;
};

SKIP: {
  skip "Cannot run Bzip2/Bunzip2 tests, install related IO::[Un]Compress modules first",
    4 unless $BZIP2_OK;

  # send the content of the tmpfile to another
  # bzip2 compressed file
  my $file_content = slurp($tmpfilename);
  my $bz2tmpfile = File::Temp->new(DIR => $dirname, SUFFIX => '.bz2');

  bz_work_with_file($bz2tmpfile->filename, 'w', sub {
    my ($fh) = @_;
    print $fh $file_content;
    return;
  });

  # check the content of the compressed file
  my $content = bz_slurp($bz2tmpfile->filename);
  like($content, qr/test data/, "Bzip2: correct content");