diff options
| author | Rui Ueyama <ruiu@google.com> | 2013-05-31 02:12:34 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2013-05-31 02:12:34 +0000 |
| commit | 7eb1d49a589d5b87cd097f74eba48481f99a02d2 (patch) | |
| tree | cff5dcd8620b98df4aa877c3c1b663f48dd34bbc /lld/unittests/DriverTests/DriverTest.h | |
| parent | fc3d80bda15098c48fb615662d5fc42a9b390c28 (diff) | |
| download | bcm5719-llvm-7eb1d49a589d5b87cd097f74eba48481f99a02d2.tar.gz bcm5719-llvm-7eb1d49a589d5b87cd097f74eba48481f99a02d2.zip | |
[Driver] Add unit tests for GnuLdDriver.
llvm-svn: 182980
Diffstat (limited to 'lld/unittests/DriverTests/DriverTest.h')
| -rw-r--r-- | lld/unittests/DriverTests/DriverTest.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lld/unittests/DriverTests/DriverTest.h b/lld/unittests/DriverTests/DriverTest.h new file mode 100644 index 00000000000..6538c1b429d --- /dev/null +++ b/lld/unittests/DriverTests/DriverTest.h @@ -0,0 +1,59 @@ +//===- 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 <stdarg.h> + +#include "gtest/gtest.h" + +#include "lld/Driver/Driver.h" +#include "lld/Driver/LinkerInput.h" + +#include "llvm/Support/raw_ostream.h" + +namespace { + +using namespace llvm; +using namespace lld; + +template<typename Driver, typename TargetInfo> +class ParserTest : public testing::Test { +protected: + void SetUp() { + os.reset(new raw_string_ostream(diags)); + } + + virtual TargetInfo *doParse(int argc, const char **argv, + raw_ostream &diag) = 0; + + void 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. + info.reset(doParse(vec.size(), &vec[0], *os)); + + // Copy the output file name for the sake of convenience. + if (info) + for (const LinkerInput &input : info->inputFiles()) + inputFiles.push_back(input.getPath().str()); + } + + std::unique_ptr<TargetInfo> info; + std::string diags; + std::unique_ptr<raw_string_ostream> os; + std::vector<std::string> inputFiles; +}; + +} |

