Skip to content

Commit

Permalink
Turbo mode (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Gerasymenko <michael.gerasymenko@tamara.co>
  • Loading branch information
mikeger and Michael Gerasymenko authored Jun 4, 2024
1 parent 25d2ad3 commit 3ff3f57
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
13 changes: 9 additions & 4 deletions Sources/DependencyCalculator/DependencyCalculator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import SelectiveTestLogger
import Workspace

public extension WorkspaceInfo {
func affectedTargets(changedFiles: Set<Path>) -> Set<TargetIdentity> {
func affectedTargets(changedFiles: Set<Path>,
incldueIndirectlyAffected: Bool = true) -> Set<TargetIdentity> {
var result = Set<TargetIdentity>()

for path in changedFiles {
Expand All @@ -20,9 +21,13 @@ public extension WorkspaceInfo {
Logger.message("Changed file at \(path) appears not to belong to any target")
}
}

let indirectlyAffected = indirectlyAffectedTargets(targets: result)
return result.union(indirectlyAffected)
if incldueIndirectlyAffected {
let indirectlyAffected = indirectlyAffectedTargets(targets: result)
return result.union(indirectlyAffected)
}
else {
return result
}
}

internal func targetForFolder(_ path: Path) -> TargetIdentity? {
Expand Down
6 changes: 5 additions & 1 deletion Sources/SelectiveTestingCore/SelectiveTestingTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public final class SelectiveTestingTool {
private let basePath: Path
private let printJSON: Bool
private let renderDependencyGraph: Bool
private let turbo: Bool
private let dot: Bool
private let verbose: Bool
private let testPlan: String?
Expand All @@ -27,6 +28,7 @@ public final class SelectiveTestingTool {
printJSON: Bool = false,
renderDependencyGraph: Bool = false,
dot: Bool = false,
turbo: Bool = false,
verbose: Bool = false) throws
{
if let configData = try? (Path.current + Config.defaultConfigName).read(),
Expand All @@ -46,6 +48,7 @@ public final class SelectiveTestingTool {
self.basePath = Path(finalBasePath)
self.printJSON = printJSON
self.renderDependencyGraph = renderDependencyGraph
self.turbo = turbo
self.dot = dot
self.verbose = verbose
self.testPlan = testPlan ?? config?.testPlan
Expand All @@ -70,7 +73,8 @@ public final class SelectiveTestingTool {
exclude: config?.exclude ?? [])

// 3. Find affected targets
let affectedTargets = workspaceInfo.affectedTargets(changedFiles: changeset)
let affectedTargets = workspaceInfo.affectedTargets(changedFiles: changeset,
incldueIndirectlyAffected: !turbo)

if renderDependencyGraph {
try Shell.exec("open -a Safari \"\(workspaceInfo.dependencyStructure.mermaidInURL(highlightTargets: affectedTargets))\"")
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 @@ -28,6 +28,9 @@ struct SelectiveTesting: AsyncParsableCommand {
@Flag(help: "Output dependency graph in Dot (Graphviz) format")
var dot: Bool = false

@Flag(help: "Turbo mode: run directly affected tests only")
var turbo: Bool = false

@Flag(help: "Produce verbose output")
var verbose: Bool = false

Expand All @@ -38,6 +41,7 @@ struct SelectiveTesting: AsyncParsableCommand {
printJSON: JSON,
renderDependencyGraph: dependencyGraph,
dot: dot,
turbo: turbo,
verbose: verbose)
let _ = try await tool.run()
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/SelectiveTestingTests/IntegrationTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ final class IntegrationTestTool {

func createSUT(config: Config? = nil,
basePath: Path? = nil,
testPlan: String? = nil) throws -> SelectiveTestingTool
testPlan: String? = nil,
turbo: Bool = false) throws -> SelectiveTestingTool
{
if let config {
let configText = try config.save()
print("config: \(configText)")
let path = Path.current + Config.defaultConfigName
try configText.write(toFile: path.string, atomically: true, encoding: .utf8)
}
Expand All @@ -73,6 +73,7 @@ final class IntegrationTestTool {
basePath: basePath?.string,
testPlan: testPlan,
renderDependencyGraph: false,
turbo: turbo,
verbose: true)
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/SelectiveTestingTests/SelectiveTestingProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ final class SelectiveTestingProjectTests: XCTestCase {
]))
}

func testProjectAlone_turbo() async throws {
// given
let tool = try testTool.createSUT(config: nil,
basePath: "ExampleProject.xcodeproj",
turbo: true)
// when
try testTool.changeFile(at: testTool.projectPath + "ExampleProject/Deep/Path/ContentView.swift")

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

func testProjectDeepPathChange() async throws {
// given
let tool = try testTool.createSUT(config: nil,
Expand Down

0 comments on commit 3ff3f57

Please sign in to comment.