Skip to content

Conversation

@stephencelis
Copy link
Member

This contains swift-snapshot-testing updates that should hopefully fix #6.

@gohanlon Can you give this branch a try and let us know if it fixes things for you?

This brings in the latest versions of Apple's macro demos and tests from
SwiftSyntax.
@stephencelis stephencelis requested a review from mbrandonw October 6, 2023 06:04
@stephencelis stephencelis mentioned this pull request Oct 6, 2023
2 tasks
@gohanlon
Copy link
Contributor

gohanlon commented Oct 6, 2023

Thanks @stephencelis! This does fix #6 for me: No crash, and now I get nice test failures. 🎉


Here's what I did to verify the fix:

After adopting this PR, starting with this (malformed) test:

  func testVarPropertyWithInitializerWithoutExplicitType_FailsWithDiagnostic() {
    assertMacro {
      """
      @MemberwiseInit
      public struct Pedometer {
        var stepsToday = 0
      }
      """
    } expansion: {
      """
      @MemberwiseInit
      public struct Pedometer {
        var stepsToday = 0
            ┬─────────────
            ╰─ 🛑 @MemberwiseInit requires explicit type declarations for `var` stored properties.
      }
      """
    }
  }

I then run the test, which re-records automatically as follows:

  func testVarPropertyWithInitializerWithoutExplicitType_FailsWithDiagnostic() {
    assertMacro {
      """
      @MemberwiseInit
      public struct Pedometer {
        var stepsToday = 0
      }
      """
    } diagnostics: {
      """
      @MemberwiseInit
      public struct Pedometer {
        var stepsToday = 0
            ┬─────────────
            ╰─ 🛑 @MemberwiseInit requires explicit type declarations for `var` stored properties.
      }
      """
    } expansion: {
      """
      @MemberwiseInit
      public struct Pedometer {
        var stepsToday = 0
            ┬─────────────
            ╰─ 🛑 @MemberwiseInit requires explicit type declarations for `var` stored properties.
      }
      """
    }
  }

As I'd expect, the recording run has the following two test failures:

…/gohanlon/swift-memberwise-init-macro/Tests/MemberwiseInitTests/MemberwiseInitTests.swift:276 testVarPropertyWithInitializerWithoutExplicitType_FailsWithDiagnostic():
🛑 failed - Automatically recorded a new snapshot for "diagnostics".

Re-run "testVarPropertyWithInitializerWithoutExplicitType_FailsWithDiagnostic()" to assert against the newly-recorded snapshot.

and:

…/gohanlon/swift-memberwise-init-macro/Tests/MemberwiseInitTests/MemberwiseInitTests.swift:276 testVarPropertyWithInitializerWithoutExplicitType_FailsWithDiagnostic():
🛑 failed - Expected macro expansion, but there was none

Then I ran the test again and, as I'd expect, I get just the second failure.

@stephencelis stephencelis merged commit 0727d7f into main Oct 6, 2023
@stephencelis stephencelis deleted the fix-unexpected-expansion branch October 6, 2023 21:05
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.

Fatal error on incorrect usage

3 participants