1 //===- lld/unittest/DriverTest.h ------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lld/Driver/Driver.h"
11 #include "llvm/Support/raw_ostream.h"
12 #include "gtest/gtest.h"
20 template<typename D, typename T>
21 class ParserTest : public testing::Test {
24 virtual const LinkingContext *linkingContext() = 0;
26 std::string &errorMessage() { return _errorMessage; }
28 // Convenience method for getting number of input files.
29 int inputFileCount() {
30 return linkingContext()->getNodes().size();
33 // Convenience method for getting i'th input files name.
34 std::string inputFile(int index) {
35 Node &node = *linkingContext()->getNodes()[index];
36 if (node.kind() == Node::Kind::File)
37 return cast<FileNode>(&node)->getFile()->path();
38 llvm_unreachable("not handling other types of input files");
41 // For unit tests to call driver with various command lines.
42 bool parse(const char *args, ...) {
43 // Construct command line options from varargs.
44 std::vector<const char *> vec;
48 while (const char *arg = va_arg(ap, const char *))
53 raw_string_ostream os(_errorMessage);
54 return D::parse(vec.size(), &vec[0], _ctx, os);
58 std::string _errorMessage;