1 //===- llvm/unittest/Support/DebugTest.cpp --------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/Support/Debug.h" 11 #include "llvm/Support/raw_ostream.h" 12 #include "gtest/gtest.h" 13 14 #include <string> 15 using namespace llvm; 16 17 #ifndef NDEBUG 18 TEST(DebugTest, Basic) { 19 std::string s1, s2; 20 raw_string_ostream os1(s1), os2(s2); 21 static const char *DT[] = {"A", "B"}; 22 23 llvm::DebugFlag = true; 24 setCurrentDebugTypes(DT, 2); 25 DEBUG_WITH_TYPE("A", os1 << "A"); 26 DEBUG_WITH_TYPE("B", os1 << "B"); 27 EXPECT_EQ("AB", os1.str()); 28 29 setCurrentDebugType("A"); 30 DEBUG_WITH_TYPE("A", os2 << "A"); 31 DEBUG_WITH_TYPE("B", os2 << "B"); 32 EXPECT_EQ("A", os2.str()); 33 } 34 #endif 35