diff --git a/Sources/SelectiveTestingCore/SelectiveTestingTool.swift b/Sources/SelectiveTestingCore/SelectiveTestingTool.swift index 6ded595..9bef42a 100644 --- a/Sources/SelectiveTestingCore/SelectiveTestingTool.swift +++ b/Sources/SelectiveTestingCore/SelectiveTestingTool.swift @@ -18,6 +18,7 @@ public final class SelectiveTestingTool { private let changedFiles: [String] private let renderDependencyGraph: Bool private let turbo: Bool + private let dryRun: Bool private let dot: Bool private let verbose: Bool private let testPlan: String? @@ -31,6 +32,7 @@ public final class SelectiveTestingTool { renderDependencyGraph: Bool = false, dot: Bool = false, turbo: Bool = false, + dryRun: Bool = false, verbose: Bool = false) throws { if let configData = try? (Path.current + Config.defaultConfigName).read(), @@ -53,6 +55,7 @@ public final class SelectiveTestingTool { self.renderDependencyGraph = renderDependencyGraph self.turbo = turbo self.dot = dot + self.dryRun = dryRun self.verbose = verbose self.testPlan = testPlan ?? config?.testPlan } @@ -127,11 +130,11 @@ public final class SelectiveTestingTool { } } - if let testPlan { + if !dryRun, let testPlan { // 4. Configure workspace to test given targets try enableTests(at: Path(testPlan), targetsToTest: affectedTargets) - } else if let testPlan = workspaceInfo.candidateTestPlan { + } else if !dryRun, let testPlan = workspaceInfo.candidateTestPlan { try enableTests(at: Path(testPlan), targetsToTest: affectedTargets) } else if !printJSON { diff --git a/Sources/xcode-selective-test/SelectiveTesting.swift b/Sources/xcode-selective-test/SelectiveTesting.swift index 5429fed..e48042d 100644 --- a/Sources/xcode-selective-test/SelectiveTesting.swift +++ b/Sources/xcode-selective-test/SelectiveTesting.swift @@ -34,6 +34,9 @@ struct SelectiveTesting: AsyncParsableCommand { @Flag(help: "Turbo mode: run directly affected tests only") var turbo: Bool = false + @Flag(help: "Dry run: do not modify the test plans") + var dryRun: Bool = false + @Flag(help: "Produce verbose output") var verbose: Bool = false diff --git a/Tests/SelectiveTestingTests/IntegrationTestTool.swift b/Tests/SelectiveTestingTests/IntegrationTestTool.swift index 0b217bd..4858ea9 100644 --- a/Tests/SelectiveTestingTests/IntegrationTestTool.swift +++ b/Tests/SelectiveTestingTests/IntegrationTestTool.swift @@ -109,6 +109,17 @@ final class IntegrationTestTool { XCTAssertEqual(Set(testPlanTargets), expected) } + + func checkTestPlanUnmodified(at newPath: Path) throws { + guard let exampleInBundle = Bundle.module.path(forResource: "ExampleProject", ofType: "") else { + fatalError("Missing ExampleProject in TestBundle") + } + let orignialTestPlanPath = Path(exampleInBundle) + Path(newPath.lastComponent) + let originalContents = try String(contentsOfFile: orignialTestPlanPath.string) + + let newContents = try String(contentsOfFile: newPath.string) + XCTAssertEqual(originalContents, newContents) + } lazy var mainProjectMainTarget = TargetIdentity.project(path: projectPath + "ExampleProject.xcodeproj", targetName: "ExampleProject", testTarget: false) lazy var mainProjectTests = TargetIdentity.project(path: projectPath + "ExampleProject.xcodeproj", targetName: "ExampleProjectTests", testTarget: true) diff --git a/Tests/SelectiveTestingTests/SelectiveTestingConfigTests.swift b/Tests/SelectiveTestingTests/SelectiveTestingConfigTests.swift index 48130b4..391b8d8 100644 --- a/Tests/SelectiveTestingTests/SelectiveTestingConfigTests.swift +++ b/Tests/SelectiveTestingTests/SelectiveTestingConfigTests.swift @@ -162,4 +162,22 @@ final class SelectiveTestingConfigTests: XCTestCase { try testTool.validateTestPlan(testPlanPath: testTool.projectPath + "ExampleProject.xctestplan", expected: Set([testTool.subtests])) } + + func testDryRun() async throws { + // given + let tool = try SelectiveTestingTool(baseBranch: "main", + basePath: (testTool.projectPath + "ExampleWorkspace.xcworkspace").string, + testPlan: "ExampleProject.xctestplan", + changedFiles: [], + renderDependencyGraph: false, + dryRun: true, + verbose: true) + + // when + try testTool.changeFile(at: testTool.projectPath + "ExamplePackage/Tests/Subtests/Test.swift") + + // then + let _ = try await tool.run() + try testTool.checkTestPlanUnmodified(at: testTool.projectPath + "ExampleProject.xctestplan") + } }