Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add TestableTarget.parallelization property #92

Merged
merged 1 commit into from
Jan 3, 2025
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
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 @@

/// 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 All @@ -39,7 +73,7 @@
randomExecutionOrdering: Bool = false,
simulatedLocation: SimulatedLocation? = nil
) -> TestableTarget {
TestableTarget(

Check warning on line 76 in Sources/XcodeGraph/Models/TestableTarget.swift

View workflow job for this annotation

GitHub Actions / Warm (macos-15)

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

Check warning on line 76 in Sources/XcodeGraph/Models/TestableTarget.swift

View workflow job for this annotation

GitHub Actions / Warm (macos-15)

'init(target:skipped:parallelizable:randomExecutionOrdering:simulatedLocation:)' is deprecated: replaced by 'init(target:skipped:parallelization:randomExecutionOrdering:simulatedLocation:)'
target: target,
skipped: skipped,
parallelizable: parallelizable,
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,9 +5,9 @@
@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(
projectPath: try! AbsolutePath(validating: "/path/to/project"),
name: "name"
Expand All @@ -20,4 +20,20 @@
// 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)
}
}
Loading