Remove DriverTest.h.
authorRui Ueyama <ruiu@google.com>
Sun, 28 Feb 2016 20:56:34 +0000 (20:56 +0000)
committerRui Ueyama <ruiu@google.com>
Sun, 28 Feb 2016 20:56:34 +0000 (20:56 +0000)
Because the class is used only by one instance, we do not have to
use template there in DriverTest.h. Everything can be moved to
DarwinLdDriverTest.cpp.

llvm-svn: 262192

lld/unittests/DriverTests/DarwinLdDriverTest.cpp
lld/unittests/DriverTests/DriverTest.h [deleted file]

index 9d5b36f..68bd736 100644 (file)
 ///
 //===----------------------------------------------------------------------===//
 
-#include "DriverTest.h"
+#include "lld/Driver/Driver.h"
 #include "lld/ReaderWriter/MachOLinkingContext.h"
 #include "llvm/Support/MachO.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
 
 using namespace llvm;
 using namespace lld;
 
 namespace {
-class DarwinLdParserTest
-    : public ParserTest<DarwinLdDriver, MachOLinkingContext> {
+class DarwinLdParserTest : public testing::Test {
 protected:
-  const LinkingContext *linkingContext() override { return &_ctx; }
+  int inputFileCount() { return _ctx.getNodes().size(); }
+
+  std::string inputFile(int index) {
+    Node &node = *_ctx.getNodes()[index];
+    if (node.kind() == Node::Kind::File)
+      return cast<FileNode>(&node)->getFile()->path();
+    llvm_unreachable("not handling other types of input files");
+  }
+
+  bool parse(std::vector<const char *> args) {
+    args.insert(args.begin(), "ld");
+    std::string errorMessage;
+    raw_string_ostream os(errorMessage);
+    return DarwinLdDriver::parse(args, _ctx, os);
+  }
+
+  MachOLinkingContext _ctx;
 };
 }
 
 TEST_F(DarwinLdParserTest, Basic) {
-  EXPECT_TRUE(parse("ld", "foo.o", "bar.o", "-arch", "i386", nullptr));
+  EXPECT_TRUE(parse({"foo.o", "bar.o", "-arch", "i386"}));
   EXPECT_FALSE(_ctx.allowRemainingUndefines());
   EXPECT_FALSE(_ctx.deadStrip());
   EXPECT_EQ(2, inputFileCount());
@@ -37,220 +54,207 @@ TEST_F(DarwinLdParserTest, Basic) {
 }
 
 TEST_F(DarwinLdParserTest, Output) {
-  EXPECT_TRUE(parse("ld", "-o", "my.out", "foo.o", "-arch", "i386", nullptr));
+  EXPECT_TRUE(parse({"-o", "my.out", "foo.o", "-arch", "i386"}));
   EXPECT_EQ("my.out", _ctx.outputPath());
 }
 
 TEST_F(DarwinLdParserTest, Dylib) {
-  EXPECT_TRUE(parse("ld", "-dylib", "foo.o", "-arch", "i386", nullptr));
+  EXPECT_TRUE(parse({"-dylib", "foo.o", "-arch", "i386"}));
   EXPECT_EQ(llvm::MachO::MH_DYLIB, _ctx.outputMachOType());
 }
 
 TEST_F(DarwinLdParserTest, Relocatable) {
-  EXPECT_TRUE(parse("ld", "-r", "foo.o", "-arch", "i386", nullptr));
+  EXPECT_TRUE(parse({"-r", "foo.o", "-arch", "i386"}));
   EXPECT_EQ(llvm::MachO::MH_OBJECT, _ctx.outputMachOType());
 }
 
 TEST_F(DarwinLdParserTest, Bundle) {
-  EXPECT_TRUE(parse("ld", "-bundle", "foo.o", "-arch", "i386", nullptr));
+  EXPECT_TRUE(parse({"-bundle", "foo.o", "-arch", "i386"}));
   EXPECT_EQ(llvm::MachO::MH_BUNDLE, _ctx.outputMachOType());
 }
 
 TEST_F(DarwinLdParserTest, Preload) {
-  EXPECT_TRUE(parse("ld", "-preload", "foo.o", "-arch", "i386", nullptr));
+  EXPECT_TRUE(parse({"-preload", "foo.o", "-arch", "i386"}));
   EXPECT_EQ(llvm::MachO::MH_PRELOAD, _ctx.outputMachOType());
 }
 
 TEST_F(DarwinLdParserTest, Static) {
-  EXPECT_TRUE(parse("ld", "-static", "foo.o", "-arch", "i386", nullptr));
+  EXPECT_TRUE(parse({"-static", "foo.o", "-arch", "i386"}));
   EXPECT_EQ(llvm::MachO::MH_EXECUTE, _ctx.outputMachOType());
 }
 
 TEST_F(DarwinLdParserTest, Entry) {
-  EXPECT_TRUE(parse("ld", "-e", "entryFunc", "foo.o", "-arch", "i386",nullptr));
+  EXPECT_TRUE(parse({"-e", "entryFunc", "foo.o", "-arch", "i386"}));
   EXPECT_EQ("entryFunc", _ctx.entrySymbolName());
 }
 
 TEST_F(DarwinLdParserTest, DeadStrip) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
+  EXPECT_TRUE(parse({"-arch", "x86_64", "-dead_strip", "foo.o"}));
   EXPECT_TRUE(_ctx.deadStrip());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsExe) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip", "foo.o", nullptr));
+  EXPECT_TRUE(parse({"-arch", "x86_64", "-dead_strip", "foo.o"}));
   EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsDylib) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dylib", "-dead_strip", "foo.o",
