[clang] 274907c - [ASTImporter] Split out Objective-C related unit tests
Raphael Isemann via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 23 05:59:04 PDT 2021
Author: Raphael Isemann
Date: 2021-03-23T13:58:45+01:00
New Revision: 274907c0a4d6dbdc8815f9a37ea2e444bdfee528
URL: https://github.com/llvm/llvm-project/commit/274907c0a4d6dbdc8815f9a37ea2e444bdfee528
DIFF: https://github.com/llvm/llvm-project/commit/274907c0a4d6dbdc8815f9a37ea2e444bdfee528.diff
LOG: [ASTImporter] Split out Objective-C related unit tests
This moves the two tests we have for importing Objective-C nodes to their own
file. The motivation is that this means I can add more Objective-C tests without
making the compilation time of ASTImporterTest even longer. Also it seems nice
to separate the Apple-specific stuff from the ASTImporter test.
Reviewed By: martong
Differential Revision: https://reviews.llvm.org/D99162
Added:
clang/unittests/AST/ASTImporterObjCTest.cpp
Modified:
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/AST/CMakeLists.txt
Removed:
################################################################################
diff --git a/clang/unittests/AST/ASTImporterObjCTest.cpp b/clang/unittests/AST/ASTImporterObjCTest.cpp
new file mode 100644
index 0000000000000..2d848dcf754ed
--- /dev/null
+++ b/clang/unittests/AST/ASTImporterObjCTest.cpp
@@ -0,0 +1,89 @@
+//===- unittest/AST/ASTImporterObjCTest.cpp -============================--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Tests for the correct import of AST nodes related to Objective-C and
+// Objective-C++.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/DeclContextInternals.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "gtest/gtest.h"
+
+#include "ASTImporterFixtures.h"
+
+using namespace clang::ast_matchers;
+using namespace clang;
+
+namespace {
+struct ImportObjCDecl : ASTImporterOptionSpecificTestBase {};
+} // namespace
+
+TEST_P(ImportObjCDecl, ImplicitlyDeclareSelf) {
+ Decl *FromTU = getTuDecl(R"(
+ __attribute__((objc_root_class))
+ @interface Root
+ @end
+ @interface C : Root
+ -(void)method;
+ @end
+ @implementation C
+ -(void)method {}
+ @end
+ )",
+ Lang_OBJCXX, "input.mm");
+ auto *FromMethod = LastDeclMatcher<ObjCMethodDecl>().match(
+ FromTU, namedDecl(hasName("method")));
+ ASSERT_TRUE(FromMethod);
+ auto ToMethod = Import(FromMethod, Lang_OBJCXX);
+ ASSERT_TRUE(ToMethod);
+
+ // Both methods should have their implicit parameters.
+ EXPECT_TRUE(FromMethod->getSelfDecl() != nullptr);
+ EXPECT_TRUE(ToMethod->getSelfDecl() != nullptr);
+}
+
+TEST_P(ImportObjCDecl, ObjPropertyNameConflict) {
+ // Tests that properties that share the same name are correctly imported.
+ // This is only possible with one instance and one class property.
+ Decl *FromTU = getTuDecl(R"(
+ @interface DupProp{}
+ @property (class) int prop;
+ @property int prop;
+ @end
+ )",
+ Lang_OBJCXX, "input.mm");
+ auto *FromClass = FirstDeclMatcher<ObjCInterfaceDecl>().match(
+ FromTU, namedDecl(hasName("DupProp")));
+ auto ToClass = Import(FromClass, Lang_OBJCXX);
+ ASSERT_TRUE(ToClass);
+ // We should have one class and one instance property.
+ ASSERT_EQ(
+ 1, std::distance(ToClass->classprop_begin(), ToClass->classprop_end()));
+ ASSERT_EQ(1,
+ std::distance(ToClass->instprop_begin(), ToClass->instprop_end()));
+ for (clang::ObjCPropertyDecl *prop : ToClass->properties()) {
+ // All properties should have a getter and a setter.
+ ASSERT_TRUE(prop->getGetterMethodDecl());
+ ASSERT_TRUE(prop->getSetterMethodDecl());
+ // The getters/setters should be able to find the right associated property.
+ ASSERT_EQ(prop->getGetterMethodDecl()->findPropertyDecl(), prop);
+ ASSERT_EQ(prop->getSetterMethodDecl()->findPropertyDecl(), prop);
+ }
+}
+
+static const auto ObjCTestArrayForRunOptions =
+ std::array<std::vector<std::string>, 2>{
+ {std::vector<std::string>{"-fno-objc-arc"},
+ std::vector<std::string>{"-fobjc-arc"}}};
+
+const auto ObjCTestValuesForRunOptions =
+ ::testing::ValuesIn(ObjCTestArrayForRunOptions);
+
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportObjCDecl,
+ ObjCTestValuesForRunOptions, );
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 94cec2c140e12..40383bcabc3f0 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -5615,59 +5615,6 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportDefaultConstructibleLambdas) {
2u);
}
-TEST_P(ASTImporterOptionSpecificTestBase, ImplicitlyDeclareSelf) {
- Decl *FromTU = getTuDecl(R"(
- __attribute__((objc_root_class))
- @interface Root
- @end
- @interface C : Root
- -(void)method;
- @end
- @implementation C
- -(void)method {}
- @end
- )",
- Lang_OBJCXX, "input.mm");
- auto *FromMethod = LastDeclMatcher<ObjCMethodDecl>().match(
- FromTU, namedDecl(hasName("method")));
- ASSERT_TRUE(FromMethod);
- auto ToMethod = Import(FromMethod, Lang_OBJCXX);
- ASSERT_TRUE(ToMethod);
-
- // Both methods should have their implicit parameters.
- EXPECT_TRUE(FromMethod->getSelfDecl() != nullptr);
- EXPECT_TRUE(ToMethod->getSelfDecl() != nullptr);
-}
-
-TEST_P(ASTImporterOptionSpecificTestBase, ObjPropertyNameConflict) {
- // Tests that properties that share the same name are correctly imported.
- // This is only possible with one instance and one class property.
- Decl *FromTU = getTuDecl(R"(
- @interface DupProp{}
- @property (class) int prop;
- @property int prop;
- @end
- )",
- Lang_OBJCXX, "input.mm");
- auto *FromClass = FirstDeclMatcher<ObjCInterfaceDecl>().match(
- FromTU, namedDecl(hasName("DupProp")));
- auto ToClass = Import(FromClass, Lang_OBJCXX);
- ASSERT_TRUE(ToClass);
- // We should have one class and one instance property.
- ASSERT_EQ(
- 1, std::distance(ToClass->classprop_begin(), ToClass->classprop_end()));
- ASSERT_EQ(1,
- std::distance(ToClass->instprop_begin(), ToClass->instprop_end()));
- for (clang::ObjCPropertyDecl *prop : ToClass->properties()) {
- // All properties should have a getter and a setter.
- ASSERT_TRUE(prop->getGetterMethodDecl());
- ASSERT_TRUE(prop->getSetterMethodDecl());
- // The getters/setters should be able to find the right associated property.
- ASSERT_EQ(prop->getGetterMethodDecl()->findPropertyDecl(), prop);
- ASSERT_EQ(prop->getSetterMethodDecl()->findPropertyDecl(), prop);
- }
-}
-
struct ImportAutoFunctions : ASTImporterOptionSpecificTestBase {};
TEST_P(ImportAutoFunctions, ReturnWithTypedefDeclaredInside) {
diff --git a/clang/unittests/AST/CMakeLists.txt b/clang/unittests/AST/CMakeLists.txt
index 979d59bd0f392..105bfd77df905 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_unittest(ASTTests
ASTContextParentMapTest.cpp
ASTImporterFixtures.cpp
ASTImporterTest.cpp
+ ASTImporterObjCTest.cpp
ASTImporterGenericRedeclTest.cpp
ASTImporterODRStrategiesTest.cpp
ASTImporterVisibilityTest.cpp
More information about the cfe-commits
mailing list