2017-10-26 16:23:20 +08:00
|
|
|
//===---- ObjCModuleTest.cpp - clang-tidy ---------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2017-10-26 16:23:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ClangTidyTest.h"
|
|
|
|
#include "gtest/gtest.h"
|
2017-10-27 15:41:36 +08:00
|
|
|
#include "objc/ForbiddenSubclassingCheck.h"
|
|
|
|
|
|
|
|
using namespace clang::tidy::objc;
|
2017-10-26 16:23:20 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace test {
|
|
|
|
|
2017-10-27 15:41:36 +08:00
|
|
|
TEST(ObjCForbiddenSubclassing, AllowedSubclass) {
|
|
|
|
std::vector<ClangTidyError> Errors;
|
|
|
|
runCheckOnCode<ForbiddenSubclassingCheck>(
|
|
|
|
"@interface Foo\n"
|
|
|
|
"@end\n"
|
|
|
|
"@interface Bar : Foo\n"
|
|
|
|
"@end\n",
|
|
|
|
&Errors,
|
|
|
|
"input.m");
|
|
|
|
EXPECT_EQ(0ul, Errors.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ObjCForbiddenSubclassing, ForbiddenSubclass) {
|
|
|
|
std::vector<ClangTidyError> Errors;
|
|
|
|
runCheckOnCode<ForbiddenSubclassingCheck>(
|
|
|
|
"@interface UIImagePickerController\n"
|
|
|
|
"@end\n"
|
|
|
|
"@interface Foo : UIImagePickerController\n"
|
|
|
|
"@end\n",
|
|
|
|
&Errors,
|
|
|
|
"input.m");
|
|
|
|
EXPECT_EQ(1ul, Errors.size());
|
|
|
|
EXPECT_EQ(
|
|
|
|
"Objective-C interface 'Foo' subclasses 'UIImagePickerController', which is not intended to be subclassed",
|
|
|
|
Errors[0].Message.Message);
|
|
|
|
}
|
2017-10-26 16:23:20 +08:00
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|