From 794543d1e4dc1926b2a1fe3e29bc8b842cad3707 Mon Sep 17 00:00:00 2001 From: Vyacheslav Khorkov Date: Sun, 10 Mar 2024 00:28:32 +0500 Subject: [PATCH] Remove RugbyPods scheme after testing --- .../Core/Test/TestManager.swift | 25 +++++++++++++------ .../Core/Test/TestManagerTests.swift | 14 +++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Sources/RugbyFoundation/Core/Test/TestManager.swift b/Sources/RugbyFoundation/Core/Test/TestManager.swift index 2c6b2ddf..2e682e9a 100644 --- a/Sources/RugbyFoundation/Core/Test/TestManager.swift +++ b/Sources/RugbyFoundation/Core/Test/TestManager.swift @@ -134,17 +134,26 @@ final class TestManager: Loggable { } let processInterruptionTask = processMonitor.runOnInterruption(cleanup) - defer { + let deleteTestsTargetScheme = { + try await self.xcodeProject.deleteTargets([testsTarget.uuid: testsTarget]) + } + do { + try await xcodeBuild.test( + scheme: testsTarget.name, + testPlan: testplanPath.deletingPathExtension().lastPathComponent, + simulatorName: simulatorName, + options: options, + paths: paths + ) + try await deleteTestsTargetScheme() + processInterruptionTask.cancel() + cleanup() + } catch { + try await deleteTestsTargetScheme() processInterruptionTask.cancel() cleanup() + throw error } - try await xcodeBuild.test( - scheme: testsTarget.name, - testPlan: testplanPath.deletingPathExtension().lastPathComponent, - simulatorName: simulatorName, - options: options, - paths: paths - ) }) } diff --git a/Tests/FoundationTests/Core/Test/TestManagerTests.swift b/Tests/FoundationTests/Core/Test/TestManagerTests.swift index 917adbbd..cdc38b37 100644 --- a/Tests/FoundationTests/Core/Test/TestManagerTests.swift +++ b/Tests/FoundationTests/Core/Test/TestManagerTests.swift @@ -249,6 +249,7 @@ extension TestManagerTests { let testplanURL = URL(fileURLWithPath: "tests/Rugby.xctestplan") testplanEditor.createTestplanTestplanTemplatePathTestTargetsInFolderPathReturnValue = testplanURL let testsTarget = IInternalTargetMock() + testsTarget.underlyingUuid = "test_RugbyPods_uuid" testsTarget.underlyingName = "RugbyPods" testsTarget.explicitDependencies = [ localPodFrameworkUnitTests.uuid: localPodFrameworkUnitTests, @@ -397,6 +398,12 @@ extension TestManagerTests { XCTAssertEqual(loggerBlockInvocations[9].level, .result) XCTAssertEqual(loggerBlockInvocations[9].output, .all) + XCTAssertEqual(xcodeProject.deleteTargetsKeepGroupsCallsCount, 1) + let deleteTargetsArgs = try XCTUnwrap(xcodeProject.deleteTargetsKeepGroupsReceivedArguments) + XCTAssertEqual(deleteTargetsArgs.targetsForRemove.count, 1) + XCTAssertTrue(deleteTargetsArgs.targetsForRemove.contains(testsTarget.uuid)) + XCTAssertTrue(deleteTargetsArgs.keepGroups) + XCTAssertEqual(loggerBlockInvocations[10].header, "Marking Tests as Passed") XCTAssertNil(loggerBlockInvocations[10].footer) XCTAssertNil(loggerBlockInvocations[10].metricKey) @@ -515,6 +522,7 @@ extension TestManagerTests { let testplanURL = URL(fileURLWithPath: "tests/Rugby.xctestplan") testplanEditor.createTestplanTestplanTemplatePathTestTargetsInFolderPathReturnValue = testplanURL let testsTarget = IInternalTargetMock() + testsTarget.underlyingUuid = "test_RugbyPods_uuid" testsTarget.underlyingName = "RugbyPods" testsTarget.explicitDependencies = [ localPodFrameworkUnitTests.uuid: localPodFrameworkUnitTests, @@ -664,6 +672,12 @@ extension TestManagerTests { XCTAssertEqual(loggerBlockInvocations[9].level, .result) XCTAssertEqual(loggerBlockInvocations[9].output, .all) + XCTAssertEqual(xcodeProject.deleteTargetsKeepGroupsCallsCount, 1) + let deleteTargetsArgs = try XCTUnwrap(xcodeProject.deleteTargetsKeepGroupsReceivedArguments) + XCTAssertEqual(deleteTargetsArgs.targetsForRemove.count, 1) + XCTAssertTrue(deleteTargetsArgs.targetsForRemove.contains(testsTarget.uuid)) + XCTAssertTrue(deleteTargetsArgs.keepGroups) + XCTAssertEqual(logger.logLevelOutputReceivedInvocations.count, 4) XCTAssertEqual(logger.logLevelOutputReceivedInvocations[0].text, "LocalPod-framework-Unit-Tests") XCTAssertEqual(logger.logLevelOutputReceivedInvocations[0].output, .all)