This revision was automatically updated to reflect the committed changes. Closed by commit rL291759: Add format_provider for the Error class (authored by labath).
Changed prior to commit: https://reviews.llvm.org/D28519?vs=83813&id=84098#toc Repository: rL LLVM https://reviews.llvm.org/D28519 Files: lldb/trunk/include/lldb/Core/Error.h lldb/trunk/unittests/Core/CMakeLists.txt lldb/trunk/unittests/Core/ErrorTest.cpp Index: lldb/trunk/unittests/Core/CMakeLists.txt =================================================================== --- lldb/trunk/unittests/Core/CMakeLists.txt +++ lldb/trunk/unittests/Core/CMakeLists.txt @@ -2,6 +2,7 @@ ArchSpecTest.cpp BroadcasterTest.cpp DataExtractorTest.cpp + ErrorTest.cpp ListenerTest.cpp ScalarTest.cpp StructuredDataTest.cpp Index: lldb/trunk/unittests/Core/ErrorTest.cpp =================================================================== --- lldb/trunk/unittests/Core/ErrorTest.cpp +++ lldb/trunk/unittests/Core/ErrorTest.cpp @@ -0,0 +1,19 @@ +//===-- ErrorTest.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "lldb/Core/Error.h" + +using namespace lldb_private; + +TEST(ErrorTest, Formatv) { + EXPECT_EQ("", llvm::formatv("{0}", Error()).str()); + EXPECT_EQ("Hello Error", llvm::formatv("{0}", Error("Hello Error")).str()); + EXPECT_EQ("Hello", llvm::formatv("{0:5}", Error("Hello Error")).str()); +} Index: lldb/trunk/include/lldb/Core/Error.h =================================================================== --- lldb/trunk/include/lldb/Core/Error.h +++ lldb/trunk/include/lldb/Core/Error.h @@ -12,6 +12,7 @@ #if defined(__cplusplus) #include "llvm/Support/DataTypes.h" +#include "llvm/Support/FormatVariadic.h" #include <cstdarg> #include <cstdio> @@ -300,5 +301,15 @@ } // namespace lldb_private +namespace llvm { +template <> struct llvm::format_provider<lldb_private::Error> { + static void format(const lldb_private::Error &error, llvm::raw_ostream &OS, + llvm::StringRef Options) { + llvm::format_provider<llvm::StringRef>::format(error.AsCString(), OS, + Options); + } +}; +} + #endif // #if defined(__cplusplus) #endif // #ifndef __DCError_h__
Index: lldb/trunk/unittests/Core/CMakeLists.txt =================================================================== --- lldb/trunk/unittests/Core/CMakeLists.txt +++ lldb/trunk/unittests/Core/CMakeLists.txt @@ -2,6 +2,7 @@ ArchSpecTest.cpp BroadcasterTest.cpp DataExtractorTest.cpp + ErrorTest.cpp ListenerTest.cpp ScalarTest.cpp StructuredDataTest.cpp Index: lldb/trunk/unittests/Core/ErrorTest.cpp =================================================================== --- lldb/trunk/unittests/Core/ErrorTest.cpp +++ lldb/trunk/unittests/Core/ErrorTest.cpp @@ -0,0 +1,19 @@ +//===-- ErrorTest.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "lldb/Core/Error.h" + +using namespace lldb_private; + +TEST(ErrorTest, Formatv) { + EXPECT_EQ("", llvm::formatv("{0}", Error()).str()); + EXPECT_EQ("Hello Error", llvm::formatv("{0}", Error("Hello Error")).str()); + EXPECT_EQ("Hello", llvm::formatv("{0:5}", Error("Hello Error")).str()); +} Index: lldb/trunk/include/lldb/Core/Error.h =================================================================== --- lldb/trunk/include/lldb/Core/Error.h +++ lldb/trunk/include/lldb/Core/Error.h @@ -12,6 +12,7 @@ #if defined(__cplusplus) #include "llvm/Support/DataTypes.h" +#include "llvm/Support/FormatVariadic.h" #include <cstdarg> #include <cstdio> @@ -300,5 +301,15 @@ } // namespace lldb_private +namespace llvm { +template <> struct llvm::format_provider<lldb_private::Error> { + static void format(const lldb_private::Error &error, llvm::raw_ostream &OS, + llvm::StringRef Options) { + llvm::format_provider<llvm::StringRef>::format(error.AsCString(), OS, + Options); + } +}; +} + #endif // #if defined(__cplusplus) #endif // #ifndef __DCError_h__
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits