# swiftlang/swift-testing architecture

> Architecture diagram of the GitHub repository swiftlang/swift-testing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/swiftlang/swift-testing
- Repository: https://github.com/swiftlang/swift-testing

## Overview

a. Test Flow:
- Test Declaration (Macros) → Discovery → Runner → Event System → Recorders

b. Platform Integration:
- Core Engine ↔ Platform Overlays ↔ Native Platform APIs

c. ABI Communication:
- Test Runner ↔ ABI Layer ↔ External Tools

##### Important Subsystems (Use nested components)

a. Event System
- Clock
- Recorders (Console, Human Readable, JUnit XML)
- Event Types

b. Test Organization
- Tags
- Traits
- Parameterization
- Scoping

##### Cross-Cutting Concerns (Use horizontal layers)

a. Source Attribution
- Backtraces
- Source Location
- Expression Capture

b. Support Infrastructure
- Locking
- Error Handling
- Environment Management

##### External Integration Points (Use interface symbols)

a. Build Systems
- SwiftPM Integration
- CMake Support

b. Platform APIs
- Foundation
- CoreGraphics
- WASI (experimental)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Testing Engine"]
        Discovery["Test Discovery"]
        Runner["Test Runner"]
        Events["Event System"]
        Expect["Expectations Engine"]
        Issues["Issue Tracking"]
    end

    subgraph Macros["Macro System"]
        TestMacro["Test Macros"]
        TagMacro["Tag Macros"]
        CondMacro["Condition Macros"]
    end

    subgraph ABI["ABI Layer"]
        EntryPoints["Entry Points"]
        Version["Version Support (v0)"]
    end

    subgraph Platform["Platform Support"]
        Foundation["Foundation Support"]
        CoreGraphics["CoreGraphics Support"]
        WASI["WASI (experimental)"]
    end

    subgraph EventSystem["Event System Components"]
        Clock["Clock"]
        subgraph Recorders["Recorders"]
            Console["Console"]
            HumanReadable["Human Readable"]
            JUnitXML["JUnit XML"]
        end
        EventTypes["Event Types"]
    end

    subgraph Support["Support Infrastructure"]
        SourceAttr["Source Attribution"]
        TestParam["Test Parameterization"]
        Traits["Traits System"]
        Infrastructure["Infrastructure Components"]
    end

    Macros --> Discovery
    Discovery --> Runner
    Runner --> Events
    Events --> Recorders
    Runner <--> ABI
    Core <--> Platform
    Events --> EventSystem
    Support --> Core

    classDef core fill:#f9f,stroke:#333,stroke-width:2px
    classDef macro fill:#bbf,stroke:#333,stroke-width:2px
    classDef abi fill:#bfb,stroke:#333,stroke-width:2px
    classDef platform fill:#fbb,stroke:#333,stroke-width:2px
    classDef event fill:#fff,stroke:#333,stroke-width:2px
    classDef experimental fill:#ddd,stroke:#333,stroke-width:2px

    class Core,Discovery,Runner,Events,Expect,Issues core
    class Macros,TestMacro,TagMacro,CondMacro macro
    class ABI,EntryPoints,Version abi
    class Platform,Foundation,CoreGraphics,WASI platform
    class EventSystem,Clock,Recorders,Console,HumanReadable,JUnitXML,EventTypes event
    class WASI experimental

    click Discovery "https://github.com/swiftlang/swift-testing/blob/main/Sources/Testing/Discovery.swift"
    click Runner "https://github.com/swiftlang/swift-testing/blob/main/Sources/Testing/Running/Runner.swift"
    click Events "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/Events/"
    click Expect "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/Expectations/"
    click Issues "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/Issues/"
    click EntryPoints "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/ABI/EntryPoints/"
    click Version "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/ABI/v0/"
    click TestMacro "https://github.com/swiftlang/swift-testing/blob/main/Sources/TestingMacros/TestDeclarationMacro.swift"
    click TagMacro "https://github.com/swiftlang/swift-testing/blob/main/Sources/TestingMacros/TagMacro.swift"
    click CondMacro "https://github.com/swiftlang/swift-testing/blob/main/Sources/TestingMacros/ConditionMacro.swift"
    click Foundation "https://github.com/swiftlang/swift-testing/tree/main/Sources/Overlays/_Testing_Foundation/"
    click CoreGraphics "https://github.com/swiftlang/swift-testing/tree/main/Sources/Overlays/_Testing_CoreGraphics/"
    click Clock "https://github.com/swiftlang/swift-testing/blob/main/Sources/Testing/Events/Clock.swift"
    click Console "https://github.com/swiftlang/swift-testing/blob/main/Sources/Testing/Events/Recorder/Event.ConsoleOutputRecorder.swift"
    click HumanReadable "https://github.com/swiftlang/swift-testing/blob/main/Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift"
    click JUnitXML "https://github.com/swiftlang/swift-testing/blob/main/Sources/Testing/Events/Recorder/Event.JUnitXMLRecorder.swift"
    click EventTypes "https://github.com/swiftlang/swift-testing/blob/main/Sources/Testing/Events/Event.swift"
    click SourceAttr "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/SourceAttribution/"
    click TestParam "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/Parameterization/"
    click Traits "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/Traits/"
    click Infrastructure "https://github.com/swiftlang/swift-testing/tree/main/Sources/Testing/Support/"
```
