Rename APIs in unittests/AST/Language.h in preparation to share them
Summary:
Declaring these helpers in the ast_matcher namespace in the clangAST
unit test seems inappropriate -- neither these helpers, nor clangAST have
anything to do with AST matchers. Therefore, I moved these helpers to
the clang namespace.
Declaring another typedef called "ArgVector" is not a good idea -- we
already have both "ArgVector", "ArgsVector", and "ArgList". I expanded
it into the underlying type.
Declaring another enum called "Language" is not a good idea because we
arleady have the "clang::Language" enum. I renamed it to
"TestLanguage".
Similarly, I renamed "getBasicRunOptionsForLanguage" to
"getCommandLineArgsForTesting" to explain the semantics better (what are
"run options"?) and not repeat types in the function name
("ForLanguage").
Reviewers: shafik, rengolin, sammccall
Reviewed By: sammccall
Subscribers: gribozavr2, sammccall, martong, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D80786
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 06f6aa1..5e70d28 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -28,8 +28,9 @@
using llvm::StringMap;
// Base class for those tests which use the family of `testImport` functions.
-class TestImportBase : public CompilerOptionSpecificTest,
- public ::testing::WithParamInterface<ArgVector> {
+class TestImportBase
+ : public CompilerOptionSpecificTest,
+ public ::testing::WithParamInterface<std::vector<std::string>> {
template <typename NodeType>
llvm::Expected<NodeType> importNode(ASTUnit *From, ASTUnit *To,
@@ -62,8 +63,9 @@
template <typename NodeType>
testing::AssertionResult
- testImport(const std::string &FromCode, const ArgVector &FromArgs,
- const std::string &ToCode, const ArgVector &ToArgs,
+ testImport(const std::string &FromCode,
+ const std::vector<std::string> &FromArgs,
+ const std::string &ToCode, const std::vector<std::string> &ToArgs,
MatchVerifier<NodeType> &Verifier,
const BindableMatcher<NodeType> &SearchMatcher,
const BindableMatcher<NodeType> &VerificationMatcher) {
@@ -110,8 +112,9 @@
template <typename NodeType>
testing::AssertionResult
- testImport(const std::string &FromCode, const ArgVector &FromArgs,
- const std::string &ToCode, const ArgVector &ToArgs,
+ testImport(const std::string &FromCode,
+ const std::vector<std::string> &FromArgs,
+ const std::string &ToCode, const std::vector<std::string> &ToArgs,
MatchVerifier<NodeType> &Verifier,
const BindableMatcher<NodeType> &VerificationMatcher) {
return testImport(
@@ -122,7 +125,7 @@
}
protected:
- ArgVector getExtraArgs() const override { return GetParam(); }
+ std::vector<std::string> getExtraArgs() const override { return GetParam(); }
public:
@@ -130,12 +133,12 @@
/// of "FromCode" virtual file is imported to "ToCode" virtual file.
/// The verification is done by running AMatcher over the imported node.
template <typename NodeType, typename MatcherType>
- void testImport(const std::string &FromCode, Language FromLang,
- const std::string &ToCode, Language ToLang,
+ void testImport(const std::string &FromCode, TestLanguage FromLang,
+ const std::string &ToCode, TestLanguage ToLang,
MatchVerifier<NodeType> &Verifier,
const MatcherType &AMatcher) {
- ArgVector FromArgs = getArgVectorForLanguage(FromLang),
- ToArgs = getArgVectorForLanguage(ToLang);
+ std::vector<std::string> FromArgs = getCommandLineArgsForLanguage(FromLang);
+ std::vector<std::string> ToArgs = getCommandLineArgsForLanguage(ToLang);
EXPECT_TRUE(
testImport(FromCode, FromArgs, ToCode, ToArgs, Verifier, AMatcher));
}
@@ -162,14 +165,14 @@
struct CodeEntry {
std::string CodeSample;
- Language Lang;
+ TestLanguage Lang;
};
using CodeFiles = StringMap<CodeEntry>;
/// Builds an ASTUnit for one potential compile options set.
SingleASTUnit createASTUnit(StringRef FileName, const CodeEntry &CE) const {
- ArgVector Args = getArgVectorForLanguage(CE.Lang);
+ std::vector<std::string> Args = getCommandLineArgsForLanguage(CE.Lang);
auto AST = tooling::buildASTFromCodeWithArgs(CE.CodeSample, Args, FileName);
EXPECT_TRUE(AST.get());
return AST;
@@ -5523,14 +5526,14 @@
}
INSTANTIATE_TEST_CASE_P(ParameterizedTests, SVEBuiltins,
- ::testing::Values(ArgVector{"-target",
- "aarch64-linux-gnu"}), );
+ ::testing::Values(std::vector<std::string>{
+ "-target", "aarch64-linux-gnu"}), );
INSTANTIATE_TEST_CASE_P(ParameterizedTests, DeclContextTest,
- ::testing::Values(ArgVector()), );
+ ::testing::Values(std::vector<std::string>()), );
INSTANTIATE_TEST_CASE_P(ParameterizedTests, CanonicalRedeclChain,
- ::testing::Values(ArgVector()), );
+ ::testing::Values(std::vector<std::string>()), );
TEST_P(ASTImporterOptionSpecificTestBase, LambdasAreDifferentiated) {
Decl *FromTU = getTuDecl(
@@ -5982,9 +5985,9 @@
}
template <typename T>
-auto ExtendWithOptions(const T &Values, const ArgVector &Args) {
+auto ExtendWithOptions(const T &Values, const std::vector<std::string> &Args) {
auto Copy = Values;
- for (ArgVector &ArgV : Copy) {
+ for (std::vector<std::string> &ArgV : Copy) {
for (const std::string &Arg : Args) {
ArgV.push_back(Arg);
}
@@ -6056,14 +6059,15 @@
DefaultTestValuesForRunOptions, );
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportPath,
- ::testing::Values(ArgVector()), );
+ ::testing::Values(std::vector<std::string>()), );
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
DefaultTestValuesForRunOptions, );
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
ExtendWithOptions(DefaultTestArrayForRunOptions,
- ArgVector{"-ffixed-point"}), );
+ std::vector<std::string>{
+ "-ffixed-point"}), );
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
DefaultTestValuesForRunOptions, );