Skip to content

Commit 65d7860

Browse files
committed
Fix GenerableTests on Xcode 16.2
1 parent 4c113d0 commit 65d7860

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

FirebaseAI/Tests/Unit/Types/Generable/GenerableTests.swift

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,28 @@ struct GenerableTests {
4747
properties: properties, uniquingKeysWith: { _, second in second }
4848
)
4949

50-
let error = try #require(throws: GenerativeModel.GenerationError.self) {
51-
try Person(modelOutput)
52-
}
53-
54-
guard case let .decodingFailure(context) = error else {
50+
do {
51+
_ = try Person(modelOutput)
52+
Issue.record("Did not throw an error.")
53+
} catch let GenerativeModel.GenerationError.decodingFailure(context) {
54+
#expect(context.debugDescription.contains("lastName"))
55+
} catch {
5556
Issue.record("Threw an unexpected error: \(error)")
56-
return
5757
}
58-
#expect(context.debugDescription.contains("lastName"))
5958
}
6059

6160
@Test
6261
func initializeGenerableFromNonStructureThrows() throws {
6362
let modelOutput = ModelOutput("not a structure")
6463

65-
let error = try #require(throws: GenerativeModel.GenerationError.self) {
66-
try Person(modelOutput)
67-
}
68-
69-
guard case let .decodingFailure(context) = error else {
64+
do {
65+
_ = try Person(modelOutput)
66+
Issue.record("Did not throw an error.")
67+
} catch let GenerativeModel.GenerationError.decodingFailure(context) {
68+
#expect(context.debugDescription.contains("does not contain an object"))
69+
} catch {
7070
Issue.record("Threw an unexpected error: \(error)")
71-
return
7271
}
73-
#expect(context.debugDescription.contains("does not contain an object"))
7472
}
7573

7674
@Test
@@ -81,15 +79,14 @@ struct GenerableTests {
8179
properties: properties, uniquingKeysWith: { _, second in second }
8280
)
8381

84-
let error = try #require(throws: GenerativeModel.GenerationError.self) {
85-
try Person(modelOutput)
86-
}
87-
88-
guard case let .decodingFailure(context) = error else {
82+
do {
83+
_ = try Person(modelOutput)
84+
Issue.record("Did not throw an error.")
85+
} catch let GenerativeModel.GenerationError.decodingFailure(context) {
86+
#expect(context.debugDescription.contains("\"forty\" does not contain Int"))
87+
} catch {
8988
Issue.record("Threw an unexpected error: \(error)")
90-
return
9189
}
92-
#expect(context.debugDescription.contains("\"forty\" does not contain Int"))
9390
}
9491

9592
@Test
@@ -100,15 +97,14 @@ struct GenerableTests {
10097
properties: properties, uniquingKeysWith: { _, second in second }
10198
)
10299

103-
let error = try #require(throws: GenerativeModel.GenerationError.self) {
104-
try Person(modelOutput)
105-
}
106-
107-
guard case let .decodingFailure(context) = error else {
100+
do {
101+
_ = try Person(modelOutput)
102+
Issue.record("Did not throw an error.")
103+
} catch let GenerativeModel.GenerationError.decodingFailure(context) {
104+
#expect(context.debugDescription.contains("40.5 does not contain Int."))
105+
} catch {
108106
Issue.record("Threw an unexpected error: \(error)")
109-
return
110107
}
111-
#expect(context.debugDescription.contains("40.5 does not contain Int."))
112108
}
113109

114110
@Test

0 commit comments

Comments
 (0)