[libcxx-commits] [libcxx] a037059 - [libc++] Decouple debug mode tests from iostreams
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 20 12:48:52 PDT 2020
Author: Louis Dionne
Date: 2020-10-20T15:48:42-04:00
New Revision: a0370595777e856653145e18f0c71c4cf9318b18
URL: https://github.com/llvm/llvm-project/commit/a0370595777e856653145e18f0c71c4cf9318b18
DIFF: https://github.com/llvm/llvm-project/commit/a0370595777e856653145e18f0c71c4cf9318b18.diff
LOG: [libc++] Decouple debug mode tests from iostreams
Added:
Modified:
libcxx/test/libcxx/debug/debug_helper_test.pass.cpp
libcxx/test/support/debug_mode_helper.h
Removed:
################################################################################
diff --git a/libcxx/test/libcxx/debug/debug_helper_test.pass.cpp b/libcxx/test/libcxx/debug/debug_helper_test.pass.cpp
index f6153b204e69..37b70b08ca00 100644
--- a/libcxx/test/libcxx/debug/debug_helper_test.pass.cpp
+++ b/libcxx/test/libcxx/debug/debug_helper_test.pass.cpp
@@ -14,23 +14,23 @@
// UNSUPPORTED: libcxx-no-debug-mode
#include <__debug>
-#include "test_macros.h"
#include "debug_mode_helper.h"
+#include <cstdio>
+#include "test_macros.h"
+
template <class Func>
inline bool TestDeathTest(const char* stmt, Func&& func, DeathTest::ResultKind ExpectResult, DebugInfoMatcher Matcher = AnyMatcher) {
DeathTest DT(Matcher);
DeathTest::ResultKind RK = DT.Run(func);
auto OnFailure = [&](std::string msg) {
- std::cerr << "EXPECT_DEATH( " << stmt << " ) failed! (" << msg << ")\n\n";
+ std::fprintf(stderr, "EXPECT_DEATH( %s ) failed! (%s)\n\n", stmt, msg.c_str());
if (!DT.getChildStdErr().empty()) {
- std::cerr << "---------- standard err ----------\n";
- std::cerr << DT.getChildStdErr() << "\n";
+ std::fprintf(stderr, "---------- standard err ----------\n%s\n", DT.getChildStdErr().c_str());
}
if (!DT.getChildStdOut().empty()) {
- std::cerr << "---------- standard out ----------\n";
- std::cerr << DT.getChildStdOut() << "\n";
+ std::fprintf(stderr, "---------- standard out ----------\n%s\n", DT.getChildStdOut().c_str());
}
return false;
};
diff --git a/libcxx/test/support/debug_mode_helper.h b/libcxx/test/support/debug_mode_helper.h
index 4b6e765a1404..a5b210d8edb5 100644
--- a/libcxx/test/support/debug_mode_helper.h
+++ b/libcxx/test/support/debug_mode_helper.h
@@ -19,13 +19,13 @@
#endif
#include <__debug>
-#include <utility>
+#include <cassert>
#include <cstddef>
+#include <cstdio>
#include <cstdlib>
-#include <cassert>
+#include <string>
#include <string_view>
-#include <sstream>
-#include <iostream>
+#include <utility>
#include <unistd.h>
#include <sys/wait.h>
@@ -53,19 +53,15 @@ struct DebugInfoMatcher {
return true;
// Write to stdout because that's the file descriptor captured by the parent
// process.
- std::cout << "Failed to match debug info!\n"
- << ToString() << "\n"
- << "VS\n"
- << got.what() << "\n";
- return false;
- }
+ std::printf("Failed to match debug info!\n%s\nVS\n%s\n", ToString().data(), got.what().data());
+ return false;
+ }
std::string ToString() const {
- std::stringstream ss;
- ss << "msg = \"" << msg << "\"\n"
- << "line = " << (line == any_line ? "'*'" : std::to_string(line)) << "\n"
- << "file = " << (file == any_file ? "'*'" : any_file) << "";
- return ss.str();
+ std::string result = "msg = \""; result += msg; result += "\"\n";
+ result += "line = " + (line == any_line ? "'*'" : std::to_string(line)) + "\n";
+ result += "file = " + (file == any_file ? "'*'" : std::string(any_file));
+ return result;
}
bool empty() const { return is_empty; }
@@ -260,17 +256,15 @@ inline bool ExpectDeath(const char* stmt, Func&& func, DebugInfoMatcher Matcher)
DeathTest DT(Matcher);
DeathTest::ResultKind RK = DT.Run(func);
auto OnFailure = [&](const char* msg) {
- std::cerr << "EXPECT_DEATH( " << stmt << " ) failed! (" << msg << ")\n\n";
+ std::fprintf(stderr, "EXPECT_DEATH( %s ) failed! (%s)\n\n", stmt, msg);
if (RK != DeathTest::RK_Unknown) {
- std::cerr << "child exit code: " << DT.getChildExitCode() << "\n";
+ std::fprintf(stderr, "child exit code: %d\n", DT.getChildExitCode());
}
if (!DT.getChildStdErr().empty()) {
- std::cerr << "---------- standard err ----------\n";
- std::cerr << DT.getChildStdErr() << "\n";
+ std::fprintf(stderr, "---------- standard err ----------\n%s\n", DT.getChildStdErr().c_str());
}
if (!DT.getChildStdOut().empty()) {
- std::cerr << "---------- standard out ----------\n";
- std::cerr << DT.getChildStdOut() << "\n";
+ std::fprintf(stderr, "---------- standard out ----------\n%s\n", DT.getChildStdOut().c_str());
}
return false;
};
More information about the libcxx-commits
mailing list