llvm-project/clang-tools-extra/test/clang-tidy/checkers/objc-assert-equals.m

26 lines
1.2 KiB
Objective-C

// RUN: %check_clang_tidy %s objc-assert-equals %t -- -- -I %S/Inputs/objc-assert
#include "XCTestAssertions.h"
// Can't reference NSString directly so we use this getStr() instead.
__typeof(@"abc") getStr() {
return @"abc";
}
void foo() {
XCTAssertEqual(getStr(), @"abc");
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
// CHECK-FIXES: XCTAssertEqualObjects(getStr(), @"abc");
XCTAssertEqual(@"abc", @"abc");
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
// CHECK-FIXES: XCTAssertEqualObjects(@"abc", @"abc");
XCTAssertEqual(@"abc", getStr());
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
// CHECK-FIXES: XCTAssertEqualObjects(@"abc", getStr());
XCTAssertEqual(getStr(), getStr());
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use XCTAssertEqualObjects for comparing objects
// CHECK-FIXES: XCTAssertEqualObjects(getStr(), getStr());
// Primitive types should be ok
XCTAssertEqual(123, 123);
XCTAssertEqual(123.0, 123.45);
// FIXME: This is the case where we don't diagnose properly.
// XCTAssertEqual(@"abc" != @"abc", @"xyz" != @"xyz")
}