Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #initFixture macro #15

Merged
merged 9 commits into from
Jul 17, 2023
Merged

Add #initFixture macro #15

merged 9 commits into from
Jul 17, 2023

Conversation

liamnichols
Copy link
Owner

@liamnichols liamnichols commented Jul 3, 2023

Turn this:

fixture.register(Item.self) { values in
    Item(
        title: try values.get("title"),
        owner: try values.get("owner")
    )
}

Into this:

fixture.register(Item.self) { values in
    #initFixture(with: values, using: Item.init(title:owner:))
}

Used internally by @ProvideFixture, but also we can probably also introduce another new macro:

class MyTests: XCTestCase {
    let fixture = Fixture()

    override func setUp() {
        super.setUp()
        
        #register(Item.init(title:owner:), in: fixture)
    }
    
    // ...    
}

But ☝️ might be redundant because we could also leverage unapplied method references in @ProvideFixture(using: User.init(foo:bar:)) on extensions as a way to solve #13 at the same time. Attaching extension macros to extensions will not be possible in Swift 5.9

@liamnichols
Copy link
Owner Author

Using #initFixture inside closures is currently blocked by swiftlang/swift#67102

@liamnichols liamnichols marked this pull request as ready for review July 17, 2023 14:36
@liamnichols liamnichols merged commit d97fc96 into main Jul 17, 2023
@liamnichols liamnichols deleted the ln/init-fixture-macro branch July 17, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant