[llvm] 5810ed5 - [llvm][TextAPI/MachO] Extract common code into unittest helper (NFC)

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 13 12:53:34 PST 2020


Author: Jonas Devlieghere
Date: 2020-02-13T12:53:24-08:00
New Revision: 5810ed5186dcad03d4ae53abc103638462519f11

URL: https://github.com/llvm/llvm-project/commit/5810ed5186dcad03d4ae53abc103638462519f11
DIFF: https://github.com/llvm/llvm-project/commit/5810ed5186dcad03d4ae53abc103638462519f11.diff

LOG: [llvm][TextAPI/MachO] Extract common code into unittest helper (NFC)

This extract common code between the 4 TBD formats in a header that can
be shared.

Differential revision: https://reviews.llvm.org/D73332

Added: 
    llvm/unittests/TextAPI/TextStubHelpers.h

Modified: 
    llvm/unittests/TextAPI/TextStubV1Tests.cpp
    llvm/unittests/TextAPI/TextStubV2Tests.cpp
    llvm/unittests/TextAPI/TextStubV3Tests.cpp
    llvm/unittests/TextAPI/TextStubV4Tests.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/TextAPI/TextStubHelpers.h b/llvm/unittests/TextAPI/TextStubHelpers.h
new file mode 100644
index 000000000000..c33a45e87eb5
--- /dev/null
+++ b/llvm/unittests/TextAPI/TextStubHelpers.h
@@ -0,0 +1,41 @@
+//===-- TextStubHelpers.cpp -------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===-----------------------------------------------------------------------===/
+
+#include "llvm/TextAPI/MachO/InterfaceFile.h"
+#include <algorithm>
+#include <string>
+
+#ifndef TEXT_STUB_HELPERS_H
+#define TEXT_STUB_HELPERS_H
+
+namespace llvm {
+struct ExportedSymbol {
+  llvm::MachO::SymbolKind Kind;
+  std::string Name;
+  bool WeakDefined;
+  bool ThreadLocalValue;
+};
+
+using ExportedSymbolSeq = std::vector<ExportedSymbol>;
+using UUIDs = std::vector<std::pair<llvm::MachO::Target, std::string>>;
+
+inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
+  return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
+}
+
+inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
+  return std::tie(LHS.Kind, LHS.Name, LHS.WeakDefined, LHS.ThreadLocalValue) ==
+         std::tie(RHS.Kind, RHS.Name, RHS.WeakDefined, RHS.ThreadLocalValue);
+}
+
+inline std::string stripWhitespace(std::string S) {
+  S.erase(std::remove_if(S.begin(), S.end(), ::isspace), S.end());
+  return S;
+}
+} // namespace llvm
+#endif

diff  --git a/llvm/unittests/TextAPI/TextStubV1Tests.cpp b/llvm/unittests/TextAPI/TextStubV1Tests.cpp
index 68baac102dbf..441db0ad629d 100644
--- a/llvm/unittests/TextAPI/TextStubV1Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV1Tests.cpp
@@ -6,6 +6,7 @@
 //
 //===-----------------------------------------------------------------------===/
 
+#include "TextStubHelpers.h"
 #include "llvm/TextAPI/MachO/InterfaceFile.h"
 #include "llvm/TextAPI/MachO/TextAPIReader.h"
 #include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -16,23 +17,6 @@
 using namespace llvm;
 using namespace llvm::MachO;
 
-struct ExportedSymbol {
-  SymbolKind Kind;
-  std::string Name;
-  bool WeakDefined;
-  bool ThreadLocalValue;
-};
-using ExportedSymbolSeq = std::vector<ExportedSymbol>;
-
-inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
-  return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
-}
-
-inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
-  return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
-         std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
-}
-
 static ExportedSymbol TBDv1Symbols[] = {
     {SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
     {SymbolKind::GlobalSymbol, "_sym1", false, false},

diff  --git a/llvm/unittests/TextAPI/TextStubV2Tests.cpp b/llvm/unittests/TextAPI/TextStubV2Tests.cpp
index 31de7fd2008b..4864d8a95ccc 100644
--- a/llvm/unittests/TextAPI/TextStubV2Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV2Tests.cpp
@@ -5,7 +5,7 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===-----------------------------------------------------------------------===/
-
+#include "TextStubHelpers.h"
 #include "llvm/TextAPI/MachO/InterfaceFile.h"
 #include "llvm/TextAPI/MachO/TextAPIReader.h"
 #include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -16,23 +16,6 @@
 using namespace llvm;
 using namespace llvm::MachO;
 
-struct ExportedSymbol {
-  SymbolKind Kind;
-  std::string Name;
-  bool WeakDefined;
-  bool ThreadLocalValue;
-};
-using ExportedSymbolSeq = std::vector<ExportedSymbol>;
-
-inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
-  return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
-}
-
-inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
-  return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
-         std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
-}
-
 static ExportedSymbol TBDv2Symbols[] = {
     {SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
     {SymbolKind::GlobalSymbol, "_sym1", false, false},

diff  --git a/llvm/unittests/TextAPI/TextStubV3Tests.cpp b/llvm/unittests/TextAPI/TextStubV3Tests.cpp
index a9e54807cc85..fe71fa5b2cf3 100644
--- a/llvm/unittests/TextAPI/TextStubV3Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV3Tests.cpp
@@ -5,7 +5,7 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===-----------------------------------------------------------------------===/
-
+#include "TextStubHelpers.h"
 #include "llvm/TextAPI/MachO/InterfaceFile.h"
 #include "llvm/TextAPI/MachO/TextAPIReader.h"
 #include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -16,29 +16,6 @@
 using namespace llvm;
 using namespace llvm::MachO;
 
-struct ExportedSymbol {
-  SymbolKind Kind;
-  std::string Name;
-  bool WeakDefined;
-  bool ThreadLocalValue;
-};
-using ExportedSymbolSeq = std::vector<ExportedSymbol>;
-using UUIDs = std::vector<std::pair<Target, std::string>>;
-
-inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
-  return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
-}
-
-inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
-  return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
-         std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
-}
-
-inline std::string stripWhitespace(std::string s) {
-  s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
-  return s;
-}
-
 static ExportedSymbol TBDv3Symbols[] = {
     {SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
     {SymbolKind::GlobalSymbol, "_sym1", false, false},

diff  --git a/llvm/unittests/TextAPI/TextStubV4Tests.cpp b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
index 53e9bd9362c2..07af8f20dea3 100644
--- a/llvm/unittests/TextAPI/TextStubV4Tests.cpp
+++ b/llvm/unittests/TextAPI/TextStubV4Tests.cpp
@@ -5,6 +5,8 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===-----------------------------------------------------------------------===/
+
+#include "TextStubHelpers.h"
 #include "llvm/TextAPI/MachO/InterfaceFile.h"
 #include "llvm/TextAPI/MachO/TextAPIReader.h"
 #include "llvm/TextAPI/MachO/TextAPIWriter.h"
@@ -15,40 +17,17 @@
 using namespace llvm;
 using namespace llvm::MachO;
 
-struct ExampleSymbol {
-  SymbolKind Kind;
-  std::string Name;
-  bool WeakDefined;
-  bool ThreadLocalValue;
-};
-using ExampleSymbolSeq = std::vector<ExampleSymbol>;
-using UUIDs = std::vector<std::pair<Target, std::string>>;
-
-inline bool operator<(const ExampleSymbol &LHS, const ExampleSymbol &RHS) {
-  return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
-}
-
-inline bool operator==(const ExampleSymbol &LHS, const ExampleSymbol &RHS) {
-  return std::tie(LHS.Kind, LHS.Name, LHS.WeakDefined, LHS.ThreadLocalValue) ==
-         std::tie(RHS.Kind, RHS.Name, RHS.WeakDefined, RHS.ThreadLocalValue);
-}
-
-inline std::string stripWhitespace(std::string s) {
-  s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
-  return s;
-}
-
-static ExampleSymbol TBDv4ExportedSymbols[] = {
+static ExportedSymbol TBDv4ExportedSymbols[] = {
     {SymbolKind::GlobalSymbol, "_symA", false, false},
     {SymbolKind::GlobalSymbol, "_symAB", false, false},
     {SymbolKind::GlobalSymbol, "_symB", false, false},
 };
 
-static ExampleSymbol TBDv4ReexportedSymbols[] = {
+static ExportedSymbol TBDv4ReexportedSymbols[] = {
     {SymbolKind::GlobalSymbol, "_symC", false, false},
 };
 
-static ExampleSymbol TBDv4UndefinedSymbols[] = {
+static ExportedSymbol TBDv4UndefinedSymbols[] = {
     {SymbolKind::GlobalSymbol, "_symD", false, false},
 };
 
@@ -146,11 +125,11 @@ TEST(TBDv4, ReadFile) {
   EXPECT_EQ(1U, File->reexportedLibraries().size());
   EXPECT_EQ(reexport, File->reexportedLibraries().front());
 
-  ExampleSymbolSeq Exports, Reexports, Undefineds;
-  ExampleSymbol temp;
+  ExportedSymbolSeq Exports, Reexports, Undefineds;
+  ExportedSymbol temp;
   for (const auto *Sym : File->symbols()) {
-    temp = ExampleSymbol{Sym->getKind(), std::string(Sym->getName()),
-                         Sym->isWeakDefined(), Sym->isThreadLocalValue()};
+    temp = ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),
+                          Sym->isWeakDefined(), Sym->isThreadLocalValue()};
     EXPECT_FALSE(Sym->isWeakReferenced());
     if (Sym->isUndefined())
       Undefineds.emplace_back(std::move(temp));
@@ -162,11 +141,11 @@ TEST(TBDv4, ReadFile) {
   llvm::sort(Reexports.begin(), Reexports.end());
   llvm::sort(Undefineds.begin(), Undefineds.end());
 
-  EXPECT_EQ(sizeof(TBDv4ExportedSymbols) / sizeof(ExampleSymbol),
+  EXPECT_EQ(sizeof(TBDv4ExportedSymbols) / sizeof(ExportedSymbol),
             Exports.size());
-  EXPECT_EQ(sizeof(TBDv4ReexportedSymbols) / sizeof(ExampleSymbol),
+  EXPECT_EQ(sizeof(TBDv4ReexportedSymbols) / sizeof(ExportedSymbol),
             Reexports.size());
-  EXPECT_EQ(sizeof(TBDv4UndefinedSymbols) / sizeof(ExampleSymbol),
+  EXPECT_EQ(sizeof(TBDv4UndefinedSymbols) / sizeof(ExportedSymbol),
             Undefineds.size());
   EXPECT_TRUE(std::equal(Exports.begin(), Exports.end(),
                          std::begin(TBDv4ExportedSymbols)));


        


More information about the llvm-commits mailing list