[Darwin][Driver] Add unit tests.

llvm-svn: 183806
This commit is contained in:
Rui Ueyama 2013-06-11 23:07:43 +00:00
parent e34ade7986
commit 9f56df8e43
2 changed files with 90 additions and 0 deletions

View File

@ -1,6 +1,7 @@
add_lld_unittest(DriverTests
UniversalDriverTest.cpp
GnuLdDriverTest.cpp
DarwinLdDriverTest.cpp
WinLinkDriverTest.cpp
)

View File

@ -0,0 +1,89 @@
//===- lld/unittest/DarwinLdDriverTest.cpp --------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief Darwin's ld driver tests.
///
//===----------------------------------------------------------------------===//
#include "DriverTest.h"
#include "lld/ReaderWriter/MachOTargetInfo.h"
#include "../../lib/ReaderWriter/MachO/MachOFormat.hpp"
using namespace llvm;
using namespace lld;
namespace {
class DarwinLdParserTest : public ParserTest<DarwinLdDriver, MachOTargetInfo> {
protected:
virtual MachOTargetInfo* doParse(int argc, const char **argv,
raw_ostream &diag) {
auto *info = new MachOTargetInfo();
DarwinLdDriver::parse(argc, argv, *info, diag);
return info;
}
};
TEST_F(DarwinLdParserTest, Basic) {
parse("ld", "foo.o", "bar.o", nullptr);
EXPECT_FALSE(info->allowRemainingUndefines());
EXPECT_FALSE(info->deadStrip());
EXPECT_EQ(2, (int)inputFiles.size());
EXPECT_EQ("foo.o", inputFiles[0]);
EXPECT_EQ("bar.o", inputFiles[1]);
}
TEST_F(DarwinLdParserTest, Dylib) {
parse("ld", "-dylib", "foo.o", nullptr);
EXPECT_EQ(mach_o::MH_DYLIB, info->outputFileType());
}
TEST_F(DarwinLdParserTest, Relocatable) {
parse("ld", "-r", "foo.o", nullptr);
EXPECT_EQ(mach_o::MH_OBJECT, info->outputFileType());
}
TEST_F(DarwinLdParserTest, Bundle) {
parse("ld", "-bundle", "foo.o", nullptr);
EXPECT_EQ(mach_o::MH_BUNDLE, info->outputFileType());
}
TEST_F(DarwinLdParserTest, Preload) {
parse("ld", "-preload", "foo.o", nullptr);
EXPECT_EQ(mach_o::MH_PRELOAD, info->outputFileType());
}
TEST_F(DarwinLdParserTest, Static) {
parse("ld", "-static", "foo.o", nullptr);
EXPECT_EQ(mach_o::MH_EXECUTE, info->outputFileType());
}
TEST_F(DarwinLdParserTest, Entry) {
parse("ld", "-e", "entryFunc", "foo.o", nullptr);
EXPECT_EQ("entryFunc", info->entrySymbolName());
}
TEST_F(DarwinLdParserTest, OutputPath) {
parse("ld", "-o", "foo", "foo.o", nullptr);
EXPECT_EQ("foo", info->outputPath());
}
TEST_F(DarwinLdParserTest, DeadStrip) {
parse("ld", "-dead_strip", "foo.o", nullptr);
EXPECT_TRUE(info->deadStrip());
}
TEST_F(DarwinLdParserTest, Arch) {
parse("ld", "-arch", "x86_64", "foo.o", nullptr);
EXPECT_EQ(MachOTargetInfo::arch_x86_64, info->arch());
}
} // end anonymous namespace