-                    nullptr));
+  EXPECT_TRUE(parse({"-arch", "x86_64", "-dylib", "-dead_strip", "foo.o"}));
   EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsRelocatable) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-r", "-dead_strip", "foo.o",
-                    nullptr));
+  EXPECT_TRUE(parse({"-arch", "x86_64", "-r", "-dead_strip", "foo.o"}));
   EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicExe) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dead_strip",
-                    "-export_dynamic", "foo.o", nullptr));
+  EXPECT_TRUE(
+      parse({"-arch", "x86_64", "-dead_strip", "-export_dynamic", "foo.o"}));
   EXPECT_TRUE(_ctx.globalsAreDeadStripRoots());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicDylib) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-dylib", "-dead_strip",
-                    "-export_dynamic", "foo.o",
-                    nullptr));
+  EXPECT_TRUE(parse({"-arch", "x86_64", "-dylib", "-dead_strip",
+                     "-export_dynamic", "foo.o"}));
   EXPECT_TRUE(_ctx.globalsAreDeadStripRoots());
 }
 
 TEST_F(DarwinLdParserTest, DeadStripRootsExportDynamicRelocatable) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "-r", "-dead_strip",
-                    "-export_dynamic", "foo.o", nullptr));
+  EXPECT_TRUE(parse(
+      {"-arch", "x86_64", "-r", "-dead_strip", "-export_dynamic", "foo.o"}));
   EXPECT_FALSE(_ctx.globalsAreDeadStripRoots());
 }
 
 TEST_F(DarwinLdParserTest, Arch) {
-  EXPECT_TRUE(parse("ld", "-arch", "x86_64", "foo.o", nullptr));
+  EXPECT_TRUE(parse({"-arch", "x86_64", "foo.o"}));
   EXPECT_EQ(MachOLinkingContext::arch_x86_64, _ctx.arch());
   EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_X86_64, _ctx.getCPUType());
   EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_X86_64_ALL, _ctx.getCPUSubType());
 }
 
 TEST_F(DarwinLdParserTest, Arch_x86) {
-  EXPECT_TRUE(parse("ld", "-arch", "i386", "foo.o", nullptr));
+  EXPECT_TRUE(parse({"-arch", "i386", "foo.o"}));
   EXPECT_EQ(MachOLinkingContext::arch_x86, _ctx.arch());
   EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_I386, _ctx.getCPUType());
   EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_X86_ALL, _ctx.getCPUSubType());
 }
 
 TEST_F(DarwinLdParserTest, Arch_armv6) {
-  EXPECT_TRUE(parse("ld", "-arch", "armv6", "foo.o", nullptr));
+  EXPECT_TRUE(parse({"-arch", "armv6", "foo.o"}));
   EXPECT_EQ(MachOLinkingContext::arch_armv6, _ctx.arch());
   EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _ctx.getCPUType());
   EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V6, _ctx.getCPUSubType());
 }
 
 TEST_F(DarwinLdParserTest, Arch_armv7) {
-  EXPECT_TRUE(parse("ld", "-arch", "armv7", "foo.o", nullptr));
+  EXPECT_TRUE(parse({"-arch", "armv7", "foo.o"}));
   EXPECT_EQ(MachOLinkingContext::arch_armv7, _ctx.arch());
   EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _ctx.getCPUType());
   EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V7, _ctx.getCPUSubType());
 }
 
 TEST_F(DarwinLdParserTest, Arch_armv7s) {
-  EXPECT_TRUE(parse("ld", "-arch", "armv7s", "foo.o", nullptr));
+  EXPECT_TRUE(parse({"-arch", "armv7s", "foo.o"}));
   EXPECT_EQ(MachOLinkingContext::arch_armv7s, _ctx.arch());
   EXPECT_EQ((uint32_t)llvm::MachO::CPU_TYPE_ARM, _ctx.getCPUType());
   EXPECT_EQ(llvm::MachO::CPU_SUBTYPE_ARM_V7S, _ctx.getCPUSubType());
 }
 
 TEST_F(DarwinLdParserTest, MinMacOSX10_7) {
-  EXPECT_TRUE(parse("ld", "-macosx_version_min", "10.7", "foo.o",
-                    "-arch", "x86_64", nullptr));
+  EXPECT_TRUE(
+      parse({"-macosx_version_min", "10.7", "foo.o", "-arch", "x86_64"}));
   EXPECT_EQ(MachOLinkingContext::OS::macOSX, _ctx.os());
   EXPECT_TRUE(_ctx.minOS("10.7", ""));
   EXPECT_FALSE(_ctx.minOS("10.8", ""));
 }
 
 TEST_F(DarwinLdParserTest, MinMacOSX10_8) {
-  EXPECT_TRUE(parse("ld", "-macosx_version_min", "10.8.3", "foo.o",
-                    "-arch", "x86_64", nullptr));
+  EXPECT_TRUE(
+      parse({"-macosx_version_min", "10.8.3", "foo.o", "-arch", "x86_64"}));
   EXPECT_EQ(MachOLinkingContext::OS::macOSX, _ctx.os());
   EXPECT_TRUE(_ctx.minOS("10.7", ""));
   EXPECT_TRUE(_ctx.minOS("10.8", ""));
 }
 
 TEST_F(DarwinLdParserTest, iOS5) {
-  EXPECT_TRUE(parse("ld", "-ios_version_min", "5.0", "foo.o",
-                    "-arch", "armv7", nullptr));
+  EXPECT_TRUE(parse({"-ios_version_min", "5.0", "foo.o", "-arch", "armv7"}));
   EXPECT_EQ(MachOLinkingContext::OS::iOS, _ctx.os());
   EXPECT_TRUE(_ctx.minOS("", "5.0"));
   EXPECT_FALSE(_ctx.minOS("", "6.0"));
 }
 
 TEST_F(DarwinLdParserTest, iOS6) {
-  EXPECT_TRUE(parse("ld", "-ios_version_min", "6.0", "foo.o", "-arch", "armv7",
-                    nullptr));
+  EXPECT_TRUE(parse({"-ios_version_min", "6.0", "foo.o", "-arch", "armv7"}));
   EXPECT_EQ(MachOLinkingContext::OS::iOS, _ctx.os());
   EXPECT_TRUE(_ctx.minOS("", "5.0"));
   EXPECT_TRUE(_ctx.minOS("", "6.0"));
 }
 
 TEST_F(DarwinLdParserTest, iOS_Simulator5) {
-  EXPECT_TRUE(parse("ld", "-ios_simulator_version_min", "5.0", "a.o",
-                    "-arch", "i386", nullptr));
+  EXPECT_TRUE(
+      parse({"-ios_simulator_version_min", "5.0", "a.o", "-arch", "i386"}));
   EXPECT_EQ(MachOLinkingContext::OS::iOS_simulator, _ctx.os());
   EXPECT_TRUE(_ctx.minOS("", "5.0"));
   EXPECT_FALSE(_ctx.minOS("", "6.0"));
 }
 
 TEST_F(DarwinLdParserTest, iOS_Simulator6) {
-  EXPECT_TRUE(parse("ld", "-ios_simulator_version_min", "6.0", "a.o",
-                    "-arch", "i386", nullptr));
+  EXPECT_TRUE(
+      parse({"-ios_simulator_version_min", "6.0", "a.o", "-arch", "i386"}));
   EXPECT_EQ(MachOLinkingContext::OS::iOS_simulator, _ctx.os());
   EXPECT_TRUE(_ctx.minOS("", "5.0"));
   EXPECT_TRUE(_ctx.minOS("", "6.0"));
 }
 
 TEST_F(DarwinLdParserTest, compatibilityVersion) {
-  EXPECT_TRUE(
-      parse("ld", "-dylib", "-compatibility_version", "1.2.3", "a.o",
-             "-arch", "i386",nullptr));
+  EXPECT_TRUE(parse(
+      {"-dylib", "-compatibility_version", "1.2.3", "a.o", "-arch", "i386"}));
   EXPECT_EQ(_ctx.compatibilityVersion(), 0x10203U);
 }
 
 TEST_F(DarwinLdParserTest, compatibilityVersionInvalidType) {
-  EXPECT_FALSE(parse("ld", "-bundle", "-compatibility_version", "1.2.3", "a.o",
-                     "-arch", "i386",nullptr));
+  EXPECT_FALSE(parse(
+      {"-bundle", "-compatibility_version", "1.2.3", "a.o", "-arch", "i386"}));
 }
 
 TEST_F(DarwinLdParserTest, compatibilityVersionInvalidValue) {
-  EXPECT_FALSE(parse("ld", "-bundle", "-compatibility_version", "1,2,3", "a.o",
-                     "-arch", "i386", nullptr));
+  EXPECT_FALSE(parse(
+      {"-bundle", "-compatibility_version", "1,2,3", "a.o", "-arch", "i386"}));
 }
 
 TEST_F(DarwinLdParserTest, currentVersion) {
   EXPECT_TRUE(
-      parse("ld", "-dylib", "-current_version", "1.2.3", "a.o", "-arch", "i386",
-            nullptr));
+      parse({"-dylib", "-current_version", "1.2.3", "a.o", "-arch", "i386"}));
   EXPECT_EQ(_ctx.currentVersion(), 0x10203U);
 }
 
 TEST_F(DarwinLdParserTest, currentVersionInvalidType) {
   EXPECT_FALSE(
-      parse("ld", "-bundle", "-current_version", "1.2.3", "a.o",
-            "-arch", "i386", nullptr));
+      parse({"-bundle", "-current_version", "1.2.3", "a.o", "-arch", "i386"}));
 }
 
 TEST_F(DarwinLdParserTest, currentVersionInvalidValue) {
   EXPECT_FALSE(
-      parse("ld", "-bundle", "-current_version", "1,2,3", "a.o",
-            "-arch", "i386", nullptr));
+      parse({"-bundle", "-current_version", "1,2,3", "a.o", "-arch", "i386"}));
 }
 
 TEST_F(DarwinLdParserTest, bundleLoader) {
   EXPECT_TRUE(
-      parse("ld", "-bundle", "-bundle_loader", "/bin/ls", "a.o",
-             "-arch", "i386", nullptr));
+      parse({"-bundle", "-bundle_loader", "/bin/ls", "a.o", "-arch", "i386"}));
   EXPECT_EQ(_ctx.bundleLoader(), "/bin/ls");
 }
 
 TEST_F(DarwinLdParserTest, bundleLoaderInvalidType) {
-  EXPECT_FALSE(parse("ld", "-bundle_loader", "/bin/ls", "a.o", "-arch", "i386",
-                     nullptr));
+  EXPECT_FALSE(parse({"-bundle_loader", "/bin/ls", "a.o", "-arch", "i386"}));
 }
 
 TEST_F(DarwinLdParserTest, deadStrippableDylib) {
   EXPECT_TRUE(
-      parse("ld", "-dylib", "-mark_dead_strippable_dylib", "a.o",
-            "-arch", "i386", nullptr));
+      parse({"-dylib", "-mark_dead_strippable_dylib", "a.o", "-arch", "i386"}));
   EXPECT_EQ(true, _ctx.deadStrippableDylib());
 }
 
 TEST_F(DarwinLdParserTest, deadStrippableDylibInvalidType) {
-  EXPECT_FALSE(parse("ld", "-mark_dead_strippable_dylib", "a.o",
-                     "-arch", "i386", nullptr));
+  EXPECT_FALSE(parse({"-mark_dead_strippable_dylib", "a.o", "-arch", "i386"}));
 }
