@@ -13,33 +13,18 @@ extension XcodeSchemeTests {
13
13
}
14
14
15
15
func test_BuildAction_init_withDuplicateLabels( ) throws {
16
- var thrown : Error ?
17
- XCTAssertThrowsError (
16
+ assertPreconditionError (
18
17
try XcodeScheme . BuildAction (
19
18
targets: [ . init( label: " //foo " ) , . init( label: " //foo " ) ]
20
- )
21
- ) {
22
- thrown = $0
23
- }
24
- guard let preconditionError = thrown as? PreconditionError else {
25
- XCTFail ( " Expected `PreconditionError`. " )
26
- return
27
- }
28
- XCTAssertEqual ( preconditionError. message, """
19
+ ) ,
20
+ expectedMessage: """
29
21
Found a duplicate label //foo:foo in provided `XcodeScheme.BuildTarget` values.
30
- """ )
22
+ """
23
+ )
31
24
}
32
25
33
26
func test_BuildAction_init_noTargets( ) throws {
34
- var thrown : Error ?
35
- XCTAssertThrowsError ( try XcodeScheme . BuildAction ( targets: [ ] ) ) {
36
- thrown = $0
37
- }
38
- guard let preconditionError = thrown as? PreconditionError else {
39
- XCTFail ( " Expected , but was \( String ( describing: thrown) ) . " )
40
- return
41
- }
42
- XCTAssertEqual ( preconditionError. message, """
27
+ assertPreconditionError ( try XcodeScheme . BuildAction ( targets: [ ] ) , expectedMessage: """
43
28
No `XcodeScheme.BuildTarget` values were provided to `XcodeScheme.BuildAction`.
44
29
""" )
45
30
}
@@ -49,15 +34,7 @@ No `XcodeScheme.BuildTarget` values were provided to `XcodeScheme.BuildAction`.
49
34
50
35
extension XcodeSchemeTests {
51
36
func test_TestAction_init_noTargets( ) throws {
52
- var thrown : Error ?
53
- XCTAssertThrowsError ( try XcodeScheme . TestAction ( targets: [ ] ) ) {
54
- thrown = $0
55
- }
56
- guard let preconditionError = thrown as? PreconditionError else {
57
- XCTFail ( " Expected , but was \( String ( describing: thrown) ) . " )
58
- return
59
- }
60
- XCTAssertEqual ( preconditionError. message, """
37
+ assertPreconditionError ( try XcodeScheme . TestAction ( targets: [ ] ) , expectedMessage: """
61
38
No `BazelLabel` values were provided to `XcodeScheme.TestAction`.
62
39
""" )
63
40
}
@@ -72,15 +49,7 @@ No `BazelLabel` values were provided to `XcodeScheme.TestAction`.
72
49
73
50
extension XcodeSchemeTests {
74
51
func test_XcodeScheme_init_noActions( ) throws {
75
- var thrown : Error ?
76
- XCTAssertThrowsError ( try XcodeScheme ( name: " Foo " ) ) {
77
- thrown = $0
78
- }
79
- guard let preconditionError = thrown as? PreconditionError else {
80
- XCTFail ( " Expected , but was \( String ( describing: thrown) ) . " )
81
- return
82
- }
83
- XCTAssertEqual ( preconditionError. message, """
52
+ assertPreconditionError ( try XcodeScheme ( name: " Foo " ) , expectedMessage: """
84
53
No actions were provided for the scheme " Foo " .
85
54
""" )
86
55
}
@@ -188,27 +157,6 @@ extension XcodeSchemeTests {
188
157
XCTAssertEqual ( actual, expected)
189
158
}
190
159
191
- func assertUsageError< T> (
192
- _ closure: @autoclosure ( ) throws -> T ,
193
- expectedMessage: String ,
194
- file: StaticString = #filePath,
195
- line: UInt = #line
196
- ) {
197
- var thrown : Error ?
198
- XCTAssertThrowsError ( try closure ( ) , file: file, line: line) {
199
- thrown = $0
200
- }
201
- guard let usageError = thrown as? UsageError else {
202
- XCTFail (
203
- " Expected `UsageError`, but was \( String ( describing: thrown) ) . " ,
204
- file: file,
205
- line: line
206
- )
207
- return
208
- }
209
- XCTAssertEqual ( usageError. message, expectedMessage, file: file, line: line)
210
- }
211
-
212
160
func test_XcodeScheme_withDefaults_withBuild_withLaunch_runningDisabled( ) throws {
213
161
let xcodeScheme = try XcodeScheme (
214
162
name: schemeName,
@@ -235,18 +183,6 @@ disabled, but the target is referenced in the scheme's launch action.
235
183
The buildFor value, " profiling " , for " \( macOSAppLabel) " in the " \( schemeName) " Xcode scheme was \
236
184
disabled, but the target is referenced in the scheme's profile action.
237
185
""" )
238
- // var thrown: Error?
239
- // XCTAssertThrowsError(try xcodeScheme.withDefaults) {
240
- // thrown = $0
241
- // }
242
- // guard let preconditionError = thrown as? PreconditionError else {
243
- // XCTFail("Expected `PreconditionError`, but was \(String(describing: thrown)).")
244
- // return
245
- // }
246
- // XCTAssertEqual(preconditionError.message, """
247
- // Failed to merge `profiling` value for "\(macOSAppLabel)" with `.enabled`. Hint: This usually means \
248
- // the other value is `.disabled`.
249
- // """)
250
186
}
251
187
252
188
func test_XcodeScheme_withDefaults_withBuild_withTest_testingDisabled( ) throws {
@@ -261,18 +197,6 @@ disabled, but the target is referenced in the scheme's profile action.
261
197
The buildFor value, " testing " , for " \( unitTestLabel) " in the " \( schemeName) " Xcode scheme was \
262
198
disabled, but the target is referenced in the scheme's test action.
263
199
""" )
264
- // var thrown: Error?
265
- // XCTAssertThrowsError(try xcodeScheme.withDefaults) {
266
- // thrown = $0
267
- // }
268
- // guard let preconditionError = thrown as? PreconditionError else {
269
- // XCTFail("Expected `PreconditionError`, but was \(String(describing: thrown)).")
270
- // return
271
- // }
272
- // XCTAssertEqual(preconditionError.message, """
273
- // Failed to merge `testing` value for "\(unitTestLabel)" with `.enabled`. Hint: This usually means \
274
- // the other value is `.disabled`.
275
- // """)
276
200
}
277
201
278
202
func test_XcodeScheme_withDefaults_noTargetsWithRunningEnabled( ) throws {
@@ -293,6 +217,52 @@ disabled, but the target is referenced in the scheme's test action.
293
217
}
294
218
}
295
219
220
+ // MARK: Assertions
221
+
222
+ extension XcodeSchemeTests {
223
+ func assertUsageError< T> (
224
+ _ closure: @autoclosure ( ) throws -> T ,
225
+ expectedMessage: String ,
226
+ file: StaticString = #filePath,
227
+ line: UInt = #line
228
+ ) {
229
+ var thrown : Error ?
230
+ XCTAssertThrowsError ( try closure ( ) , file: file, line: line) {
231
+ thrown = $0
232
+ }
233
+ guard let usageError = thrown as? UsageError else {
234
+ XCTFail (
235
+ " Expected `UsageError`, but was \( String ( describing: thrown) ) . " ,
236
+ file: file,
237
+ line: line
238
+ )
239
+ return
240
+ }
241
+ XCTAssertEqual ( usageError. message, expectedMessage, file: file, line: line)
242
+ }
243
+
244
+ func assertPreconditionError< T> (
245
+ _ closure: @autoclosure ( ) throws -> T ,
246
+ expectedMessage: String ,
247
+ file: StaticString = #filePath,
248
+ line: UInt = #line
249
+ ) {
250
+ var thrown : Error ?
251
+ XCTAssertThrowsError ( try closure ( ) , file: file, line: line) {
252
+ thrown = $0
253
+ }
254
+ guard let preconditionError = thrown as? PreconditionError else {
255
+ XCTFail (
256
+ " Expected `PreconditionError`, but was \( String ( describing: thrown) ) . " ,
257
+ file: file,
258
+ line: line
259
+ )
260
+ return
261
+ }
262
+ XCTAssertEqual ( preconditionError. message, expectedMessage, file: file, line: line)
263
+ }
264
+ }
265
+
296
266
// MARK: `BuildAction.init` Tests
297
267
298
268
class XcodeSchemeTests : XCTestCase {
0 commit comments