[llvm] Add thread-local overrides for `llvm::errs()` and `llvm::outs()`. (PR #90374)

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 01:08:56 PDT 2024


================
@@ -64,4 +64,32 @@ TEST(raw_fd_streamTest, DynCast) {
   }
 }
 
+TEST(raw_fd_streamTest, OverrideOutsAndErrs) {
+  SmallString<64> Path;
+  int FD;
+  ASSERT_FALSE(sys::fs::createTemporaryFile("foo", "bar", FD, Path));
+  FileRemover Cleanup(Path);
+  std::error_code EC;
+  raw_fd_stream OS(Path, EC);
+  ASSERT_TRUE(!EC);
+
+  ScopedOutsAndErrsOverride Overrides(&OS, &OS);
----------------
chandlerc wrote:

Good call. Also added tests for the crash recovery context and such.

Sadly, testing the null-override requires reaching into GoogleTest magic to test stderr and stout, but this is pretty widely done by GoogleTest users already, so doing it here doesn't seem all that bad.

https://github.com/llvm/llvm-project/pull/90374


More information about the llvm-commits mailing list