Skip to content

Commit

Permalink
Added tests and changes to make the test work.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitwham authored and jkbonfield committed Feb 19, 2024
1 parent d4038e6 commit f19b844
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
31 changes: 20 additions & 11 deletions bgzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,15 @@ int main(int argc, char **argv)
return 1;
}

if (write_fname && pstdout) {
fprintf(stderr, "[bgzip] Cannot write to %s and stdout at the same time.\n", write_fname);
return 1;
if (write_fname) {
if (pstdout) {
fprintf(stderr, "[bgzip] Cannot write to %s and stdout at the same time.\n", write_fname);
return 1;
} else if (strncmp(write_fname, "-", strlen(write_fname)) == 0) {
// stdout has special handling so treat as -c
pstdout = 1;
write_fname = NULL;
}
}

do {
Expand Down Expand Up @@ -713,16 +719,19 @@ int main(int argc, char **argv)
if (bgzf_close(fp) < 0) error("Close failed: Error %d\n",fp->errcode);

if (statfilename) {
//get input file timestamp
if (!getfilespec(argv[optind], &filestat)) {
//set output file timestamp
if (setfilespec(statfilename, &filestat) < 0) {
fprintf(stderr, "[bgzip] Failed to set file specification.\n");
if (!write_fname) {
//get input file timestamp
if (!getfilespec(argv[optind], &filestat)) {
//set output file timestamp
if (setfilespec(statfilename, &filestat) < 0) {
fprintf(stderr, "[bgzip] Failed to set file specification.\n");
}
}
else {
fprintf(stderr, "[bgzip] Failed to get file specification.\n");
}
}
else {
fprintf(stderr, "[bgzip] Failed to get file specification.\n");
}

free(statfilename);
}

Expand Down
32 changes: 31 additions & 1 deletion test/test.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env perl
#
# Copyright (C) 2012-2023 Genome Research Ltd.
# Copyright (C) 2012-2024 Genome Research Ltd.
#
# Author: Petr Danecek <pd3@sanger.ac.uk>
#
Expand Down Expand Up @@ -589,6 +589,36 @@ sub test_bgzip {
return;
}
passed($opts,$test);

# try writing to an explicit file name, round trip test
$test = sprintf('%s %2s threads', 'bgzip --output',
$threads ? $threads : 'no');
print "$test: ";

my $compressed_op = "$$opts{tmp}/arbitrary.$threads.gz";
my $uncompressed_op = "$$opts{tmp}/arbitrary.$threads.txt";

$c = "$$opts{bin}/bgzip $at '$data' -o '$compressed_op'";

($ret, $out) = _cmd($c);
if ($ret) {
failed($opts, $test, "non-zero exit from $c");
return;
}
$c = "$$opts{bin}/bgzip $at -d $compressed_op --output '$uncompressed_op'";

($ret, $out) = _cmd($c);
if ($ret) {
failed($opts, $test, "non-zero exit from $c");
return;
}
$c = "cmp '$data' '$uncompressed_op'";
($ret, $out) = _cmd($c);
if ($ret) {
failed($opts, $test, $out ? $out : "'$data' '$uncompressed_op' differ");
return;
}
passed($opts,$test);
}

my $test_view_failures;
Expand Down

0 comments on commit f19b844

Please sign in to comment.