]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Redirect and verify stderr in test_read_append_filter_wrong_program
authorMartin Matuska <martin@matuska.org>
Thu, 13 Oct 2016 10:36:00 +0000 (12:36 +0200)
committerMartin Matuska <martin@matuska.org>
Thu, 13 Oct 2016 11:03:01 +0000 (13:03 +0200)
libarchive/test/test_read_set_format.c

index f9be978351c4a302380f135dd777cba487bd1d74..d333269c2ee9832ce2133e2c7366a248be47e212 100644 (file)
@@ -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");
 }