diff --git a/Sources/TuistAutomation/Utilities/BuildGraphInspector.swift b/Sources/TuistAutomation/Utilities/BuildGraphInspector.swift index 3a9b95af270..802ec5b7df0 100644 --- a/Sources/TuistAutomation/Utilities/BuildGraphInspector.swift +++ b/Sources/TuistAutomation/Utilities/BuildGraphInspector.swift @@ -1,9 +1,11 @@ import Foundation +import Mockable import Path import TuistCore import TuistSupport import XcodeGraph +@Mockable public protocol BuildGraphInspecting { /// Returns the build arguments to be used with the given target. /// - Parameter project: Project whose build arguments will be returned. diff --git a/Sources/TuistAutomationTesting/Utilities/MockBuildGraphInspector.swift b/Sources/TuistAutomationTesting/Utilities/MockBuildGraphInspector.swift deleted file mode 100644 index d93db664fe5..00000000000 --- a/Sources/TuistAutomationTesting/Utilities/MockBuildGraphInspector.swift +++ /dev/null @@ -1,96 +0,0 @@ -import Foundation -import Path -import TuistCore -import TuistCoreTesting -import XcodeGraph - -@testable import TuistAutomation - -public final class MockBuildGraphInspector: BuildGraphInspecting { - public init() {} - public var workspacePathStub: ((AbsolutePath) -> AbsolutePath?)? - public func workspacePath(directory: AbsolutePath) -> AbsolutePath? { - workspacePathStub?(directory) ?? nil - } - - public var buildableTargetStub: ((Scheme, GraphTraversing) -> GraphTarget?)? - public func buildableTarget(scheme: Scheme, graphTraverser: GraphTraversing) -> GraphTarget? { - if let buildableTargetStub { - return buildableTargetStub(scheme, graphTraverser) - } else { - return GraphTarget.test() - } - } - - public var buildableSchemesStub: ((GraphTraversing) -> [Scheme])? - public func buildableSchemes(graphTraverser: GraphTraversing) -> [Scheme] { - if let buildableSchemesStub { - return buildableSchemesStub(graphTraverser) - } else { - return [] - } - } - - public var buildableEntrySchemesStub: ((GraphTraversing) -> [Scheme])? - public func buildableEntrySchemes(graphTraverser: GraphTraversing) -> [Scheme] { - buildableEntrySchemesStub?(graphTraverser) ?? [] - } - - public var buildArgumentsStub: ((Project, Target, String?, Bool) -> [XcodeBuildArgument])? - public func buildArguments( - project: Project, - target: Target, - configuration: String?, - skipSigning: Bool - ) -> [XcodeBuildArgument] { - if let buildArgumentsStub { - return buildArgumentsStub(project, target, configuration, skipSigning) - } else { - return [] - } - } - - public var testableTargetStub: ((Scheme, String?, [TestIdentifier], [TestIdentifier], GraphTraversing) -> GraphTarget?)? - public func testableTarget( - scheme: Scheme, - testPlan: String?, - testTargets: [TestIdentifier], - skipTestTargets: [TestIdentifier], - graphTraverser: GraphTraversing - ) -> GraphTarget? { - if let testableTargetStub { - return testableTargetStub(scheme, testPlan, testTargets, skipTestTargets, graphTraverser) - } else { - return GraphTarget.test() - } - } - - public var testableSchemesStub: ((GraphTraversing) -> [Scheme])? - public func testableSchemes(graphTraverser: GraphTraversing) -> [Scheme] { - if let testableSchemesStub { - return testableSchemesStub(graphTraverser) - } else { - return [] - } - } - - public var testSchemesStub: ((GraphTraversing) -> [Scheme])? - public func testSchemes(graphTraverser: GraphTraversing) -> [Scheme] { - testSchemesStub?(graphTraverser) ?? [] - } - - public var runnableTargetStub: ((Scheme, GraphTraversing) -> GraphTarget?)? - public func runnableTarget(scheme: Scheme, graphTraverser: GraphTraversing) -> GraphTarget? { - runnableTargetStub?(scheme, graphTraverser) - } - - public var runnableSchemesStub: ((GraphTraversing) -> [Scheme])? - public func runnableSchemes(graphTraverser: GraphTraversing) -> [Scheme] { - runnableSchemesStub?(graphTraverser) ?? [] - } - - public var workspaceSchemesStub: ((GraphTraversing) -> [Scheme])? - public func workspaceSchemes(graphTraverser: GraphTraversing) -> [Scheme] { - workspaceSchemesStub?(graphTraverser) ?? [] - } -} diff --git a/Sources/TuistKit/Commands/TrackableCommand/TrackableCommand.swift b/Sources/TuistKit/Commands/TrackableCommand/TrackableCommand.swift index 3e8d1c1d269..caa8b181484 100644 --- a/Sources/TuistKit/Commands/TrackableCommand/TrackableCommand.swift +++ b/Sources/TuistKit/Commands/TrackableCommand/TrackableCommand.swift @@ -43,7 +43,7 @@ public class TrackableCommand: TrackableParametersDelegate { public func run() async throws { let runId: String let timer = clock.startTimer() - if var command = command as? HasTrackableParameters & ParsableCommand { + if let command = command as? HasTrackableParameters & ParsableCommand { type(of: command).analyticsDelegate = self runId = command.runId self.command = command diff --git a/Sources/TuistKit/Generator/Generator.swift b/Sources/TuistKit/Generator/Generator.swift index a1e88378ef2..7f0c338d189 100644 --- a/Sources/TuistKit/Generator/Generator.swift +++ b/Sources/TuistKit/Generator/Generator.swift @@ -1,4 +1,5 @@ import Foundation +import Mockable import Path import ProjectDescription import TuistCore @@ -9,6 +10,7 @@ import TuistPlugin import TuistSupport import XcodeGraph +@Mockable public protocol Generating { @discardableResult func load(path: AbsolutePath) async throws -> Graph diff --git a/Sources/TuistKit/Services/TestService.swift b/Sources/TuistKit/Services/TestService.swift index 78274717b40..fcaaf0eba53 100644 --- a/Sources/TuistKit/Services/TestService.swift +++ b/Sources/TuistKit/Services/TestService.swift @@ -245,7 +245,7 @@ final class TestService { // swiftlint:disable:this type_body_length } if let schemeName { - guard let scheme = testableSchemes.first(where: { $0.name == schemeName }) + guard let scheme = graphTraverser.schemes().first(where: { $0.name == schemeName }) else { throw TestServiceError.schemeNotFound( scheme: schemeName, @@ -254,6 +254,8 @@ final class TestService { // swiftlint:disable:this type_body_length } switch (testPlanConfiguration?.testPlan, scheme.testAction?.targets.isEmpty, scheme.testAction?.testPlans?.isEmpty) { + case (_, false, _): + break case (nil, true, _), (nil, nil, _): logger.log(level: .info, "The scheme \(schemeName)'s test action has no tests to run, finishing early.") return diff --git a/Tests/TuistKitTests/Generator/Mocks/MockGenerator.swift b/Tests/TuistKitTests/Generator/Mocks/MockGenerator.swift deleted file mode 100644 index 78626056053..00000000000 --- a/Tests/TuistKitTests/Generator/Mocks/MockGenerator.swift +++ /dev/null @@ -1,72 +0,0 @@ -import Foundation -import Path -import TuistCore -import TuistGenerator -import XcodeGraph -import XcodeGraphTesting -@testable import TuistKit - -final class MockGenerator: Generating { - enum MockError: Error { - case stubNotImplemented - } - - var generateCalls: [AbsolutePath] = [] - var generateStub: ((AbsolutePath) throws -> AbsolutePath)? - func generate(path: AbsolutePath) throws -> AbsolutePath { - guard let generateStub else { - throw MockError.stubNotImplemented - } - - generateCalls.append(path) - return try generateStub(path) - } - - var generateWithGraphCalls: [AbsolutePath] = [] - var generateWithGraphStub: ((AbsolutePath) throws -> (AbsolutePath, Graph))? - func generateWithGraph(path: AbsolutePath) throws -> (AbsolutePath, Graph) { - guard let generateWithGraphStub else { - throw MockError.stubNotImplemented - } - generateWithGraphCalls.append(path) - return try generateWithGraphStub(path) - } - - var invokedGenerateProjectWorkspace = false - var invokedGenerateProjectWorkspaceCount = 0 - var invokedGenerateProjectWorkspaceParameters: (path: AbsolutePath, Void)? - var invokedGenerateProjectWorkspaceParametersList = [(path: AbsolutePath, Void)]() - var stubbedGenerateProjectWorkspaceError: Error? - var stubbedGenerateProjectWorkspaceResult: (AbsolutePath, Graph)! - - func generateProjectWorkspace(path: AbsolutePath) throws -> (AbsolutePath, Graph) { - invokedGenerateProjectWorkspace = true - invokedGenerateProjectWorkspaceCount += 1 - invokedGenerateProjectWorkspaceParameters = (path, ()) - invokedGenerateProjectWorkspaceParametersList.append((path, ())) - if let error = stubbedGenerateProjectWorkspaceError { - throw error - } - return stubbedGenerateProjectWorkspaceResult - } - - var invokedLoadParameterPath: AbsolutePath? - var loadStub: ((AbsolutePath) throws -> Graph)? - func load(path: AbsolutePath) throws -> Graph { - invokedLoadParameterPath = path - if let loadStub { - return try loadStub(path) - } else { - return Graph.test() - } - } - - var loadProjectStub: ((AbsolutePath) throws -> (Project, Graph, [SideEffectDescriptor]))? - func loadProject(path: AbsolutePath) throws -> (Project, Graph, [SideEffectDescriptor]) { - if let loadProjectStub { - return try loadProjectStub(path) - } else { - return (Project.test(), Graph.test(), []) - } - } -} diff --git a/Tests/TuistKitTests/Services/BuildServiceTests.swift b/Tests/TuistKitTests/Services/BuildServiceTests.swift index 5f51f98f0d0..af79e047678 100644 --- a/Tests/TuistKitTests/Services/BuildServiceTests.swift +++ b/Tests/TuistKitTests/Services/BuildServiceTests.swift @@ -2,6 +2,7 @@ import Foundation import MockableTest import Path import TSCUtility +import TuistAutomation import TuistCore import TuistServer import TuistSupport @@ -38,16 +39,16 @@ final class BuildServiceErrorTests: TuistUnitTestCase { } final class BuildServiceTests: TuistUnitTestCase { - private var generator: MockGenerator! + private var generator: MockGenerating! private var generatorFactory: MockGeneratorFactorying! - private var buildGraphInspector: MockBuildGraphInspector! + private var buildGraphInspector: MockBuildGraphInspecting! private var targetBuilder: MockTargetBuilder! private var cacheStorageFactory: MockCacheStorageFactorying! private var subject: BuildService! override func setUp() { super.setUp() - generator = MockGenerator() + generator = .init() generatorFactory = .init() given(generatorFactory) .building( @@ -57,7 +58,11 @@ final class BuildServiceTests: TuistUnitTestCase { cacheStorage: .any ) .willReturn(generator) - buildGraphInspector = MockBuildGraphInspector() + buildGraphInspector = .init() + given(buildGraphInspector) + .buildableEntrySchemes(graphTraverser: .any) + .willReturn([]) + targetBuilder = MockTargetBuilder() cacheStorageFactory = .init() given(cacheStorageFactory) @@ -92,27 +97,26 @@ final class BuildServiceTests: TuistUnitTestCase { let buildArguments: [XcodeBuildArgument] = [.sdk("iphoneos")] let skipSigning = false - generator.generateWithGraphStub = { _path in - XCTAssertEqual(_path, path) - return (path, graph) - } - buildGraphInspector.buildableSchemesStub = { _ in - [scheme] - } - buildGraphInspector.buildableTargetStub = { _scheme, _ in - XCTAssertEqual(_scheme, scheme) - return GraphTarget.test(path: project.path, target: target, project: project) - } - buildGraphInspector.workspacePathStub = { _path in - XCTAssertEqual(_path, path) - return workspacePath - } - buildGraphInspector.buildArgumentsStub = { _project, _target, _, _skipSigning in - XCTAssertEqual(_project, project) - XCTAssertEqual(_target, target) - XCTAssertEqual(_skipSigning, skipSigning) - return buildArguments - } + given(generator) + .load(path: .value(path)) + .willReturn(graph) + given(buildGraphInspector) + .buildableSchemes(graphTraverser: .any) + .willReturn([scheme]) + given(buildGraphInspector) + .buildableTarget(scheme: .value(scheme), graphTraverser: .any) + .willReturn(GraphTarget.test(path: project.path, target: target, project: project)) + given(buildGraphInspector) + .workspacePath(directory: .value(path)) + .willReturn(workspacePath) + given(buildGraphInspector) + .buildArguments( + project: .value(project), + target: .value(target), + configuration: .any, + skipSigning: .value(skipSigning) + ) + .willReturn(buildArguments) targetBuilder .buildTargetStub = { _, _workspacePath, _scheme, _clean, _, _, _, _device, _osVersion, _, _, _ in XCTAssertEqual(_workspacePath, workspacePath) @@ -140,27 +144,30 @@ final class BuildServiceTests: TuistUnitTestCase { let buildArguments: [XcodeBuildArgument] = [.sdk("iphoneos")] let skipSigning = false - generator.loadStub = { _path in - XCTAssertEqual(_path, path) - return graph - } - buildGraphInspector.buildableSchemesStub = { _ in - [scheme] - } - buildGraphInspector.buildableTargetStub = { _scheme, _ in - XCTAssertEqual(_scheme, scheme) - return GraphTarget.test(path: project.path, target: target, project: project) - } - buildGraphInspector.workspacePathStub = { _path in - XCTAssertEqual(_path, path) - return workspacePath - } - buildGraphInspector.buildArgumentsStub = { _project, _target, _, _skipSigning in - XCTAssertEqual(_project, project) - XCTAssertEqual(_target, target) - XCTAssertEqual(_skipSigning, skipSigning) - return buildArguments - } + given(generator) + .load(path: .value(path)) + .willReturn(graph) + given(buildGraphInspector) + .buildableSchemes(graphTraverser: .any) + .willReturn( + [ + scheme, + ] + ) + given(buildGraphInspector) + .buildableTarget(scheme: .value(scheme), graphTraverser: .any) + .willReturn(GraphTarget.test(path: project.path, target: target, project: project)) + given(buildGraphInspector) + .workspacePath(directory: .value(path)) + .willReturn(workspacePath) + given(buildGraphInspector) + .buildArguments( + project: .value(project), + target: .value(target), + configuration: .any, + skipSigning: .value(skipSigning) + ) + .willReturn(buildArguments) targetBuilder.buildTargetStub = { _, _workspacePath, _scheme, _clean, _, _, _, _, _, _, _, _ in XCTAssertEqual(_workspacePath, workspacePath) XCTAssertEqual(_scheme, scheme) @@ -187,26 +194,29 @@ final class BuildServiceTests: TuistUnitTestCase { let buildArguments: [XcodeBuildArgument] = [.sdk("iphoneos")] let skipSigning = false - generator.loadStub = { _path in - XCTAssertEqual(_path, path) - return graph - } - buildGraphInspector.buildableSchemesStub = { _ in - [schemeA, schemeB] - } - buildGraphInspector.buildableTargetStub = { _scheme, _ in - if _scheme == schemeA { return GraphTarget.test(path: project.path, target: targetA, project: project) } - else if _scheme == schemeB { return GraphTarget.test(path: project.path, target: targetB, project: project) } - else { XCTFail("unexpected scheme"); return GraphTarget.test(path: project.path, target: targetA, project: project) } - } - buildGraphInspector.workspacePathStub = { _path in - XCTAssertEqual(_path, path) - return workspacePath - } - buildGraphInspector.buildArgumentsStub = { _, _, _, _skipSigning in - XCTAssertEqual(_skipSigning, skipSigning) - return buildArguments - } + given(generator) + .load(path: .value(path)) + .willReturn(graph) + given(buildGraphInspector) + .buildableSchemes(graphTraverser: .any) + .willReturn([schemeA, schemeB]) + given(buildGraphInspector) + .buildableTarget(scheme: .matching { + $0 == schemeA || $0 == schemeB + }, graphTraverser: .any) + .willProduce { scheme, _ in + if scheme == schemeA { + return GraphTarget.test(path: project.path, target: targetA, project: project) + } else { + return GraphTarget.test(path: project.path, target: targetB, project: project) + } + } + given(buildGraphInspector) + .workspacePath(directory: .value(path)) + .willReturn(workspacePath) + given(buildGraphInspector) + .buildArguments(project: .any, target: .any, configuration: .any, skipSigning: .value(skipSigning)) + .willReturn(buildArguments) targetBuilder .buildTargetStub = { _, _workspacePath, _scheme, _clean, _, _, _, _device, _osVersion, _, _, _ in XCTAssertEqual(_workspacePath, workspacePath) @@ -244,26 +254,34 @@ final class BuildServiceTests: TuistUnitTestCase { let buildArguments: [XcodeBuildArgument] = [.sdk("iphoneos")] let skipSigning = false - generator.loadStub = { _path in - XCTAssertEqual(_path, path) - return graph - } - buildGraphInspector.buildableSchemesStub = { _ in - [schemeA, schemeB] - } - buildGraphInspector.buildableTargetStub = { _scheme, _ in - if _scheme == schemeA { return GraphTarget.test(path: project.path, target: targetA, project: project) } - else if _scheme == schemeB { return GraphTarget.test(path: project.path, target: targetB, project: project) } - else { XCTFail("unexpected scheme"); return GraphTarget.test(path: project.path, target: targetA, project: project) } - } - buildGraphInspector.workspacePathStub = { _path in - XCTAssertEqual(_path, path) - return workspacePath - } - buildGraphInspector.buildArgumentsStub = { _, _, _, _skipSigning in - XCTAssertEqual(_skipSigning, skipSigning) - return buildArguments - } + given(generator) + .load(path: .value(path)) + .willReturn(graph) + given(buildGraphInspector) + .buildableSchemes(graphTraverser: .any) + .willReturn( + [ + schemeA, + schemeB, + ] + ) + given(buildGraphInspector) + .buildableTarget(scheme: .matching { + $0 == schemeA || $0 == schemeB + }, graphTraverser: .any) + .willProduce { scheme, _ in + if scheme == schemeA { + return GraphTarget.test(path: project.path, target: targetA, project: project) + } else { + return GraphTarget.test(path: project.path, target: targetB, project: project) + } + } + given(buildGraphInspector) + .workspacePath(directory: .value(path)) + .willReturn(workspacePath) + given(buildGraphInspector) + .buildArguments(project: .any, target: .any, configuration: .any, skipSigning: .value(skipSigning)) + .willReturn(buildArguments) targetBuilder.buildTargetStub = { _, _workspacePath, _scheme, _clean, _, _, _, _, _, _, _, _ in XCTAssertEqual(_workspacePath, workspacePath) if _scheme.name == "A" { @@ -288,20 +306,20 @@ final class BuildServiceTests: TuistUnitTestCase { let graph = Graph.test() let schemeA = Scheme.test(name: "A") let schemeB = Scheme.test(name: "B") - generator.loadStub = { _path in - XCTAssertEqual(_path, path) - return graph - } - buildGraphInspector.workspacePathStub = { _path in - XCTAssertEqual(_path, path) - return workspacePath - } - buildGraphInspector.buildableSchemesStub = { _ in - [ - schemeA, - schemeB, - ] - } + given(generator) + .load(path: .value(path)) + .willReturn(graph) + given(buildGraphInspector) + .workspacePath(directory: .value(path)) + .willReturn(workspacePath) + given(buildGraphInspector) + .buildableSchemes(graphTraverser: .any) + .willReturn( + [ + schemeA, + schemeB, + ] + ) // When try await subject.testRun( diff --git a/Tests/TuistKitTests/Services/GenerateServiceTests.swift b/Tests/TuistKitTests/Services/GenerateServiceTests.swift index 10359f7ff40..79dc4327cce 100644 --- a/Tests/TuistKitTests/Services/GenerateServiceTests.swift +++ b/Tests/TuistKitTests/Services/GenerateServiceTests.swift @@ -15,7 +15,7 @@ import XCTest final class GenerateServiceTests: TuistUnitTestCase { private var subject: GenerateService! private var opener: MockOpener! - private var generator: MockGenerator! + private var generator: MockGenerating! private var generatorFactory: MockGeneratorFactorying! private var cacheStorageFactory: MockCacheStorageFactorying! private var clock: StubClock! @@ -23,7 +23,7 @@ final class GenerateServiceTests: TuistUnitTestCase { override func setUp() { super.setUp() opener = MockOpener() - generator = MockGenerator() + generator = .init() generatorFactory = .init() given(generatorFactory) .generation( @@ -59,9 +59,9 @@ final class GenerateServiceTests: TuistUnitTestCase { func test_run_fatalErrors_when_theworkspaceGenerationFails() async throws { let expectedError = NSError.test() - generator.generateStub = { _ in - throw expectedError - } + given(generator) + .generate(path: .any) + .willThrow(expectedError) do { try await subject @@ -81,9 +81,9 @@ final class GenerateServiceTests: TuistUnitTestCase { func test_run() async throws { let workspacePath = try AbsolutePath(validating: "/test.xcworkspace") - generator.generateStub = { _ in - workspacePath - } + given(generator) + .generate(path: .any) + .willReturn(workspacePath) try await subject.run( path: nil, @@ -100,9 +100,9 @@ final class GenerateServiceTests: TuistUnitTestCase { // Given let workspacePath = try AbsolutePath(validating: "/test.xcworkspace") - generator.generateStub = { _ in - workspacePath - } + given(generator) + .generate(path: .any) + .willReturn(workspacePath) clock.assertOnUnexpectedCalls = true clock.primedTimers = [ 0.234, diff --git a/Tests/TuistKitTests/Services/RunServiceTests.swift b/Tests/TuistKitTests/Services/RunServiceTests.swift index 6b0f9a09eab..b76c93f7ffc 100644 --- a/Tests/TuistKitTests/Services/RunServiceTests.swift +++ b/Tests/TuistKitTests/Services/RunServiceTests.swift @@ -2,6 +2,7 @@ import Foundation import MockableTest import Path import struct TSCUtility.Version +import TuistAutomation import TuistCore import TuistSupport import XcodeGraph @@ -37,9 +38,9 @@ final class RunServiceErrorTests: TuistUnitTestCase { } final class RunServiceTests: TuistUnitTestCase { - private var generator: MockGenerator! + private var generator: MockGenerating! private var generatorFactory: MockGeneratorFactorying! - private var buildGraphInspector: MockBuildGraphInspector! + private var buildGraphInspector: MockBuildGraphInspecting! private var targetBuilder: MockTargetBuilder! private var targetRunner: MockTargetRunner! private var subject: RunService! @@ -48,12 +49,12 @@ final class RunServiceTests: TuistUnitTestCase { override func setUp() { super.setUp() - generator = MockGenerator() + generator = .init() generatorFactory = MockGeneratorFactorying() given(generatorFactory) .defaultGenerator(config: .any) .willReturn(generator) - buildGraphInspector = MockBuildGraphInspector() + buildGraphInspector = .init() targetBuilder = MockTargetBuilder() targetRunner = MockTargetRunner() subject = RunService( @@ -76,42 +77,48 @@ final class RunServiceTests: TuistUnitTestCase { func test_run_generates_when_generateIsTrue() async throws { // Given - let expectation = expectation(description: "generates when required") - generator.generateWithGraphStub = { _ in - expectation.fulfill() - return (try AbsolutePath(validating: "/path/to/project.xcworkspace"), .test()) - } - buildGraphInspector.workspacePathStub = { _ in try! AbsolutePath(validating: "/path/to/project.xcworkspace") } - buildGraphInspector.runnableSchemesStub = { _ in [.test()] } - buildGraphInspector.runnableTargetStub = { _, _ in .test() } + given(generator) + .generateWithGraph(path: .any) + .willReturn((try AbsolutePath(validating: "/path/to/project.xcworkspace"), .test())) + given(buildGraphInspector) + .workspacePath(directory: .any) + .willReturn(try! AbsolutePath(validating: "/path/to/project.xcworkspace")) + given(buildGraphInspector) + .runnableSchemes(graphTraverser: .any) + .willReturn([.test()]) + given(buildGraphInspector) + .runnableTarget(scheme: .any, graphTraverser: .any) + .willReturn(.test()) try await subject.run(generate: true) - await fulfillment(of: [expectation], timeout: 1) } func test_run_generates_when_workspaceNotFound() async throws { // Given let workspacePath = try temporaryPath().appending(component: "App.xcworkspace") - let expectation = expectation(description: "generates when required") - generator.generateWithGraphStub = { _ in - // Then - self.buildGraphInspector.workspacePathStub = { _ in workspacePath } - expectation.fulfill() - return (workspacePath, .test()) - } - buildGraphInspector.workspacePathStub = { _ in nil } - buildGraphInspector.runnableSchemesStub = { _ in [.test()] } - buildGraphInspector.runnableTargetStub = { _, _ in .test() } + given(generator) + .generateWithGraph(path: .any) + .willReturn((workspacePath, .test())) + given(generator) + .load(path: .any) + .willReturn(.test()) + given(buildGraphInspector) + .workspacePath(directory: .any) + .willReturn(workspacePath) + given(buildGraphInspector) + .runnableSchemes(graphTraverser: .any) + .willReturn([.test()]) + given(buildGraphInspector) + .runnableTarget(scheme: .any, graphTraverser: .any) + .willReturn(.test()) // When try await subject.run() - await fulfillment(of: [expectation], timeout: 1) } func test_run_buildsTarget() async throws { // Given let workspacePath = try temporaryPath().appending(component: "App.xcworkspace") - let expectation = expectation(description: "builds target") let schemeName = "AScheme" let clean = true let configuration = "Test" @@ -122,13 +129,20 @@ final class RunServiceTests: TuistUnitTestCase { XCTAssertEqual(_scheme.name, schemeName) XCTAssertEqual(_clean, clean) XCTAssertEqual(_configuration, configuration) - expectation.fulfill() } - generator.generateWithGraphStub = { _ in (workspacePath, .test()) } + given(generator) + .load(path: .any) + .willReturn(.test()) targetRunner.assertCanRunTargetStub = { _ in } - buildGraphInspector.workspacePathStub = { _ in workspacePath } - buildGraphInspector.runnableSchemesStub = { _ in [.test(name: schemeName)] } - buildGraphInspector.runnableTargetStub = { _, _ in .test() } + given(buildGraphInspector) + .workspacePath(directory: .any) + .willReturn(workspacePath) + given(buildGraphInspector) + .runnableSchemes(graphTraverser: .any) + .willReturn([.test(name: schemeName)]) + given(buildGraphInspector) + .runnableTarget(scheme: .any, graphTraverser: .any) + .willReturn(.test()) // When try await subject.run( @@ -136,13 +150,11 @@ final class RunServiceTests: TuistUnitTestCase { clean: clean, configuration: configuration ) - await fulfillment(of: [expectation], timeout: 1) } func test_run_runsTarget() async throws { // Given let workspacePath = try AbsolutePath(validating: "/path/to/project.xcworkspace") - let expectation = expectation(description: "runs target") let schemeName = "AScheme" let configuration = "Test" let minVersion = Target.test().deploymentTargets.configuredVersions.first?.versionString.version() @@ -159,13 +171,20 @@ final class RunServiceTests: TuistUnitTestCase { XCTAssertEqual(_version, version) XCTAssertEqual(_deviceName, deviceName) XCTAssertEqual(_arguments, arguments) - expectation.fulfill() } - generator.generateWithGraphStub = { _ in (workspacePath, .test()) } + given(generator) + .load(path: .any) + .willReturn(.test()) targetRunner.assertCanRunTargetStub = { _ in } - buildGraphInspector.workspacePathStub = { _ in workspacePath } - buildGraphInspector.runnableSchemesStub = { _ in [.test(name: schemeName)] } - buildGraphInspector.runnableTargetStub = { _, _ in .test() } + given(buildGraphInspector) + .workspacePath(directory: .any) + .willReturn(workspacePath) + given(buildGraphInspector) + .runnableSchemes(graphTraverser: .any) + .willReturn([.test(name: schemeName)]) + given(buildGraphInspector) + .runnableTarget(scheme: .any, graphTraverser: .any) + .willReturn(.test()) // When try await subject.run( @@ -175,8 +194,6 @@ final class RunServiceTests: TuistUnitTestCase { version: version.description, arguments: arguments ) - - await fulfillment(of: [expectation], timeout: 1) } func test_run_throws_beforeBuilding_if_cantRunTarget() async throws { @@ -184,10 +201,18 @@ final class RunServiceTests: TuistUnitTestCase { let workspacePath = try temporaryPath().appending(component: "App.xcworkspace") let expectation = expectation(description: "does not run target builder") expectation.isInverted = true - generator.generateWithGraphStub = { _ in (workspacePath, .test()) } - buildGraphInspector.workspacePathStub = { _ in workspacePath } - buildGraphInspector.runnableSchemesStub = { _ in [.test()] } - buildGraphInspector.runnableTargetStub = { _, _ in .test() } + given(generator) + .load(path: .any) + .willReturn(.test()) + given(buildGraphInspector) + .workspacePath(directory: .any) + .willReturn(workspacePath) + given(buildGraphInspector) + .runnableSchemes(graphTraverser: .any) + .willReturn([.test()]) + given(buildGraphInspector) + .runnableTarget(scheme: .any, graphTraverser: .any) + .willReturn(.test()) targetBuilder.buildTargetStub = { _, _, _, _, _, _, _, _, _, _, _, _ in expectation.fulfill() } targetRunner.assertCanRunTargetStub = { _ in throw TestError() } diff --git a/Tests/TuistKitTests/Services/TestServiceTests.swift b/Tests/TuistKitTests/Services/TestServiceTests.swift index a0402c9f925..0e26e76910d 100644 --- a/Tests/TuistKitTests/Services/TestServiceTests.swift +++ b/Tests/TuistKitTests/Services/TestServiceTests.swift @@ -16,10 +16,10 @@ import XCTest final class TestServiceTests: TuistUnitTestCase { private var subject: TestService! - private var generator: MockGenerator! + private var generator: MockGenerating! private var generatorFactory: MockGeneratorFactorying! private var xcodebuildController: MockXcodeBuildController! - private var buildGraphInspector: MockBuildGraphInspector! + private var buildGraphInspector: MockBuildGraphInspecting! private var simulatorController: MockSimulatorController! private var contentHasher: MockContentHasher! private var testsCacheTemporaryDirectory: TemporaryDirectory! @@ -53,6 +53,10 @@ final class TestServiceTests: TuistUnitTestCase { "hash" } + given(buildGraphInspector) + .buildArguments(project: .any, target: .any, configuration: .any, skipSigning: .any) + .willReturn([]) + subject = TestService( generatorFactory: generatorFactory, xcodebuildController: xcodebuildController, @@ -183,46 +187,57 @@ final class TestServiceTests: TuistUnitTestCase { // Given givenGenerator() let path = try temporaryPath() - var generatedPath: AbsolutePath? - generator.generateWithGraphStub = { - generatedPath = $0 - return ($0, Graph.test()) - } + given(generator) + .generateWithGraph(path: .value(path)) + .willReturn((path, .test())) + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn([]) + given(configLoader) .loadConfig(path: .any) .willReturn(.default) // When - try? await subject.testRun( + try await subject.testRun( path: path ) - - // Then - XCTAssertEqual(generatedPath, path) } - func test_run_tests_wtih_specified_arch() async throws { + func test_run_tests_with_specified_arch() async throws { // Given givenGenerator() given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "App-Workspace"), - Scheme.test(name: "TestScheme"), - ] - } - buildGraphInspector.testableTargetStub = { scheme, _, _, _, _ in - GraphTarget.test( - target: Target.test( - name: scheme.name - ) + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "App-Workspace"), + Scheme.test(name: "TestScheme"), + ] ) - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willProduce { scheme, _, _, _, _ in + GraphTarget.test( + target: Target.test( + name: scheme.name + ) + ) + } + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "TestScheme")]))) + } var testedRosetta: Bool? xcodebuildController.testStub = { _, _, _, _, rosetta, _, _, _, _, _, _, _, _ in testedRosetta = rosetta @@ -245,22 +260,31 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "App-Workspace"), - Scheme.test(name: "TestScheme"), - ] - } - buildGraphInspector.testableTargetStub = { scheme, _, _, _, _ in - GraphTarget.test( - target: Target.test( - name: scheme.name - ) + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "App-Workspace"), + Scheme.test(name: "TestScheme"), + ] ) - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willProduce { scheme, _, _, _, _ in + GraphTarget.test( + target: Target.test( + name: scheme.name + ) + ) + } + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "TestScheme")]))) + } var testedSchemes: [String] = [] xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in testedSchemes.append(scheme) @@ -282,20 +306,29 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "TestScheme"), - ] - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectSchemeOne"), - Scheme.test(name: "ProjectSchemeTwo"), - ] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "TestScheme"), + ] + ) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectSchemeOne"), + Scheme.test(name: "ProjectSchemeTwo"), + ] + ) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test()) + } var testedSchemes: [String] = [] xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in testedSchemes.append(scheme) @@ -328,20 +361,29 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "TestScheme"), - ] - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectSchemeOne"), - Scheme.test(name: "ProjectSchemeTwo"), - ] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "TestScheme"), + ] + ) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectSchemeOne"), + Scheme.test(name: "ProjectSchemeTwo"), + ] + ) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "ProjectSchemeOne"), .test(name: "ProjectSchemeTwo")]))) + } var testedSchemes: [String] = [] xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in testedSchemes.append(scheme) @@ -363,6 +405,48 @@ final class TestServiceTests: TuistUnitTestCase { XCTAssertEqual(testedSchemes, ["ProjectSchemeOne"]) } + func test_run_tests_individual_scheme_with_no_test_actions() async throws { + // Given + givenGenerator() + given(configLoader) + .loadConfig(path: .any) + .willReturn(.default) + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "ProjectSchemeOne", testAction: .test(targets: []))]))) + } + var testedSchemes: [String] = [] + xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in + testedSchemes.append(scheme) + } + try fileHandler.touch( + testsCacheTemporaryDirectory.path.appending(component: "A") + ) + try fileHandler.touch( + testsCacheTemporaryDirectory.path.appending(component: "B") + ) + + // When + try await subject.testRun( + schemeName: "ProjectSchemeOne", + path: try temporaryPath() + ) + + // Then + XCTAssertStandardOutput(pattern: "The scheme ProjectSchemeOne's test action has no tests to run, finishing early.") + XCTAssertEmpty(testedSchemes) + } + func test_run_tests_with_skipped_targets() async throws { // Given given(generatorFactory) @@ -382,14 +466,24 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "ProjectSchemeOneTests"), - ] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectSchemeOneTests"), + ] + ) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn([]) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "ProjectSchemeOneTests")]))) + } + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) var testedSchemes: [String] = [] xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in testedSchemes.append(scheme) @@ -412,14 +506,24 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectScheme"), - ] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectScheme"), + ] + ) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test()) + } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) var testedSchemes: [String] = [] xcodebuildController.testErrorStub = NSError.test() xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in @@ -453,12 +557,20 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.workspaceSchemesStub = { _ in - [] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test()) + } var testedSchemes: [String] = [] xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in testedSchemes.append(scheme) @@ -486,14 +598,24 @@ final class TestServiceTests: TuistUnitTestCase { xcodebuildController.testStub = { _, _, _, _, _, _, gotResourceBundlePath, _, _, _, _, _, _ in resourceBundlePath = gotResourceBundlePath } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectScheme"), - ] - } + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test()) + } + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectScheme"), + ] + ) + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) // When try await subject.testRun( @@ -519,14 +641,24 @@ final class TestServiceTests: TuistUnitTestCase { xcodebuildController.testStub = { _, _, _, _, _, _, gotResourceBundlePath, _, _, _, _, _, _ in resultBundlePath = gotResourceBundlePath } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectScheme"), - ] - } + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test()) + } + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectScheme"), + ] + ) + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) given(configLoader) .loadConfig(path: .any) .willReturn( @@ -564,15 +696,25 @@ final class TestServiceTests: TuistUnitTestCase { xcodebuildController.testStub = { _, _, _, _, _, _, gotResourceBundlePath, _, _, _, _, _, _ in resourceBundlePath = gotResourceBundlePath } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectScheme"), - Scheme.test(name: "ProjectScheme2"), - ] - } + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "ProjectScheme2")]))) + } + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectScheme"), + Scheme.test(name: "ProjectScheme2"), + ] + ) + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn([]) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) // When try await subject.testRun( @@ -594,19 +736,28 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "TestScheme"), - ] - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectSchemeOne"), - ] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "TestScheme"), + ] + ) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectSchemeOne"), + ] + ) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "ProjectSchemeOne")]))) + } + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) var passedRetryCount = 0 xcodebuildController.testStub = { _, _, _, _, _, _, _, _, retryCount, _, _, _, _ in @@ -630,19 +781,28 @@ final class TestServiceTests: TuistUnitTestCase { given(configLoader) .loadConfig(path: .any) .willReturn(.default) - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "TestScheme"), - ] - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectSchemeOne"), - ] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "TestScheme"), + ] + ) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectSchemeOne"), + ] + ) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "ProjectSchemeOne")]))) + } + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) var passedRetryCount = -1 xcodebuildController.testStub = { _, _, _, _, _, _, _, _, retryCount, _, _, _, _ in @@ -667,29 +827,54 @@ final class TestServiceTests: TuistUnitTestCase { .willReturn(.default) let testPlan = "TestPlan" let testPlanPath = try AbsolutePath(validating: "/testPlan/\(testPlan)") - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "App-Workspace"), - Scheme.test( - name: "TestScheme", - testAction: .test( - testPlans: [.init(path: testPlanPath, testTargets: [], isDefault: true)] + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "App-Workspace"), + Scheme.test( + name: "TestScheme", + testAction: .test( + testPlans: [.init(path: testPlanPath, testTargets: [], isDefault: true)] + ) + ), + ] + ) + given(buildGraphInspector) + .testableTarget( + scheme: .any, + testPlan: .value(testPlan), + testTargets: .any, + skipTestTargets: .any, + graphTraverser: .any + ) + .willProduce { scheme, _, _, _, _ in + GraphTarget.test( + target: Target.test( + name: scheme.name ) - ), - ] - } - var passedTestPlan: String? - buildGraphInspector.testableTargetStub = { scheme, testPlan, _, _, _ in - passedTestPlan = testPlan - return GraphTarget.test( - target: Target.test( - name: scheme.name ) - ) - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + } + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn([]) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + ( + path, + .test( + workspace: .test( + schemes: [ + .test( + name: "TestScheme", + testAction: .test(targets: [.test()]) + ), + ] + ) + ) + ) + } var testedSchemes: [String] = [] xcodebuildController.testStub = { _, scheme, _, _, _, _, _, _, _, _, _, _, _ in testedSchemes.append(scheme) @@ -704,7 +889,6 @@ final class TestServiceTests: TuistUnitTestCase { // Then XCTAssertEqual(testedSchemes, ["TestScheme"]) - XCTAssertEqual(passedTestPlan, testPlan) } func test_run_test_plan_failure() async throws { @@ -715,25 +899,34 @@ final class TestServiceTests: TuistUnitTestCase { .willReturn(.default) let testPlan = "TestPlan" let testPlanPath = try AbsolutePath(validating: "/testPlan/\(testPlan)") - buildGraphInspector.testableSchemesStub = { _ in - [ - Scheme.test(name: "App-Workspace"), - Scheme.test( - name: "TestScheme", - testAction: .test( - testPlans: [.init(path: testPlanPath, testTargets: [], isDefault: true)] - ) - ), - ] - } - buildGraphInspector.workspaceSchemesStub = { _ in - [ - Scheme.test(name: "ProjectSchemeOne"), - ] - } - generator.generateWithGraphStub = { path in - (path, Graph.test()) - } + given(buildGraphInspector) + .testableSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "App-Workspace"), + Scheme.test( + name: "TestScheme", + testAction: .test( + testPlans: [.init(path: testPlanPath, testTargets: [], isDefault: true)] + ) + ), + ] + ) + given(buildGraphInspector) + .workspaceSchemes(graphTraverser: .any) + .willReturn( + [ + Scheme.test(name: "ProjectSchemeOne"), + ] + ) + given(buildGraphInspector) + .testableTarget(scheme: .any, testPlan: .any, testTargets: .any, skipTestTargets: .any, graphTraverser: .any) + .willReturn(.test()) + given(generator) + .generateWithGraph(path: .any) + .willProduce { path in + (path, .test(workspace: .test(schemes: [.test(name: "TestScheme")]))) + } xcodebuildController.testStub = { _, _, _, _, _, _, _, _, _, _, _, _, _ in } let notDefinedTestPlan = "NotDefined"