Skip to content

Commit

Permalink
Silence stderr in test_read_append_filter_program
Browse files Browse the repository at this point in the history
When the FreeBSD testsuite runs the libarchive tests it checks that stderr
is empty. Since #1382 this is no longer the case. This change restores
the behaviour of silencing bunzip2 stderr but doesn't bring back the
output text check.

Partially reverts 2e7aa5d
  • Loading branch information
arichardson committed Mar 10, 2021
1 parent bc2e773 commit a1b7bf8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libarchive/test/test_read_set_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
{
struct archive_entry *ae;
struct archive *a;
#if !defined(_WIN32) || defined(__CYGWIN__)
FILE * fp;
int fd;
fpos_t pos;
#endif

/*
* If we have "bunzip2 -q", try using that.
Expand All @@ -210,6 +215,14 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
return;
}

#if !defined(_WIN32) || defined(__CYGWIN__)
/* bunzip2 will write to stderr, redirect it to a file */
fflush(stderr);
fgetpos(stderr, &pos);
assert((fd = dup(fileno(stderr))) != -1);
fp = freopen("stderr1", "w", stderr);
#endif

assert((a = archive_read_new()) != NULL);
assertA(0 == archive_read_set_format(a, ARCHIVE_FORMAT_TAR));
assertEqualIntA(a, ARCHIVE_OK,
Expand All @@ -219,4 +232,15 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
assertA(archive_read_next_header(a, &ae) < (ARCHIVE_WARN));
assertEqualIntA(a, ARCHIVE_WARN, archive_read_close(a));
assertEqualInt(ARCHIVE_OK, archive_read_free(a));

#if !defined(_WIN32) || defined(__CYGWIN__)
/* restore stderr */
if (fp != NULL) {
fflush(stderr);
dup2(fd, fileno(stderr));
clearerr(stderr);
(void)fsetpos(stderr, &pos);
}
close(fd);
#endif
}

0 comments on commit a1b7bf8

Please sign in to comment.