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
18 changes: 13 additions & 5 deletions Sources/SelectiveTestingCore/SelectiveTestingTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public final class SelectiveTestingTool {
private let baseBranch: String?
private let basePath: Path
private let printJSON: Bool
private let changedFiles: [String]
private let renderDependencyGraph: Bool
private let turbo: Bool
private let dot: Bool
Expand All @@ -25,6 +26,7 @@ public final class SelectiveTestingTool {
public init(baseBranch: String?,
basePath: String?,
testPlan: String?,
changedFiles: [String],
printJSON: Bool = false,
renderDependencyGraph: Bool = false,
dot: Bool = false,
Expand All @@ -46,6 +48,7 @@ public final class SelectiveTestingTool {

self.baseBranch = baseBranch
self.basePath = Path(finalBasePath)
self.changedFiles = changedFiles
self.printJSON = printJSON
self.renderDependencyGraph = renderDependencyGraph
self.turbo = turbo
Expand All @@ -58,11 +61,16 @@ public final class SelectiveTestingTool {
// 1. Identify changed files
let changeset: Set<Path>

Logger.message("Finding changeset for repository at \(basePath)")
if let baseBranch {
changeset = try Git(path: basePath).changeset(baseBranch: baseBranch, verbose: verbose)
} else {
changeset = try Git(path: basePath).localChangeset()
if changedFiles.isEmpty {
Logger.message("Finding changeset for repository at \(basePath)")
if let baseBranch {
changeset = try Git(path: basePath).changeset(baseBranch: baseBranch, verbose: verbose)
} else {
changeset = try Git(path: basePath).localChangeset()
}
}
else {
changeset = Set(changedFiles.map { Path($0).absolute() })
}

if verbose { Logger.message("Changed files: \(changeset)") }
Expand Down
4 changes: 4 additions & 0 deletions Sources/xcode-selective-test/SelectiveTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ struct SelectiveTesting: AsyncParsableCommand {
@Argument(help: "Project, workspace or package path", completion: .file(extensions: ["xcworkspace", "xcodeproj"]))
var basePath: String?

@Option(name: [.customShort("c"), .long], parsing: .upToNextOption, help: "List of changed files")
var changedFiles: [String] = []

@Option(name: .long, help: "Name of the base branch")
var baseBranch: String?

Expand All @@ -38,6 +41,7 @@ struct SelectiveTesting: AsyncParsableCommand {
let tool = try SelectiveTestingTool(baseBranch: baseBranch,
basePath: basePath,
testPlan: testPlan,
changedFiles: changedFiles,
printJSON: JSON,
renderDependencyGraph: dependencyGraph,
dot: dot,
Expand Down
3 changes: 3 additions & 0 deletions Tests/SelectiveTestingTests/IntegrationTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ final class IntegrationTestTool {
func createSUT(config: Config? = nil,
basePath: Path? = nil,
testPlan: String? = nil,
changedFiles: [String] = [],
turbo: Bool = false) throws -> SelectiveTestingTool
{
if let config {
Expand All @@ -72,6 +73,7 @@ final class IntegrationTestTool {
return try SelectiveTestingTool(baseBranch: "main",
basePath: basePath?.string,
testPlan: testPlan,
changedFiles: changedFiles,
renderDependencyGraph: false,
turbo: turbo,
verbose: true)
Expand All @@ -81,6 +83,7 @@ final class IntegrationTestTool {
return try SelectiveTestingTool(baseBranch: "main",
basePath: (projectPath + "ExampleWorkspace.xcworkspace").string,
testPlan: "ExampleProject.xctestplan",
changedFiles: [],
renderDependencyGraph: false,
verbose: true)
}
Expand Down
16 changes: 16 additions & 0 deletions Tests/SelectiveTestingTests/SelectiveTestingProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,20 @@ final class SelectiveTestingProjectTests: XCTestCase {
testTool.mainProjectUITests,
]))
}

func testPassingChangedFiles() async throws {
// given & when
let changedPath = testTool.projectPath + "ExampleProject/Base.lproj/Example.xib"
let tool = try testTool.createSUT(config: nil,
basePath: "ExampleProject.xcodeproj",
changedFiles: [changedPath.string])

// then
let result = try await tool.run()
XCTAssertEqual(result, Set([
testTool.mainProjectMainTarget,
testTool.mainProjectTests,
testTool.mainProjectUITests,
]))
}
}