Skip to content

Commit 2245558

Browse files
Improve EndToEndTests cleanup, DRY out test case methods
1 parent c62d022 commit 2245558

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

Tests/SwiftSDKGeneratorTests/EndToEndTests.swift

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ extension FileManager {
3434
try createDirectory(at: temporaryDirectory, withIntermediateDirectories: false)
3535
defer {
3636
// Best effort cleanup.
37-
do {
38-
if cleanup {
39-
try removeItem(at: temporaryDirectory)
40-
logger.info("Removed temporary directory")
41-
} else {
42-
logger.info("Keeping temporary directory")
43-
}
44-
} catch {}
37+
if cleanup {
38+
try? removeItem(at: temporaryDirectory)
39+
logger.info("Removed temporary directory")
40+
} else {
41+
logger.info("Keeping temporary directory")
42+
}
4543
}
4644

4745
logger.info("Created temporary directory")
@@ -274,6 +272,8 @@ func buildTestcase(_ logger: Logger, testcase: String, bundleName: String, tempD
274272
}
275273

276274
func buildTestcases(config: SDKConfiguration) async throws {
275+
try skipSlow()
276+
277277
var logger = Logger(label: "EndToEndTests")
278278
logger[metadataKey: "testcase"] = "testPackageInitExecutable"
279279

@@ -293,17 +293,26 @@ func buildTestcases(config: SDKConfiguration) async throws {
293293
try await buildSDK(logger, scratchPath: tempDir.path, withArguments: config.sdkGeneratorArguments)
294294
}
295295

296-
logger.info("Built SDK")
296+
logger.info("Built Swift SDK")
297+
298+
// Cleanup
299+
let cleanupSdk: () async -> Void = {
300+
logger.info("Removing Swift SDK to cleanup...")
301+
try? await Shell.run("swift experimental-sdk remove \(bundleName)")
302+
}
297303

298304
for testcase in testcases {
299-
try await FileManager.default.withTemporaryDirectory(logger: logger) { tempDir in
300-
try await buildTestcase(logger, testcase: testcase, bundleName: bundleName, tempDir: tempDir)
305+
do {
306+
try await FileManager.default.withTemporaryDirectory(logger: logger) { tempDir in
307+
try await buildTestcase(logger, testcase: testcase, bundleName: bundleName, tempDir: tempDir)
308+
}
309+
} catch {
310+
await cleanupSdk()
311+
throw error
301312
}
302313
}
303314

304-
// Cleanup
305-
logger.info("Removing SDK to cleanup...")
306-
try await Shell.run("swift experimental-sdk remove \(bundleName)")
315+
await cleanupSdk()
307316
}
308317

309318
final class Swift59_UbuntuEndToEndTests: XCTestCase {
@@ -316,22 +325,18 @@ final class Swift59_UbuntuEndToEndTests: XCTestCase {
316325
)
317326

318327
func testAarch64Direct() async throws {
319-
try skipSlow()
320328
try await buildTestcases(config: config.withArchitecture("aarch64"))
321329
}
322330

323331
func testX86_64Direct() async throws {
324-
try skipSlow()
325332
try await buildTestcases(config: config.withArchitecture("x86_64"))
326333
}
327334

328335
func testAarch64FromContainer() async throws {
329-
try skipSlow()
330336
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
331337
}
332338

333339
func testX86_64FromContainer() async throws {
334-
try skipSlow()
335340
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
336341
}
337342
}
@@ -346,22 +351,18 @@ final class Swift510_UbuntuEndToEndTests: XCTestCase {
346351
)
347352

348353
func testAarch64Direct() async throws {
349-
try skipSlow()
350354
try await buildTestcases(config: config.withArchitecture("aarch64"))
351355
}
352356

353357
func testX86_64Direct() async throws {
354-
try skipSlow()
355358
try await buildTestcases(config: config.withArchitecture("x86_64"))
356359
}
357360

358361
func testAarch64FromContainer() async throws {
359-
try skipSlow()
360362
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
361363
}
362364

363365
func testX86_64FromContainer() async throws {
364-
try skipSlow()
365366
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
366367
}
367368
}
@@ -376,22 +377,18 @@ final class Swift60_UbuntuEndToEndTests: XCTestCase {
376377
)
377378

378379
func testAarch64Direct() async throws {
379-
try skipSlow()
380380
try await buildTestcases(config: config.withArchitecture("aarch64"))
381381
}
382382

383383
func testX86_64Direct() async throws {
384-
try skipSlow()
385384
try await buildTestcases(config: config.withArchitecture("x86_64"))
386385
}
387386

388387
func testAarch64FromContainer() async throws {
389-
try skipSlow()
390388
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
391389
}
392390

393391
func testX86_64FromContainer() async throws {
394-
try skipSlow()
395392
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
396393
}
397394
}
@@ -406,12 +403,10 @@ final class Swift59_RHELEndToEndTests: XCTestCase {
406403
)
407404

408405
func testAarch64FromContainer() async throws {
409-
try skipSlow()
410406
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
411407
}
412408

413409
func testX86_64FromContainer() async throws {
414-
try skipSlow()
415410
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
416411
}
417412
}
@@ -426,12 +421,10 @@ final class Swift510_RHELEndToEndTests: XCTestCase {
426421
)
427422

428423
func testAarch64FromContainer() async throws {
429-
try skipSlow()
430424
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
431425
}
432426

433427
func testX86_64FromContainer() async throws {
434-
try skipSlow()
435428
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
436429
}
437430
}
@@ -446,12 +439,10 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
446439
)
447440

448441
func testAarch64FromContainer() async throws {
449-
try skipSlow()
450442
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
451443
}
452444

453445
func testX86_64FromContainer() async throws {
454-
try skipSlow()
455446
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
456447
}
457448
}

0 commit comments

Comments
 (0)