|
| 1 | +//===-- ArgParsingTest.h ----------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef ARG_PARSING_TEST_H |
| 14 | +#define ARG_PARSING_TEST_H |
| 15 | + |
| 16 | +#include "swift/Frontend/Frontend.h" |
| 17 | +#include "gtest/gtest.h" |
| 18 | + |
| 19 | +using Args = std::vector<std::string>; |
| 20 | + |
| 21 | +class ArgParsingTest : public ::testing::Test { |
| 22 | + swift::CompilerInvocation invocation; |
| 23 | + swift::SourceManager sourceMgr; |
| 24 | + swift::DiagnosticEngine diags; |
| 25 | + |
| 26 | +protected: |
| 27 | + std::optional<std::string> langMode; |
| 28 | + |
| 29 | +public: |
| 30 | + ArgParsingTest(); |
| 31 | + |
| 32 | + void parseArgs(const Args &args); |
| 33 | + |
| 34 | + swift::LangOptions &getLangOptions(); |
| 35 | +}; |
| 36 | + |
| 37 | +template <typename T> |
| 38 | +struct ArgParsingTestCase final { |
| 39 | + Args args; |
| 40 | + T expectedResult; |
| 41 | + |
| 42 | + ArgParsingTestCase(Args args, T expectedResult) |
| 43 | + : args(std::move(args)), expectedResult(std::move(expectedResult)) {} |
| 44 | +}; |
| 45 | + |
| 46 | +// MARK: - Printers |
| 47 | + |
| 48 | +void PrintTo(const Args &, std::ostream *); |
| 49 | + |
| 50 | +template <typename T> |
| 51 | +void PrintTo(const ArgParsingTestCase<T> &value, std::ostream *os) { |
| 52 | + PrintTo(value.args, os); |
| 53 | +} |
| 54 | + |
| 55 | +#endif // ARG_PARSING_TEST_H |
0 commit comments