Skip to content

Tests: Convert SPMBuildCoreTests to Swift Testing #8625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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: 16 additions & 11 deletions Tests/SPMBuildCoreTests/ArtifactsArchiveMetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
// Copyright (c) 2014-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -12,10 +12,11 @@

import Basics
import PackageModel
import XCTest
import Testing

final class ArtifactsArchiveMetadataTests: XCTestCase {
func testParseMetadata() throws {
struct ArtifactsArchiveMetadataTests {
@Test
func parseMetadata() throws {
let fileSystem = InMemoryFileSystem()
try fileSystem.writeFileContents(
"/info.json",
Expand Down Expand Up @@ -43,7 +44,7 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
)

let metadata = try ArtifactsArchiveMetadata.parse(fileSystem: fileSystem, rootPath: .root)
XCTAssertEqual(metadata, try ArtifactsArchiveMetadata(
let expected = try ArtifactsArchiveMetadata(
schemaVersion: "1.0",
artifacts: [
"protocol-buffer-compiler": ArtifactsArchiveMetadata.Artifact(
Expand All @@ -61,9 +62,12 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
]
),
]
))
)
#expect(metadata == expected, "Actual is not as expected")
}
func testParseMetadataWithoutSupportedTriple() throws {

@Test
func parseMetadataWithoutSupportedTriple() throws {
let fileSystem = InMemoryFileSystem()
try fileSystem.writeFileContents(
"/info.json",
Expand All @@ -90,7 +94,7 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
)

let metadata = try ArtifactsArchiveMetadata.parse(fileSystem: fileSystem, rootPath: .root)
XCTAssertEqual(metadata, ArtifactsArchiveMetadata(
let expected = ArtifactsArchiveMetadata(
schemaVersion: "1.0",
artifacts: [
"protocol-buffer-compiler": ArtifactsArchiveMetadata.Artifact(
Expand All @@ -108,16 +112,17 @@ final class ArtifactsArchiveMetadataTests: XCTestCase {
]
),
]
))
)
#expect(metadata == expected, "Actual is not as expected")

let binaryTarget = BinaryModule(
name: "protoc", kind: .artifactsArchive, path: .root, origin: .local
)
// No supportedTriples with binaryTarget should be rejected
XCTAssertThrowsError(
#expect(throws: (any Error).self) {
try binaryTarget.parseArtifactArchives(
for: Triple("x86_64-apple-macosx"), fileSystem: fileSystem
)
)
}
}
}
15 changes: 7 additions & 8 deletions Tests/SPMBuildCoreTests/BuildParametersTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Copyright (c) 2024-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
Expand All @@ -14,18 +14,17 @@
import Basics
import struct PackageModel.BuildEnvironment
import _InternalTestSupport
import XCTest
import Testing

final class BuildParametersTests: XCTestCase {
func testConfigurationDependentProperties() throws {
// Ensure that properties that depend on the "configuration" property are
// correctly updated after modifying the configuration.
struct BuildParametersTests {
@Test
func configurationDependentProperties() throws {
var parameters = mockBuildParameters(
destination: .host,
environment: BuildEnvironment(platform: .linux, configuration: .debug)
)
XCTAssertEqual(parameters.enableTestability, true)
#expect(parameters.enableTestability)
parameters.configuration = .release
XCTAssertEqual(parameters.enableTestability, false)
#expect(!parameters.enableTestability)
}
}
75 changes: 40 additions & 35 deletions Tests/SPMBuildCoreTests/XCFrameworkMetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

import class Basics.InMemoryFileSystem
import SPMBuildCore
import XCTest
import Testing

final class XCFrameworkMetadataTests: XCTestCase {
func testParseFramework() throws {
struct XCFrameworkMetadataTests {
@Test
func parseFramework() throws {
let fileSystem = InMemoryFileSystem(files: [
"/Info.plist": """
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -62,28 +63,31 @@ final class XCFrameworkMetadataTests: XCTestCase {
])

let metadata = try XCFrameworkMetadata.parse(fileSystem: fileSystem, rootPath: .root)
XCTAssertEqual(metadata,
XCFrameworkMetadata(libraries: [
XCFrameworkMetadata.Library(
libraryIdentifier: "macos-x86_64",
libraryPath: "MyFramework.framework",
headersPath: nil,
platform: "macos",
architectures: ["x86_64"],
variant: nil
),
XCFrameworkMetadata.Library(
libraryIdentifier: "ios-arm64_x86_64-simulator",
libraryPath: "MyFramework.framework",
headersPath: nil,
platform: "ios",
architectures: ["arm64", "x86_64"],
variant: "simulator"
),
]))
let expected = XCFrameworkMetadata(
libraries: [
XCFrameworkMetadata.Library(
libraryIdentifier: "macos-x86_64",
libraryPath: "MyFramework.framework",
headersPath: nil,
platform: "macos",
architectures: ["x86_64"],
variant: nil
),
XCFrameworkMetadata.Library(
libraryIdentifier: "ios-arm64_x86_64-simulator",
libraryPath: "MyFramework.framework",
headersPath: nil,
platform: "ios",
architectures: ["arm64", "x86_64"],
variant: "simulator"
),
],
)
#expect(metadata == expected)
}

func testParseLibrary() throws {
@Test
func parseLibrary() throws {
let fileSystem = InMemoryFileSystem(files: [
"/Info.plist": """
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -117,17 +121,18 @@ final class XCFrameworkMetadataTests: XCTestCase {
])

let metadata = try XCFrameworkMetadata.parse(fileSystem: fileSystem, rootPath: .root)
XCTAssertEqual(metadata,
XCFrameworkMetadata(
libraries: [
XCFrameworkMetadata.Library(
libraryIdentifier: "macos-x86_64",
libraryPath: "MyLibrary.a",
headersPath: "Headers",
platform: "macos",
architectures: ["x86_64"],
variant: nil
),
]))
let expected = XCFrameworkMetadata(
libraries: [
XCFrameworkMetadata.Library(
libraryIdentifier: "macos-x86_64",
libraryPath: "MyLibrary.a",
headersPath: "Headers",
platform: "macos",
architectures: ["x86_64"],
variant: nil
),
],
)
#expect(metadata == expected)
}
}
Loading