Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Sources/SelectiveTestingCore/SelectiveTestingTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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(),
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions Sources/xcode-selective-test/SelectiveTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions Tests/SelectiveTestingTests/IntegrationTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions Tests/SelectiveTestingTests/SelectiveTestingConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}