[Lldb-commits] [PATCH] D113011: [lldb] make the code prettier in FindFileTest.cpp

Xu Jun via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 2 06:17:16 PDT 2021


xujuntwt95329 created this revision.
xujuntwt95329 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113011

Files:
  lldb/unittests/Target/FindFileTest.cpp


Index: lldb/unittests/Target/FindFileTest.cpp
===================================================================
--- lldb/unittests/Target/FindFileTest.cpp
+++ lldb/unittests/Target/FindFileTest.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "TestingSupport/SubsystemRAII.h"
 #include "TestingSupport/TestUtilities.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
@@ -24,22 +25,13 @@
 namespace {
 struct Matches {
   FileSpec original;
-  llvm::StringRef remapped;
-  Matches(const char *o, const char *r) : original(o), remapped(r) {}
-  Matches(const char *o, llvm::sys::path::Style style, const char *r)
+  std::string remapped;
+  Matches(llvm::StringRef o, llvm::sys::path::Style style, llvm::StringRef r)
       : original(o, style), remapped(r) {}
 };
 
 class FindFileTest : public testing::Test {
-public:
-  void SetUp() override {
-    FileSystem::Initialize();
-    HostInfo::Initialize();
-  }
-  void TearDown() override {
-    HostInfo::Terminate();
-    FileSystem::Terminate();
-  }
+  SubsystemRAII<FileSystem, HostInfo> subsystems;
 };
 } // namespace
 
@@ -53,11 +45,11 @@
 
   for (const auto &match : matches) {
     SCOPED_TRACE(match.original.GetPath() + " -> " + match.remapped);
-    llvm::Optional<FileSpec> remapped;
+    llvm::Optional<FileSpec> remapped = map.FindFile(match.original);
 
-    EXPECT_TRUE(bool(remapped = map.FindFile(match.original)));
-    EXPECT_TRUE(FileSpec(remapped.getValue()).GetPath() ==
-                ConstString(match.remapped).GetStringRef());
+    EXPECT_TRUE(remapped);
+    EXPECT_EQ(FileSpec(remapped.getValue()).GetPath(),
+              ConstString(match.remapped).GetStringRef());
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113011.384056.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211102/58530074/attachment.bin>


More information about the lldb-commits mailing list