Skip to content

Commit

Permalink
Fix running selective tests with a custom result bundle path when all…
Browse files Browse the repository at this point in the history
… tests are skipped (tuist#6959)
  • Loading branch information
fortmarek authored Oct 30, 2024
1 parent a074f26 commit b594a0e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/TuistKit/Services/TestService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ final class TestService { // swiftlint:disable:this type_body_length
resultBundlePath: AbsolutePath?
) async throws {
if let runResultBundlePath, let resultBundlePath, runResultBundlePath != resultBundlePath {
guard try await fileSystem.exists(resultBundlePath) else { return }
if try await !fileSystem.exists(resultBundlePath.parentDirectory) {
try await fileSystem.makeDirectory(at: resultBundlePath.parentDirectory)
}
Expand Down
62 changes: 62 additions & 0 deletions Tests/TuistKitTests/Services/TestServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,68 @@ final class TestServiceTests: TuistUnitTestCase {
XCTAssertStandardOutput(pattern: "The scheme ProjectSchemeOne's test action has no tests to run, finishing early.")
}

func test_skips_running_tests_when_all_tests_are_cached() async throws {
// Given
givenGenerator()
var environment = MapperEnvironment()
environment.initialGraph = .test(
projects: [
try temporaryPath(): .test(schemes: [.test(name: "ProjectSchemeOne")]),
]
)
given(generator)
.generateWithGraph(path: .any)
.willProduce { path in
(
path,
.test(),
environment
)
}

// When
try await testRun(
path: try temporaryPath()
)

// Then
XCTAssertEmpty(testedSchemes)
XCTAssertStandardOutput(pattern: "There are no tests to run, finishing early")
}

func test_skips_running_tests_when_all_tests_are_cached_with_a_custom_result_bundle_path() async throws {
// Given
givenGenerator()
var environment = MapperEnvironment()
environment.initialGraph = .test(
projects: [
try temporaryPath(): .test(schemes: [.test(name: "ProjectSchemeOne")]),
]
)
given(generator)
.generateWithGraph(path: .any)
.willProduce { path in
(
path,
.test(),
environment
)
}

let resultBundlePath = try temporaryPath()
.appending(component: "test.xcresult")

// When
try await testRun(
path: try temporaryPath(),
resultBundlePath: resultBundlePath
)

// Then
XCTAssertEmpty(testedSchemes)
XCTAssertStandardOutput(pattern: "There are no tests to run, finishing early")
}

func test_run_tests_when_part_is_cached() async throws {
// Given
givenGenerator()
Expand Down

0 comments on commit b594a0e

Please sign in to comment.