diff --git a/lld/unittests/DriverTests/DriverTest.h b/lld/unittests/DriverTests/DriverTest.h
deleted file mode 100644 (file)
index 65af7ca..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-//===- lld/unittest/DriverTest.h ------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lld/Driver/Driver.h"
-#include "llvm/Support/raw_ostream.h"
-#include "gtest/gtest.h"
-#include <stdarg.h>
-
-namespace {
-
-using namespace llvm;
-using namespace lld;
-
-template<typename D, typename T>
-class ParserTest : public testing::Test {
-protected:
-
-  virtual const LinkingContext *linkingContext() = 0;
-
-  std::string &errorMessage() { return  _errorMessage; }
-
-  // Convenience method for getting number of input files.
-  int inputFileCount() {
-    return linkingContext()->getNodes().size();
-  }
-
-  // Convenience method for getting i'th input files name.
-  std::string inputFile(int index) {
-    Node &node = *linkingContext()->getNodes()[index];
-    if (node.kind() == Node::Kind::File)
-      return cast<FileNode>(&node)->getFile()->path();
-    llvm_unreachable("not handling other types of input files");
-  }
-
-  // For unit tests to call driver with various command lines.
-  bool parse(const char *args, ...) {
-    // Construct command line options from varargs.
-    std::vector<const char *> vec;
-    vec.push_back(args);
-    va_list ap;
-    va_start(ap, args);
-    while (const char *arg = va_arg(ap, const char *))
-      vec.push_back(arg);
-    va_end(ap);
-
-    // Call the parser.
-    raw_string_ostream os(_errorMessage);
-    return D::parse(vec, _ctx, os);
-  }
-
-  T _ctx;
-  std::string _errorMessage;
-};
-
-}