swift-fatal-test-value

1.0.1

This Swift macro auto-injects fatalError() into initializers, streamlining the setup of unit tests for Dependency Injected components.
CuriositySoftware/swift-fatal-test-value

What's New

v1.0.1

2023-11-06T07:39:38Z

What's Changed

  • Delete Assertions.swift by @yimajo in #1
  • Add badges in README.md by @yimajo in #2
  • Fix import module name by @yimajo in #4
  • Run tests with GitHub Actions by @yimajo in #5
  • Remove swift-testing by @yimajo in #7
  • SwiftSyntax version specification changed to upToNextMajor by @yimajo in #6
  • Update Instration in README.md by @yimajo in #8

New Contributors

  • @yimajo made their first contribution in #1

Full Changelog: v1.0.0...v1.0.1

swift-fatal-test-value

Swift Package Manager License

This macro eliminates boilerplate needed to set initial values of Dependency Injected instances' methods in unit tests. By simply annotating a struct or class with @FatalTestValue, it auto-generates an initializer invoking fatalError() for the closure.

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()
        }
    )
}

Instaration

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"
)

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Mon Dec 16 2024 02:20:50 GMT-1000 (Hawaii-Aleutian Standard Time)