Contents

CuriositySoftware/swift-fatal-test-value

This Swift macro auto-injects fatalError() into initializers, streamlining the setup of unit tests for Dependency Injected components.

Quick start

To get started, import FatalTestValue: import FatalTestValue, annotate your struct or class with @FatalTestValue:

import FatalTestValue

@FatalTestValue
struct Example {
    var create: @Sendable (Int) async throws -> Void
    var read: @Sendable (Int) async throws -> String
    var update: @Sendable (Int, String) async throws -> Void
    var delete: (Int) -> Void
}

This will automatically generate an extension with a testValue property.

extension Example {
    public static let testValue = Example(
        create: { _ in
            fatalError()
        },
        read: { _ in
            fatalError()
        },
        update: { _, _ in
            fatalError()
        },
        delete: { _ in
            fatalError()
        }
    )
}

Installation

For Xcode

If you are using GUI to set up Package Dependencies in Xcode, add the URL in Pacakge Dependencies.

https://github.com/CuriositySoftware/swift-fatal-test-value

For Package.swift

If you are using Package.swift add:

.package(
    url: "https://github.com/CuriositySoftware/swift-fatal-test-value/",
    .upToNextMajor(from: "1.0.0")
)

and then add the product to any target that needs access to the macro:

.product(
    name: "FatalTestValue",
    package: "swift-fatal-test-value"
)

Package Metadata

Repository: CuriositySoftware/swift-fatal-test-value

Stars: 4

Forks: 0

Open issues: 0

Default branch: main

Primary language: swift

License: MIT

Topics: swiftmacros, tca, testability

README: README.md