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 | |
9 | #include "llvm/Support/Debug.h" |
10 | #include "llvm/Support/raw_ostream.h" |
11 | #include "gtest/gtest.h" |
12 | |
13 | #include <string> |
14 | using namespace llvm; |
15 | |
16 | #ifndef NDEBUG |
17 | TEST(DebugTest, Basic) { |
18 | std::string s1, s2; |
19 | raw_string_ostream os1(s1), os2(s2); |
20 | static const char *DT[] = {"A" , "B" }; |
21 | |
22 | llvm::DebugFlag = true; |
23 | setCurrentDebugTypes(Types: DT, Count: 2); |
24 | DEBUG_WITH_TYPE("A" , os1 << "A" ); |
25 | DEBUG_WITH_TYPE("B" , os1 << "B" ); |
26 | EXPECT_EQ("AB" , os1.str()); |
27 | |
28 | setCurrentDebugType("A" ); |
29 | DEBUG_WITH_TYPE("A" , os2 << "A" ); |
30 | DEBUG_WITH_TYPE("B" , os2 << "B" ); |
31 | EXPECT_EQ("A" , os2.str()); |
32 | } |
33 | #endif |
34 | |