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

Fix unexpected expansion #7

Merged
merged 5 commits into from
Oct 6, 2023
Merged

Fix unexpected expansion #7

merged 5 commits into from
Oct 6, 2023

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.
@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
2 checks passed
@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