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

Improve diffing of collections and structured values. #65

Closed
wants to merge 5 commits into from

Commits on Oct 16, 2023

  1. Improve diffing of collections and structured values.

    This PR improves the test output when comparing collections and structured values (using `#expect()`) when the comparison fails. Previously, we'd just the insertions and deletions as arrays, which was potentially hard to read and didn't show the test author _where_ these changes occurred. Now, we convert the compared values into something similar to multi-line `diff` output. Consider the following test function:
    
    ```swift
    @test func f() {
      let lhs = """
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
      non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      """
      let rhs = """
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      potato salad. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
      non dentistry, sunt in culpa qui officia deserunt mollit anim id est laborum.
      """
      #expect(lhs == rhs)
    }
    ```
    
    The output will now be:
    
    ```
    ◇ Test f() started.
    ✘ Test f() recorded an issue at MyTests.swift:45:5: Expectation failed: lhs == rhs
    ±  4 changes:
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod"
      "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,"
      "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo"
    + "potato salad. Duis aute irure dolor in reprehenderit in voluptate velit esse"
    - "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse"
      "cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat"
    + "non dentistry, sunt in culpa qui officia deserunt mollit anim id est laborum."
    - "non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    ✘ Test f() failed after 0.001 seconds with 1 issue.
    ```
    
    Similarly, with this test:
    
    ```swift
    struct S: Equatable {
      var x: Int
      var y: String
    }
    
    @test func f() {
      let lhs = S(x: 123, y: "abc")
      let rhs = S(x: 123, y: "def")
      #expect(lhs == rhs)
    }
    ```
    
    The output should appear similar to:
    
    ```
    ◇ Test f() started.
    ✘ Test f() recorded an issue at MyTests.swift:36:5: Expectation failed: lhs == rhs
    ± 1 change:
      MyTests.S(
        x: 123
    -   y: "abc"
    +   y: "def"
      )
    ✘ Test f() failed after 0.001 seconds with 1 issue.
    ```
    
    Resolves rdar://66351980.
    grynspan committed Oct 16, 2023
    Configuration menu
    Copy the full SHA
    43ba3c3 View commit details
    Browse the repository at this point in the history

Commits on Oct 17, 2023

  1. Remove BidirectionalCollection overload of __checkBinaryOperation() s…

    …ince we don't need it anymore
    grynspan committed Oct 17, 2023
    Configuration menu
    Copy the full SHA
    c002c3a View commit details
    Browse the repository at this point in the history

Commits on Oct 18, 2023

  1. Refactor to put control over the comparison logic into instead of so …

    …that types with specific needs can opt out of the default mirroring behaviour
    grynspan committed Oct 18, 2023
    Configuration menu
    Copy the full SHA
    e1da802 View commit details
    Browse the repository at this point in the history

Commits on Oct 21, 2023

  1. Some refactoring

    grynspan committed Oct 21, 2023
    Configuration menu
    Copy the full SHA
    a19ed58 View commit details
    Browse the repository at this point in the history

Commits on Oct 23, 2023

  1. Add a todo message

    grynspan committed Oct 23, 2023
    Configuration menu
    Copy the full SHA
    eacc1e1 View commit details
    Browse the repository at this point in the history