Skip to content
Open
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
27 changes: 23 additions & 4 deletions Sources/_InternalBuildTestSupport/MockBuildTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import PackageModel
import SPMBuildCore
import TSCUtility
import XCTest
import Testing

public func mockBuildPlan(
buildPath: AbsolutePath? = nil,
Expand Down Expand Up @@ -174,12 +175,30 @@ public struct BuildPlanResult {
self.plan = plan
}

public func checkTargetsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) {
XCTAssertEqual(self.targetMap.count, count, file: file, line: line)
public func checkTargetsCount(
_ count: Int,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
) {
if Test.current != nil {
#expect(self.targetMap.count == count, sourceLocation: sourceLocation)
} else {
XCTAssertEqual(self.targetMap.count, count, file: file, line: line)
}
}

public func checkProductsCount(_ count: Int, file: StaticString = #file, line: UInt = #line) {
XCTAssertEqual(self.productMap.count, count, file: file, line: line)
public func checkProductsCount(
_ count: Int,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
) {
if Test.current != nil {
#expect(self.productMap.count == count, sourceLocation: sourceLocation)
} else {
XCTAssertEqual(self.productMap.count, count, file: file, line: line)
}
}

public func moduleBuildDescription(for name: String) throws -> Build.ModuleBuildDescription {
Expand Down
92 changes: 80 additions & 12 deletions Sources/_InternalBuildTestSupport/PIFTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import Basics
import XCBuildSupport
import XCTest
import Testing

public func PIFTester(_ pif: PIF.TopLevelObject, _ body: (PIFWorkspaceTester) throws -> Void) throws {
try body(PIFWorkspaceTester(workspace: pif.workspace))
Expand All @@ -36,10 +37,16 @@ public final class PIFWorkspaceTester {
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
body: (PIFProjectTester) -> Void
) throws {
guard let project = projectMap[guid] else {
return XCTFail("project \(guid) not found", file: file, line: line)
if Test.current != nil {
Issue.record("project \(guid) not found", sourceLocation: sourceLocation)
return
} else {
return XCTFail("project \(guid) not found", file: file, line: line)
}
}

body(try PIFProjectTester(project: project, targetMap: targetMap))
Expand Down Expand Up @@ -72,15 +79,26 @@ public final class PIFProjectTester {
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
body: ((PIFTargetTester) -> Void)? = nil
) {
guard let baseTarget = baseTarget(withGUID: guid) else {
let guids = project.targets.map { $0.guid }.joined(separator: ", ")
return XCTFail("target \(guid) not found among \(guids)", file: file, line: line)
if Test.current != nil {
Issue.record("target \(guid) not found among \(guids)", sourceLocation: sourceLocation)
return
} else {
return XCTFail("target \(guid) not found among \(guids)", file: file, line: line)
}
}

guard let target = baseTarget as? PIF.Target else {
return XCTFail("target \(guid) is not a standard target", file: file, line: line)
if Test.current != nil {
Issue.record("target \(guid) is not a standard target", sourceLocation: sourceLocation)
return
} else {
return XCTFail("target \(guid) is not a standard target", file: file, line: line)
}
}

body?(PIFTargetTester(target: target, targetMap: targetMap, fileMap: fileMap))
Expand All @@ -90,26 +108,42 @@ public final class PIFProjectTester {
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
body: ((PIFTargetTester) -> Void)? = nil
) {
if baseTarget(withGUID: guid) != nil {
XCTFail("target \(guid) found", file: file, line: line)
if Test.current != nil {
Issue.record("target \(guid) found", sourceLocation: sourceLocation)
} else {
XCTFail("target \(guid) found", file: file, line: line)
}
}
}

public func checkAggregateTarget(
_ guid: PIF.GUID,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
body: ((PIFAggregateTargetTester) -> Void)? = nil
) {
guard let baseTarget = baseTarget(withGUID: guid) else {
let guids = project.targets.map { $0.guid }.joined(separator: ", ")
return XCTFail("target \(guid) not found among \(guids)", file: file, line: line)
if Test.current != nil {
Issue.record("target \(guid) not found among \(guids)", sourceLocation: sourceLocation)
return
} else {
return XCTFail("target \(guid) not found among \(guids)", file: file, line: line)
}
}

guard let target = baseTarget as? PIF.AggregateTarget else {
return XCTFail("target \(guid) is not an aggregate target", file: file, line: line)
if Test.current != nil {
Issue.record("target \(guid) is not an aggregate target", sourceLocation: sourceLocation)
return
} else {
return XCTFail("target \(guid) is not an aggregate target", file: file, line: line)
}
}

body?(PIFAggregateTargetTester(target: target, targetMap: targetMap, fileMap: fileMap))
Expand All @@ -119,11 +153,17 @@ public final class PIFProjectTester {
_ name: String,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
body: (PIFBuildConfigurationTester) -> Void
) {
guard let configuration = buildConfiguration(withName: name) else {
let names = project.buildConfigurations.map { $0.name }.joined(separator: ", ")
return XCTFail("build configuration \(name) not found among \(names)", file: file, line: line)
if Test.current != nil {
Issue.record("build configuration \(name) not found among \(names)", sourceLocation: sourceLocation)
return
} else {
return XCTFail("build configuration \(name) not found among \(names)", file: file, line: line)
}
}

body(PIFBuildConfigurationTester(buildConfiguration: configuration))
Expand Down Expand Up @@ -185,10 +225,16 @@ public class PIFBaseTargetTester {
_ name: String,
file: StaticString = #file,
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation,
body: (PIFBuildConfigurationTester) -> Void
) {
guard let configuration = buildConfiguration(withName: name) else {
return XCTFail("build configuration \(name) not found", file: file, line: line)
if Test.current != nil {
Issue.record("build configuration \(name) not found", sourceLocation: #_sourceLocation)
return
} else {
return XCTFail("build configuration \(name) not found", file: file, line: line)
}
}

body(PIFBuildConfigurationTester(buildConfiguration: configuration))
Expand Down Expand Up @@ -319,20 +365,42 @@ public final class PIFBuildSettingsTester {
}
}

public func checkUncheckedSettings(file: StaticString = #file, line: UInt = #line) {
public func checkUncheckedSettings(file: StaticString = #file, line: UInt = #line, sourceLocation: SourceLocation = #_sourceLocation) {
let uncheckedKeys =
Array(buildSettings.singleValueSettings.keys.map { $0.rawValue }) +
Array(buildSettings.multipleValueSettings.keys.map { $0.rawValue })
XCTAssert(uncheckedKeys.isEmpty, "settings are left unchecked: \(uncheckedKeys)", file: file, line: line)
if Test.current != nil {
#expect(
uncheckedKeys.isEmpty,
"settings are left unchecked: \(uncheckedKeys)",
sourceLocation: sourceLocation,
)
} else {
XCTAssert(uncheckedKeys.isEmpty, "settings are left unchecked: \(uncheckedKeys)", file: file, line: line)
}

for (platform, settings) in buildSettings.platformSpecificSingleValueSettings {
let uncheckedKeys = Array(settings.keys.map { $0.rawValue })
XCTAssert(uncheckedKeys.isEmpty, "\(platform) settings are left unchecked: \(uncheckedKeys)", file: file, line: line)
if Test.current != nil {
#expect(
uncheckedKeys.isEmpty, "\(platform) settings are left unchecked: \(uncheckedKeys)",
sourceLocation: sourceLocation,
)
} else {
XCTAssert(uncheckedKeys.isEmpty, "\(platform) settings are left unchecked: \(uncheckedKeys)", file: file, line: line)
}
}

for (platform, settings) in buildSettings.platformSpecificMultipleValueSettings {
let uncheckedKeys = Array(settings.keys.map { $0.rawValue })
XCTAssert(uncheckedKeys.isEmpty, "\(platform) settings are left unchecked: \(uncheckedKeys)", file: file, line: line)
if Test.current != nil {
#expect(
uncheckedKeys.isEmpty, "\(platform) settings are left unchecked: \(uncheckedKeys)",
sourceLocation: sourceLocation,
)
} else {
XCTAssert(uncheckedKeys.isEmpty, "\(platform) settings are left unchecked: \(uncheckedKeys)", file: file, line: line)
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/_InternalTestSupport/MockBuildTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import struct PackageGraph.ResolvedProduct
import PackageModel
import SPMBuildCore
import TSCUtility
import XCTest

public struct MockToolchain: PackageModel.Toolchain {
#if os(Windows)
Expand Down
22 changes: 19 additions & 3 deletions Sources/_InternalTestSupport/MockDependencyGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//
//===----------------------------------------------------------------------===//
import XCTest
import Testing

import PackageGraph
import PackageModel
Expand All @@ -32,15 +33,30 @@ public struct MockDependencyGraph {
public func checkResult(
_ output: [(container: PackageReference, version: Version)],
file: StaticString = #file,
line: UInt = #line
line: UInt = #line,
sourceLocation: SourceLocation = #_sourceLocation
) {
var result = self.result
for item in output {
XCTAssertEqual(result[item.container], item.version, file: file, line: line)
if Test.current != nil {
#expect(
result[item.container] == item.version,
sourceLocation: sourceLocation,
)
} else {
XCTAssertEqual(result[item.container], item.version, file: file, line: line)
}
result[item.container] = nil
}
if !result.isEmpty {
XCTFail("Unchecked containers: \(result)", file: file, line: line)
if Test.current != nil {
Issue.record(
"Unchecked containers: \(result)",
sourceLocation: sourceLocation,
)
} else {
XCTFail("Unchecked containers: \(result)", file: file, line: line)
}
}
}
}
1 change: 0 additions & 1 deletion Sources/_InternalTestSupport/MockPackageContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Dispatch
import PackageGraph
import PackageModel
import SourceControl
import XCTest

import struct TSCUtility.Version

Expand Down
Loading