Skip to content
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
4 changes: 2 additions & 2 deletions Sources/_InternalTestSupport/SwiftTesting+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public func expectThrowsCommandExecutionError<T>(
/// An `async`-friendly replacement for `XCTAssertThrowsError`.
public func expectAsyncThrowsError<T>(
_ expression: @autoclosure () async throws -> T,
_ message: @autoclosure () -> Comment = "",
_ message: @autoclosure () -> Comment? = nil,
sourceLocation: SourceLocation = #_sourceLocation,
_ errorHandler: (_ error: any Error) -> Void = { _ in }
) async {
do {
_ = try await expression()
Issue.record(message(), sourceLocation: sourceLocation)
Issue.record(message() ?? "Expected an error, which did not not.", sourceLocation: sourceLocation)
} catch {
errorHandler(error)
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/_InternalTestSupport/SwiftTesting+Tags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extension Tag.Feature {

extension Tag.Feature.Command {
public enum Package {}
public enum PackageRegistry {}
@Tag public static var Build: Tag
@Tag public static var Test: Tag
@Tag public static var Run: Tag
Expand All @@ -48,6 +49,15 @@ extension Tag.Feature.Command.Package {
@Tag public static var ToolsVersion: Tag
}

extension Tag.Feature.Command.PackageRegistry {
@Tag public static var General: Tag
@Tag public static var Login: Tag
@Tag public static var Logout: Tag
@Tag public static var Publish: Tag
@Tag public static var Set: Tag
@Tag public static var Unset: Tag
}

extension Tag.Feature.PackageType {
@Tag public static var Library: Tag
@Tag public static var Executable: Tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import class PackageModel.UserToolchain
import DriverSupport
import Basics
import Testing
import TSCclibc // for SPM_posix_spawn_file_actions_addchdir_np_supported

extension Trait where Self == Testing.ConditionTrait {
/// Skip test if the host operating system does not match the running OS.
Expand Down Expand Up @@ -67,6 +68,22 @@ extension Trait where Self == Testing.ConditionTrait {
requiresHostLibrary(lib: "libSwiftSyntaxMacros.dylib")
}

/// Ensure platform support working directory
public static var requiresWorkingDirectorySupport: Self {
enabled("working directory not supported on this platform") {
#if !os(Windows)
// needed for archiving
if SPM_posix_spawn_file_actions_addchdir_np_supported() {
return true
} else {
return false
}
#else
return true
#endif
}
}

/// Skip test unconditionally
public static func skip(_ comment: Comment? = nil) -> Self {
disabled(comment ?? "Unconditional skip, a comment should be added for the reason") { true }
Expand Down
74 changes: 41 additions & 33 deletions Tests/CommandsTests/MermaidPackageSerializerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
//
// 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
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Foundation

import class Basics.InMemoryFileSystem
import class Basics.ObservabilitySystem
Expand All @@ -24,14 +25,20 @@ import func _InternalTestSupport.XCTAssertNoDiagnostics
@testable
import Commands

import XCTest
import Testing
import _InternalTestSupport

final class MermaidPackageSerializerTests: XCTestCase {
func testSimplePackage() throws {
struct MermaidPackageSerializerTests {
@Test(
.tags(
.TestSize.medium, //?
),
)
func simplePackage() throws {
let observability = ObservabilitySystem.makeForTesting()
let fileSystem = InMemoryFileSystem(
emptyFiles:
"/A/Sources/ATarget/main.swift",
"/A/Sources/ATarget/main.swift",
"/A/Tests/ATargetTests/TestCases.swift"
)
let graph = try loadModulesGraph(
Expand All @@ -48,14 +55,12 @@ final class MermaidPackageSerializerTests: XCTestCase {
],
observabilityScope: observability.topScope
)
XCTAssertNoDiagnostics(observability.diagnostics)
expectNoDiagnostics(observability.diagnostics)

XCTAssertEqual(graph.packages.count, 1)
let package = try XCTUnwrap(graph.packages.first)
#expect(graph.packages.count == 1)
let package = try #require(graph.packages.first)
let serializer = MermaidPackageSerializer(package: package.underlying)
XCTAssertEqual(
serializer.renderedMarkdown,
"""
#expect(serializer.renderedMarkdown == """
```mermaid
flowchart TB
subgraph a
Expand All @@ -65,14 +70,18 @@ final class MermaidPackageSerializerTests: XCTestCase {
end
```

"""
)
""")
}

func testDependenciesOnProducts() throws {
@Test(
.tags(
.TestSize.medium, //?
),
)
func dependenciesOnProducts() throws {
let fileSystem = InMemoryFileSystem(
emptyFiles:
"/A/Sources/ATarget/foo.swift",
"/A/Sources/ATarget/foo.swift",
"/A/Tests/ATargetTests/foo.swift",
"/B/Sources/BTarget/foo.swift",
"/B/Tests/BTargetTests/foo.swift"
Expand Down Expand Up @@ -107,14 +116,12 @@ final class MermaidPackageSerializerTests: XCTestCase {
],
observabilityScope: observability.topScope
)
XCTAssertNoDiagnostics(observability.diagnostics)
expectNoDiagnostics(observability.diagnostics)

XCTAssertEqual(graph.packages.count, 2)
let package = try XCTUnwrap(graph.package(for: .plain("A")))
#expect(graph.packages.count == 2)
let package = try #require(graph.package(for: .plain("A")))
let serializer = MermaidPackageSerializer(package: package.underlying)
XCTAssertEqual(
serializer.renderedMarkdown,
"""
#expect(serializer.renderedMarkdown == """
```mermaid
flowchart TB
subgraph a
Expand All @@ -124,14 +131,18 @@ final class MermaidPackageSerializerTests: XCTestCase {
end
```

"""
)
""")
}

func testDependenciesOnPackages() throws {
@Test(
.tags(
.TestSize.medium, //?
),
)
func dependenciesOnPackages() throws {
let fileSystem = InMemoryFileSystem(
emptyFiles:
"/A/Sources/ATarget/foo.swift",
"/A/Sources/ATarget/foo.swift",
"/A/Tests/ATargetTests/foo.swift",
"/B/Sources/BTarget/foo.swift",
"/B/Tests/BTargetTests/foo.swift"
Expand Down Expand Up @@ -166,14 +177,12 @@ final class MermaidPackageSerializerTests: XCTestCase {
],
observabilityScope: observability.topScope
)
XCTAssertNoDiagnostics(observability.diagnostics)
expectNoDiagnostics(observability.diagnostics)

XCTAssertEqual(graph.packages.count, 2)
let package = try XCTUnwrap(graph.package(for: .plain("A")))
#expect(graph.packages.count == 2)
let package = try #require(graph.package(for: .plain("A")))
let serializer = MermaidPackageSerializer(package: package.underlying)
XCTAssertEqual(
serializer.renderedMarkdown,
"""
#expect(serializer.renderedMarkdown == """
```mermaid
flowchart TB
subgraph a
Expand All @@ -186,7 +195,6 @@ final class MermaidPackageSerializerTests: XCTestCase {
end
```

"""
)
""")
}
}
Loading