Skip to content

Commit be3a667

Browse files
authored
55: Flag --dry-run (#59)
1 parent adbdf89 commit be3a667

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

Sources/SelectiveTestingCore/SelectiveTestingTool.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public final class SelectiveTestingTool {
1818
private let changedFiles: [String]
1919
private let renderDependencyGraph: Bool
2020
private let turbo: Bool
21+
private let dryRun: Bool
2122
private let dot: Bool
2223
private let verbose: Bool
2324
private let testPlan: String?
@@ -31,6 +32,7 @@ public final class SelectiveTestingTool {
3132
renderDependencyGraph: Bool = false,
3233
dot: Bool = false,
3334
turbo: Bool = false,
35+
dryRun: Bool = false,
3436
verbose: Bool = false) throws
3537
{
3638
if let configData = try? (Path.current + Config.defaultConfigName).read(),
@@ -53,6 +55,7 @@ public final class SelectiveTestingTool {
5355
self.renderDependencyGraph = renderDependencyGraph
5456
self.turbo = turbo
5557
self.dot = dot
58+
self.dryRun = dryRun
5659
self.verbose = verbose
5760
self.testPlan = testPlan ?? config?.testPlan
5861
}
@@ -127,11 +130,11 @@ public final class SelectiveTestingTool {
127130
}
128131
}
129132

130-
if let testPlan {
133+
if !dryRun, let testPlan {
131134
// 4. Configure workspace to test given targets
132135
try enableTests(at: Path(testPlan),
133136
targetsToTest: affectedTargets)
134-
} else if let testPlan = workspaceInfo.candidateTestPlan {
137+
} else if !dryRun, let testPlan = workspaceInfo.candidateTestPlan {
135138
try enableTests(at: Path(testPlan),
136139
targetsToTest: affectedTargets)
137140
} else if !printJSON {

Sources/xcode-selective-test/SelectiveTesting.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct SelectiveTesting: AsyncParsableCommand {
3434
@Flag(help: "Turbo mode: run directly affected tests only")
3535
var turbo: Bool = false
3636

37+
@Flag(help: "Dry run: do not modify the test plans")
38+
var dryRun: Bool = false
39+
3740
@Flag(help: "Produce verbose output")
3841
var verbose: Bool = false
3942

Tests/SelectiveTestingTests/IntegrationTestTool.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ final class IntegrationTestTool {
109109

110110
XCTAssertEqual(Set(testPlanTargets), expected)
111111
}
112+
113+
func checkTestPlanUnmodified(at newPath: Path) throws {
114+
guard let exampleInBundle = Bundle.module.path(forResource: "ExampleProject", ofType: "") else {
115+
fatalError("Missing ExampleProject in TestBundle")
116+
}
117+
let orignialTestPlanPath = Path(exampleInBundle) + Path(newPath.lastComponent)
118+
let originalContents = try String(contentsOfFile: orignialTestPlanPath.string)
119+
120+
let newContents = try String(contentsOfFile: newPath.string)
121+
XCTAssertEqual(originalContents, newContents)
122+
}
112123

113124
lazy var mainProjectMainTarget = TargetIdentity.project(path: projectPath + "ExampleProject.xcodeproj", targetName: "ExampleProject", testTarget: false)
114125
lazy var mainProjectTests = TargetIdentity.project(path: projectPath + "ExampleProject.xcodeproj", targetName: "ExampleProjectTests", testTarget: true)

Tests/SelectiveTestingTests/SelectiveTestingConfigTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,22 @@ final class SelectiveTestingConfigTests: XCTestCase {
162162
try testTool.validateTestPlan(testPlanPath: testTool.projectPath + "ExampleProject.xctestplan",
163163
expected: Set([testTool.subtests]))
164164
}
165+
166+
func testDryRun() async throws {
167+
// given
168+
let tool = try SelectiveTestingTool(baseBranch: "main",
169+
basePath: (testTool.projectPath + "ExampleWorkspace.xcworkspace").string,
170+
testPlan: "ExampleProject.xctestplan",
171+
changedFiles: [],
172+
renderDependencyGraph: false,
173+
dryRun: true,
174+
verbose: true)
175+
176+
// when
177+
try testTool.changeFile(at: testTool.projectPath + "ExamplePackage/Tests/Subtests/Test.swift")
178+
179+
// then
180+
let _ = try await tool.run()
181+
try testTool.checkTestPlanUnmodified(at: testTool.projectPath + "ExampleProject.xctestplan")
182+
}
165183
}

0 commit comments

Comments
 (0)