1// RUN: %check_clang_tidy %s objc-assert-equals %t -- -- -I %S/Inputs/assert
2#include "XCTestAssertions.h"
3// Can't reference NSString directly so we use this getStr() instead.
4__typeof(@"abc") getStr(void) {
5 return @"abc";
6}
7void foo(void) {
8 XCTAssertEqual(getStr(), @"abc");
9 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
10 // CHECK-FIXES: XCTAssertEqualObjects(getStr(), @"abc");
11 XCTAssertEqual(@"abc", @"abc");
12 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
13 // CHECK-FIXES: XCTAssertEqualObjects(@"abc", @"abc");
14 XCTAssertEqual(@"abc", getStr());
15 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
16 // CHECK-FIXES: XCTAssertEqualObjects(@"abc", getStr());
17 XCTAssertEqual(getStr(), getStr());
18 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
19 // CHECK-FIXES: XCTAssertEqualObjects(getStr(), getStr());
20 // Primitive types should be ok
21 XCTAssertEqual(123, 123);
22 XCTAssertEqual(123.0, 123.45);
23 // FIXME: This is the case where we don't diagnose properly.
24 // XCTAssertEqual(@"abc" != @"abc", @"xyz" != @"xyz")
25}
26

source code of clang-tools-extra/test/clang-tidy/checkers/objc/assert-equals.m