Skip to content

Commit

Permalink
feat: add TestableTarget.parallelization property
Browse files Browse the repository at this point in the history
  • Loading branch information
fortmarek committed Dec 26, 2024
1 parent 0020a01 commit a21a724
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
40 changes: 37 additions & 3 deletions Sources/XcodeGraph/Models/TestableTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,61 @@ import Path

/// Testable target describe target and tests information.
public struct TestableTarget: Equatable, Hashable, Codable, Sendable {
/// With the introduction of Swift Testing and Xcode 16, you can now choose to run your tests
/// in parallel across either the full suite of tests in a target with `.all`, just those created
/// under Swift Testing with `.swiftTestingOnly`, or run them serially with the `.none` option.
public enum Parallelization: Equatable, Hashable, Codable, Sendable {
case none, swiftTestingOnly, all
}

/// The target name and its project path.
public let target: TargetReference
/// Skip test target from TestAction.
public let isSkipped: Bool

/// Execute tests in parallel.
public let isParallelizable: Bool
@available(
*,
deprecated,
renamed: "parallelization",
message: "isParallelizable was deprecated. Use the paralellization property instead."
)
public var isParallelizable: Bool {
parallelization == .none
}

public let parallelization: Parallelization

/// Execute tests in random order.
public let isRandomExecutionOrdering: Bool
/// A simulated location used when testing this test target.
public let simulatedLocation: SimulatedLocation?

@available(*, deprecated, renamed: "init(target:skipped:parallelization:randomExecutionOrdering:simulatedLocation:)")
public init(
target: TargetReference,
skipped: Bool = false,
parallelizable: Bool,
randomExecutionOrdering: Bool = false,
simulatedLocation: SimulatedLocation? = nil
) {
self.target = target
isSkipped = skipped
parallelization = parallelizable ? .all : .none
isRandomExecutionOrdering = randomExecutionOrdering
self.simulatedLocation = simulatedLocation
}

public init(
target: TargetReference,
skipped: Bool = false,
parallelizable: Bool = false,
parallelization: Parallelization = .none,
randomExecutionOrdering: Bool = false,
simulatedLocation: SimulatedLocation? = nil
) {
self.target = target
isSkipped = skipped
isParallelizable = parallelizable
self.parallelization = parallelization
isRandomExecutionOrdering = randomExecutionOrdering
self.simulatedLocation = simulatedLocation
}
Expand Down
18 changes: 17 additions & 1 deletion Tests/XcodeGraphTests/Models/TestableTargetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import XCTest
@testable import XcodeGraph

final class TestableTargetTests: XCTestCase {
func test_codable() {
func test_codable_with_deprecated_parallelizable() {
// Given
let subject = TestableTarget(

Check warning on line 10 in Tests/XcodeGraphTests/Models/TestableTargetTests.swift

View workflow job for this annotation

GitHub Actions / Tuist Build (macos-15)

'init(target:skipped:parallelizable:randomExecutionOrdering:simulatedLocation:)' is deprecated: replaced by 'init(target:skipped:parallelization:randomExecutionOrdering:simulatedLocation:)'

Check warning on line 10 in Tests/XcodeGraphTests/Models/TestableTargetTests.swift

View workflow job for this annotation

GitHub Actions / Tuist Test (macos-15)

'init(target:skipped:parallelizable:randomExecutionOrdering:simulatedLocation:)' is deprecated: replaced by 'init(target:skipped:parallelization:randomExecutionOrdering:simulatedLocation:)'
target: .init(
Expand All @@ -20,4 +20,20 @@ final class TestableTargetTests: XCTestCase {
// Then
XCTAssertCodable(subject)
}

func test_codable() {
// Given
let subject = TestableTarget(
target: .init(
projectPath: try! AbsolutePath(validating: "/path/to/project"),
name: "name"
),
skipped: true,
parallelization: .all,
randomExecutionOrdering: true
)

// Then
XCTAssertCodable(subject)
}
}

0 comments on commit a21a724

Please sign in to comment.