Eugene Leviant | c089e40 | 2016-12-27 09:31:20 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/Support/DebugTest.cpp --------------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Eugene Leviant | c089e40 | 2016-12-27 09:31:20 +0000 | [diff] [blame] | 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 | |
Eugene Leviant | c2f5408 | 2016-12-27 11:07:53 +0000 | [diff] [blame] | 16 | #ifndef NDEBUG |
Eugene Leviant | c089e40 | 2016-12-27 09:31:20 +0000 | [diff] [blame] | 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(DT, 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 | } |
Eugene Leviant | c2f5408 | 2016-12-27 11:07:53 +0000 | [diff] [blame] | 33 | #endif |