Skip to content

Commit a40b433

Browse files
authored
Tests: Convert SPMBuildCoreTests to Swift Testing (#8625)
Convert the Tests/SwiftBuildCoreTests/*.swift, and Tests/_InternalTestSupport/Misc.swift to Swift Testing.
1 parent a3cd491 commit a40b433

File tree

4 files changed

+169
-185
lines changed

4 files changed

+169
-185
lines changed

Tests/SPMBuildCoreTests/ArtifactsArchiveMetadataTests.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -12,10 +12,11 @@
1212

1313
import Basics
1414
import PackageModel
15-
import XCTest
15+
import Testing
1616

17-
final class ArtifactsArchiveMetadataTests: XCTestCase {
18-
func testParseMetadata() throws {
17+
struct ArtifactsArchiveMetadataTests {
18+
@Test
19+
func parseMetadata() throws {
1920
let fileSystem = InMemoryFileSystem()
2021
try fileSystem.writeFileContents(
2122
"/info.json",
@@ -43,7 +44,7 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
4344
)
4445

4546
let metadata = try ArtifactsArchiveMetadata.parse(fileSystem: fileSystem, rootPath: .root)
46-
XCTAssertEqual(metadata, try ArtifactsArchiveMetadata(
47+
let expected = try ArtifactsArchiveMetadata(
4748
schemaVersion: "1.0",
4849
artifacts: [
4950
"protocol-buffer-compiler": ArtifactsArchiveMetadata.Artifact(
@@ -61,9 +62,12 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
6162
]
6263
),
6364
]
64-
))
65+
)
66+
#expect(metadata == expected, "Actual is not as expected")
6567
}
66-
func testParseMetadataWithoutSupportedTriple() throws {
68+
69+
@Test
70+
func parseMetadataWithoutSupportedTriple() throws {
6771
let fileSystem = InMemoryFileSystem()
6872
try fileSystem.writeFileContents(
6973
"/info.json",
@@ -90,7 +94,7 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
9094
)
9195

9296
let metadata = try ArtifactsArchiveMetadata.parse(fileSystem: fileSystem, rootPath: .root)
93-
XCTAssertEqual(metadata, ArtifactsArchiveMetadata(
97+
let expected = ArtifactsArchiveMetadata(
9498
schemaVersion: "1.0",
9599
artifacts: [
96100
"protocol-buffer-compiler": ArtifactsArchiveMetadata.Artifact(
@@ -108,16 +112,17 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
108112
]
109113
),
110114
]
111-
))
115+
)
116+
#expect(metadata == expected, "Actual is not as expected")
112117

113118
let binaryTarget = BinaryModule(
114119
name: "protoc", kind: .artifactsArchive, path: .root, origin: .local
115120
)
116121
// No supportedTriples with binaryTarget should be rejected
117-
XCTAssertThrowsError(
122+
#expect(throws: (any Error).self) {
118123
try binaryTarget.parseArtifactArchives(
119124
for: Triple("x86_64-apple-macosx"), fileSystem: fileSystem
120125
)
121-
)
126+
}
122127
}
123128
}

Tests/SPMBuildCoreTests/BuildParametersTests.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024-2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -14,18 +14,17 @@
1414
import Basics
1515
import struct PackageModel.BuildEnvironment
1616
import _InternalTestSupport
17-
import XCTest
17+
import Testing
1818

19-
final class BuildParametersTests: XCTestCase {
20-
func testConfigurationDependentProperties() throws {
21-
// Ensure that properties that depend on the "configuration" property are
22-
// correctly updated after modifying the configuration.
19+
struct BuildParametersTests {
20+
@Test
21+
func configurationDependentProperties() throws {
2322
var parameters = mockBuildParameters(
2423
destination: .host,
2524
environment: BuildEnvironment(platform: .linux, configuration: .debug)
2625
)
27-
XCTAssertEqual(parameters.enableTestability, true)
26+
#expect(parameters.enableTestability)
2827
parameters.configuration = .release
29-
XCTAssertEqual(parameters.enableTestability, false)
28+
#expect(!parameters.enableTestability)
3029
}
3130
}

Tests/SPMBuildCoreTests/XCFrameworkMetadataTests.swift

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212

1313
import class Basics.InMemoryFileSystem
1414
import SPMBuildCore
15-
import XCTest
15+
import Testing
1616

17-
final class XCFrameworkMetadataTests: XCTestCase {
18-
func testParseFramework() throws {
17+
struct XCFrameworkMetadataTests {
18+
@Test
19+
func parseFramework() throws {
1920
let fileSystem = InMemoryFileSystem(files: [
2021
"/Info.plist": """
2122
<?xml version="1.0" encoding="UTF-8"?>
@@ -62,28 +63,31 @@ final class XCFrameworkMetadataTests: XCTestCase {
6263
])
6364

6465
let metadata = try XCFrameworkMetadata.parse(fileSystem: fileSystem, rootPath: .root)
65-
XCTAssertEqual(metadata,
66-
XCFrameworkMetadata(libraries: [
67-
XCFrameworkMetadata.Library(
68-
libraryIdentifier: "macos-x86_64",
69-
libraryPath: "MyFramework.framework",
70-
headersPath: nil,
71-
platform: "macos",
72-
architectures: ["x86_64"],
73-
variant: nil
74-
),
75-
XCFrameworkMetadata.Library(
76-
libraryIdentifier: "ios-arm64_x86_64-simulator",
77-
libraryPath: "MyFramework.framework",
78-
headersPath: nil,
79-
platform: "ios",
80-
architectures: ["arm64", "x86_64"],
81-
variant: "simulator"
82-
),
83-
]))
66+
let expected = XCFrameworkMetadata(
67+
libraries: [
68+
XCFrameworkMetadata.Library(
69+
libraryIdentifier: "macos-x86_64",
70+
libraryPath: "MyFramework.framework",
71+
headersPath: nil,
72+
platform: "macos",
73+
architectures: ["x86_64"],
74+
variant: nil
75+
),
76+
XCFrameworkMetadata.Library(
77+
libraryIdentifier: "ios-arm64_x86_64-simulator",
78+
libraryPath: "MyFramework.framework",
79+
headersPath: nil,
80+
platform: "ios",
81+
architectures: ["arm64", "x86_64"],
82+
variant: "simulator"
83+
),
84+
],
85+
)
86+
#expect(metadata == expected)
8487
}
8588

86-
func testParseLibrary() throws {
89+
@Test
90+
func parseLibrary() throws {
8791
let fileSystem = InMemoryFileSystem(files: [
8892
"/Info.plist": """
8993
<?xml version="1.0" encoding="UTF-8"?>
@@ -117,17 +121,18 @@ final class XCFrameworkMetadataTests: XCTestCase {
117121
])
118122

119123
let metadata = try XCFrameworkMetadata.parse(fileSystem: fileSystem, rootPath: .root)
120-
XCTAssertEqual(metadata,
121-
XCFrameworkMetadata(
122-
libraries: [
123-
XCFrameworkMetadata.Library(
124-
libraryIdentifier: "macos-x86_64",
125-
libraryPath: "MyLibrary.a",
126-
headersPath: "Headers",
127-
platform: "macos",
128-
architectures: ["x86_64"],
129-
variant: nil
130-
),
131-
]))
124+
let expected = XCFrameworkMetadata(
125+
libraries: [
126+
XCFrameworkMetadata.Library(
127+
libraryIdentifier: "macos-x86_64",
128+
libraryPath: "MyLibrary.a",
129+
headersPath: "Headers",
130+
platform: "macos",
131+
architectures: ["x86_64"],
132+
variant: nil
133+
),
134+
],
135+
)
136+
#expect(metadata == expected)
132137
}
133138
}

0 commit comments

Comments
 (0)