summaryrefslogtreecommitdiff
path: root/libarchive
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2016-10-13 12:36:00 +0200
committerMartin Matuska <martin@matuska.org>2016-10-13 13:03:01 +0200
commite3bdbbf3475c3abf264e563c753a20972095665e (patch)
treebeb5f0e35a74ee8433228c9077b9880f3eb822da /libarchive
parentc84e4e245f19fad155a50091784c9456d051cf91 (diff)
downloadlibarchive-e3bdbbf3475c3abf264e563c753a20972095665e.tar.gz
Redirect and verify stderr in test_read_append_filter_wrong_program
Diffstat (limited to 'libarchive')
-rw-r--r--libarchive/test/test_read_set_format.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/libarchive/test/test_read_set_format.c b/libarchive/test/test_read_set_format.c
index f9be9783..d333269c 100644
--- a/libarchive/test/test_read_set_format.c
+++ b/libarchive/test/test_read_set_format.c
@@ -200,6 +200,8 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
{
struct archive_entry *ae;
struct archive *a;
+ int fd;
+ fpos_t pos;
/*
* If we have "bunzip2 -q", try using that.
@@ -208,6 +210,13 @@ DEFINE_TEST(test_read_append_filter_wrong_program)
skipping("Can't run bunzip2 program on this platform");
return;
}
+
+ /* bunzip2 will write to stderr, redirect it to a file */
+ fflush(stderr);
+ fgetpos(stderr, &pos);
+ fd = dup(fileno(stderr));
+ freopen("stderr1", "w", stderr);
+
assert((a = archive_read_new()) != NULL);
assertA(0 == archive_read_set_format(a, ARCHIVE_FORMAT_TAR));
assertEqualIntA(a, ARCHIVE_OK,
@@ -217,4 +226,13 @@ 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));
+
+ /* restore stderr */
+ fflush(stderr);
+ dup2(fd, fileno(stderr));
+ close(fd);
+ clearerr(stderr);
+ fsetpos(stderr, &pos);
+
+ assertTextFileContents("bunzip2: (stdin) is not a bzip2 file.\n", "stderr1");
}