2013-05-31 10:12:34 +08:00
|
|
|
//===- 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"
|
2014-10-18 13:33:55 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <stdarg.h>
|
2013-05-31 10:12:34 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace lld;
|
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
template<typename D, typename T>
|
2013-05-31 10:12:34 +08:00
|
|
|
class ParserTest : public testing::Test {
|
|
|
|
protected:
|
2013-07-17 02:45:57 +08:00
|
|
|
|
2013-08-07 06:31:59 +08:00
|
|
|
virtual const LinkingContext *linkingContext() = 0;
|
2013-07-27 01:08:12 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
std::string &errorMessage() { return _errorMessage; }
|
2013-07-27 01:08:12 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
// Convenience method for getting number of input files.
|
2015-01-15 15:20:39 +08:00
|
|
|
int inputFileCount() {
|
2015-01-15 16:46:36 +08:00
|
|
|
return linkingContext()->getNodes().size();
|
2015-01-15 15:20:39 +08:00
|
|
|
}
|
2013-05-31 10:12:34 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
// Convenience method for getting i'th input files name.
|
2013-12-05 21:07:49 +08:00
|
|
|
std::string inputFile(int index) {
|
2015-01-15 16:46:36 +08:00
|
|
|
Node &node = *linkingContext()->getNodes()[index];
|
2015-01-15 16:31:46 +08:00
|
|
|
if (node.kind() == Node::Kind::File)
|
|
|
|
return cast<FileNode>(&node)->getFile()->path();
|
2013-08-22 23:23:54 +08:00
|
|
|
llvm_unreachable("not handling other types of input files");
|
2013-07-17 02:45:57 +08:00
|
|
|
}
|
2013-05-31 10:12:34 +08:00
|
|
|
|
2013-07-17 02:45:57 +08:00
|
|
|
// For unit tests to call driver with various command lines.
|
|
|
|
bool parse(const char *args, ...) {
|
2013-05-31 10:12:34 +08:00
|
|
|
// 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.
|
2013-07-17 02:45:57 +08:00
|
|
|
raw_string_ostream os(_errorMessage);
|
2015-06-21 14:32:10 +08:00
|
|
|
return D::parse(vec, _ctx, os);
|
2013-05-31 10:12:34 +08:00
|
|
|
}
|
|
|
|
|
2015-02-11 05:28:52 +08:00
|
|
|
T _ctx;
|
2013-07-17 02:45:57 +08:00
|
|
|
std::string _errorMessage;
|
2013-05-31 10:12:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|