summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2018-10-10 19:35:13 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2018-10-10 19:37:11 +0200
commite917d971d9e6ed3eb28b101157c0d9b16864a888 (patch)
tree33c5139635347f32b42509ddf04e140714f557e3
parent00b3dca5cfa19b314471e877a432cdabb9500935 (diff)
downloadu3-e917d971d9e6ed3eb28b101157c0d9b16864a888.tar.gz
u3-e917d971d9e6ed3eb28b101157c0d9b16864a888.tar.bz2
u3-e917d971d9e6ed3eb28b101157c0d9b16864a888.zip
fix: run stdout error tests only when stdout is mutable
-rw-r--r--configure.ac22
-rw-r--r--tst/rev-test.c12
-rw-r--r--tst/seq-test.c8
-rw-r--r--tst/std-redirects.c16
4 files changed, 58 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index fb26a6c..981908a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,28 @@ AC_SUBST(COVERAGE_LDFLAGS)
###
+# detect whether HAVE_MUTABLE_STDOUT
+#
+
+
+AC_MSG_CHECKING("whether stdout is modifiable")
+AC_TRY_RUN(
+[
+ #include <stdio.h>
+ int main() { FILE *f = NULL; stdout = f; return stdout != NULL; }
+]
+, # if true
+[
+ AC_DEFINE([HAVE_MUTABLE_STDOUT], [1], [stdout is mutable])
+ AC_MSG_RESULT("yes")
+]
+, # if false
+[
+ AC_MSG_RESULT("no")
+])
+
+
+###
# --enable-analyzer
#
diff --git a/tst/rev-test.c b/tst/rev-test.c
index 8c0d1d7..652d285 100644
--- a/tst/rev-test.c
+++ b/tst/rev-test.c
@@ -843,6 +843,8 @@ static void rev_lib_invalid_arg(void)
========================================================================== */
+#if HAVE_MUTABLE_STDOUT
+
static void rev_lib_stdout_error(void)
{
int argc = 2;
@@ -866,11 +868,15 @@ static void rev_lib_stdout_error(void)
mt_fail(strncmp(buf, "e/fputs()", 9) == 0);
}
+#endif /* HAVE_MUTABLE_STDOUT */
+
/* ==========================================================================
========================================================================== */
+#if HAVE_MUTABLE_STDOUT
+
static void rev_lib_stdout_error_no_nl(void)
{
int argc = 2;
@@ -893,6 +899,8 @@ static void rev_lib_stdout_error_no_nl(void)
unlink(REV_TEST_STDOUT);
}
+#endif /* HAVE_MUTABLE_STDOUT */
+
/* ==========================================================================
_
@@ -906,9 +914,13 @@ static void rev_lib_stdout_error_no_nl(void)
int main(void)
{
+#if HAVE_MUTABLE_STDOUT
+
mt_run(rev_lib_stdout_error);
mt_run(rev_lib_stdout_error_no_nl);
+#endif /* HAVE_MUTABLE_STDOUT */
+
mt_prepare_test = &prepare_test;
mt_cleanup_test = &cleanup_test;
diff --git a/tst/seq-test.c b/tst/seq-test.c
index 4b44898..eec9a69 100644
--- a/tst/seq-test.c
+++ b/tst/seq-test.c
@@ -651,6 +651,8 @@ static void seq_print_version(void)
========================================================================== */
+#if HAVE_MUTABLE_STDOUT
+
static void seq_stdout_error(void)
{
int argc = 2;
@@ -670,6 +672,8 @@ static void seq_stdout_error(void)
restore_stderr();
}
+#endif /* HAVE_MUTABLE_STDOUT */
+
/* ==========================================================================
_
@@ -683,8 +687,12 @@ static void seq_stdout_error(void)
int main(void)
{
+#if HAVE_MUTABLE_STDOUT
+
mt_run(seq_stdout_error);
+#endif /* HAVE_MUTABLE_STDOUT */
+
mt_prepare_test = prepare_test;
mt_cleanup_test = cleanup_test;
diff --git a/tst/std-redirects.c b/tst/std-redirects.c
index edd6e1d..bcfdb26 100644
--- a/tst/std-redirects.c
+++ b/tst/std-redirects.c
@@ -13,6 +13,9 @@
========================================================================== */
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
#include <errno.h>
#include <stdio.h>
@@ -32,8 +35,13 @@
========================================================================== */
+#if HAVE_MUTABLE_STDOUT
+
static FILE *stdout_save;
static FILE *stdout_ro;
+
+#endif /* HAVE_MUTABLE_STDOUT */
+
static int fd_stdin = -1;
static int fd_stdout = -1;
static int fd_stderr = -1;
@@ -176,6 +184,8 @@ int stdout_to_file
========================================================================== */
+#if HAVE_MUTABLE_STDOUT
+
int stdout_sabotage
(
const char *file
@@ -204,18 +214,24 @@ int stdout_sabotage
return 0;
}
+#endif /* HAVE_MUTABLE_STDOUT */
+
/* ==========================================================================
Recover stdout from sabotage
========================================================================== */
+#if HAVE_MUTABLE_STDOUT
+
void stdout_recover(void)
{
stdout = stdout_save;
fclose(stdout_ro);
}
+#endif /* HAVE_MUTABLE_STDOUT */
+
/* ==========================================================================
Redirects stderr to file