don't redirect stderr by default in unit tests (in case the sanitizers fire and print stuff)

This commit is contained in:
arvidn 2016-12-31 01:11:27 -05:00 committed by Arvid Norberg
parent 8800cae585
commit 03aa3467f3
1 changed files with 12 additions and 13 deletions

View File

@ -71,7 +71,7 @@ using namespace libtorrent;
int old_stdout = -1;
int old_stderr = -1;
bool redirect_stdout = true;
bool redirect_stderr = true;
bool redirect_stderr = false;
bool keep_files = false;
extern int _g_test_idx;
@ -81,8 +81,10 @@ unit_test_t* current_test = nullptr;
void output_test_log_to_terminal()
{
if (current_test == nullptr || old_stdout == -1 || old_stderr == -1
|| !redirect_stdout || current_test->output == nullptr)
if (current_test == nullptr
|| (old_stdout == -1 && old_stderr == -1)
|| (!redirect_stdout && !redirect_stderr)
|| current_test->output == nullptr)
return;
fflush(stdout);
@ -209,10 +211,7 @@ void print_usage(char const* executable)
"-n,--no-redirect don't redirect test output to\n"
" temporary file, but let it go straight\n"
" to stdout\n"
"--no-stderr-redirect don't redirect stderr, but still redirect\n"
" stdout. This is useful when building with\n"
" sanitizers, which rely on being able to print\n"
" to stderr and exit\n"
"--stderr-redirect also redirect stderr in addition to stdout\n"
"\n"
"for tests, specify one or more test names as printed\n"
"by -l. If no test is specified, all tests are run\n", executable);
@ -247,12 +246,11 @@ EXPORT int main(int argc, char const* argv[])
if (strcmp(argv[0], "-n") == 0 || strcmp(argv[0], "--no-redirect") == 0)
{
redirect_stdout = false;
redirect_stderr = false;
}
if (strcmp(argv[0], "--no-stderr-redirect") == 0)
if (strcmp(argv[0], "--stderr-redirect") == 0)
{
redirect_stderr = false;
redirect_stderr = true;
}
if (strcmp(argv[0], "-k") == 0 || strcmp(argv[0], "--keep") == 0)
@ -361,7 +359,7 @@ EXPORT int main(int argc, char const* argv[])
unit_test_t& t = _g_unit_tests[i];
if (redirect_stdout)
if (redirect_stdout || redirect_stderr)
{
// redirect test output to a temporary file
fflush(stdout);
@ -370,8 +368,9 @@ EXPORT int main(int argc, char const* argv[])
FILE* f = tmpfile();
if (f != nullptr)
{
int ret1 = dup2(fileno(f), fileno(stdout));
if (redirect_stderr) dup2(fileno(f), fileno(stderr));
int ret1 = 0;
if (redirect_stdout) ret1 |= dup2(fileno(f), fileno(stdout));
if (redirect_stderr) ret1 |= dup2(fileno(f), fileno(stderr));
if (ret1 >= 0)
{
t.output = f;