| 1 |
//===---- ObjCModuleTest.cpp - clang-tidy ---------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "ClangTidyTest.h" |
| 10 |
#include "gtest/gtest.h" |
| 11 |
#include "objc/ForbiddenSubclassingCheck.h" |
| 12 |
|
| 13 |
using namespace clang::tidy::objc; |
| 14 |
|
| 15 |
namespace clang { |
| 16 |
namespace tidy { |
| 17 |
namespace test { |
| 18 |
|
| 19 |
TEST(ObjCForbiddenSubclassing, AllowedSubclass) { |
| 20 |
std::vector<ClangTidyError> Errors; |
| 21 |
runCheckOnCode<ForbiddenSubclassingCheck>( |
| 22 |
"@interface Foo\n" |
| 23 |
"@end\n" |
| 24 |
"@interface Bar : Foo\n" |
| 25 |
"@end\n", |
| 26 |
&Errors, |
| 27 |
"input.m"); |
| 28 |
EXPECT_EQ(0ul, Errors.size()); |
| 29 |
} |
| 30 |
|
| 31 |
TEST(ObjCForbiddenSubclassing, ForbiddenSubclass) { |
| 32 |
std::vector<ClangTidyError> Errors; |
| 33 |
runCheckOnCode<ForbiddenSubclassingCheck>( |
| 34 |
"@interface UIImagePickerController\n" |
| 35 |
"@end\n" |
| 36 |
"@interface Foo : UIImagePickerController\n" |
| 37 |
"@end\n", |
| 38 |
&Errors, |
| 39 |
"input.m"); |
| 40 |
EXPECT_EQ(1ul, Errors.size()); |
| 41 |
EXPECT_EQ( |
| 42 |
"Objective-C interface 'Foo' subclasses 'UIImagePickerController', which is not intended to be subclassed", |
| 43 |
Errors[0].Message.Message); |
| 44 |
} |
| 45 |
|
| 46 |
} // namespace test |
| 47 |
} // namespace tidy |
| 48 |
} // namespace clang |