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
13using namespace clang::tidy::objc;
14
15namespace clang {
16namespace tidy {
17namespace test {
18
19TEST(ObjCForbiddenSubclassing, AllowedSubclass) {
20 std::vector<ClangTidyError> Errors;
21 runCheckOnCode<ForbiddenSubclassingCheck>(
22 Code: "@interface Foo\n"
23 "@end\n"
24 "@interface Bar : Foo\n"
25 "@end\n",
26 Errors: &Errors,
27 Filename: "input.m");
28 EXPECT_EQ(0ul, Errors.size());
29}
30
31TEST(ObjCForbiddenSubclassing, ForbiddenSubclass) {
32 std::vector<ClangTidyError> Errors;
33 runCheckOnCode<ForbiddenSubclassingCheck>(
34 Code: "@interface UIImagePickerController\n"
35 "@end\n"
36 "@interface Foo : UIImagePickerController\n"
37 "@end\n",
38 Errors: &Errors,
39 Filename: "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
49

source code of clang-tools-extra/unittests/clang-tidy/ObjCModuleTest.cpp