Skip to content

Commit 47fcf14

Browse files
authored
Fix FSTGoogleTestTests under Xcode 12 (#6478)
The bridge from GoogleTest to XCTest recorded failures using recordFailureWithDescription:inFile:atLine:expected:, which has been deprecated.
1 parent 100e2fa commit 47fcf14

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Firestore/core/test/unit/FSTGoogleTestTests.mm

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,30 @@ void XCTestMethod(XCTestCase* self, SEL _cmd) {
221221
int parts = result->total_part_count();
222222
for (int i = 0; i < parts; i++) {
223223
const testing::TestPartResult& part = result->GetTestPartResult(i);
224-
[self
225-
recordFailureWithDescription:@(part.message())
226-
inFile:@(part.file_name() ? part.file_name() : "")
227-
atLine:(part.line_number() > 0
228-
? part.line_number()
229-
: 0)
230-
expected:true];
224+
const char* path = part.file_name() ? part.file_name() : "";
225+
int line = part.line_number() > 0 ? part.line_number() : 0;
226+
227+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
228+
// Xcode 12
229+
auto* location = [[XCTSourceCodeLocation alloc] initWithFilePath:@(path)
230+
lineNumber:line];
231+
auto* context = [[XCTSourceCodeContext alloc] initWithLocation:location];
232+
auto* issue = [[XCTIssue alloc] initWithType:XCTIssueTypeAssertionFailure
233+
compactDescription:@(part.summary())
234+
detailedDescription:@(part.message())
235+
sourceCodeContext:context
236+
associatedError:nil
237+
attachments:@[]];
238+
[self recordIssue:issue];
239+
240+
#else
241+
// Xcode 11 and prior. recordFailureWithDescription:inFile:atLine:expected:
242+
// is deprecated in Xcode 12.
243+
[self recordFailureWithDescription:@(part.message())
244+
inFile:@(path)
245+
atLine:line
246+
expected:true];
247+
#endif
231248
}
232249
}
233250

0 commit comments

Comments
 (0)