Giter Site home page Giter Site logo

curiositysoftware / swift-fatal-test-value Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 39 KB

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

License: MIT License

Swift 100.00%
tca testability swiftmacros

swift-fatal-test-value's Introduction

swift-fatal-test-value

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

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

swift-fatal-test-value's People

Contributors

yimajo avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

swift-fatal-test-value's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.