DebugTest.cpp 951 B

123456789101112131415161718192021222324252627282930313233
  1. //===- llvm/unittest/Support/DebugTest.cpp --------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/Support/Debug.h"
  9. #include "llvm/Support/raw_ostream.h"
  10. #include "gtest/gtest.h"
  11. #include <string>
  12. using namespace llvm;
  13. #ifndef NDEBUG
  14. TEST(DebugTest, Basic) {
  15. std::string s1, s2;
  16. raw_string_ostream os1(s1), os2(s2);
  17. static const char *DT[] = {"A", "B"};
  18. llvm::DebugFlag = true;
  19. setCurrentDebugTypes(DT, 2);
  20. DEBUG_WITH_TYPE("A", os1 << "A");
  21. DEBUG_WITH_TYPE("B", os1 << "B");
  22. EXPECT_EQ("AB", os1.str());
  23. setCurrentDebugType("A");
  24. DEBUG_WITH_TYPE("A", os2 << "A");
  25. DEBUG_WITH_TYPE("B", os2 << "B");
  26. EXPECT_EQ("A", os2.str());
  27. }
  28. #endif