diff --git a/Sources/TuistKit/Services/TestService.swift b/Sources/TuistKit/Services/TestService.swift index 245c4fe8ba7..91d0de29e7f 100644 --- a/Sources/TuistKit/Services/TestService.swift +++ b/Sources/TuistKit/Services/TestService.swift @@ -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) } diff --git a/Tests/TuistKitTests/Services/TestServiceTests.swift b/Tests/TuistKitTests/Services/TestServiceTests.swift index 2c4910090e6..70f8f710516 100644 --- a/Tests/TuistKitTests/Services/TestServiceTests.swift +++ b/Tests/TuistKitTests/Services/TestServiceTests.swift @@ -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()