kishikawakatsumi / swift-power-assert

Power Assert in Swift.

Home Page:https://power-assert.swiftfiddle.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

3 tests failing on main branch

amomchilov opened this issue · comments

Hmmm, I'm not sure if something is wrong with my local setup, but I'm seeing 3 tests fail on main (at 6fc37b):

  1. testTryExpression1

    diff
        diff --git a/testTryExpression1_expected.txt b/testTryExpression1_actual.txt
    index 7753e42..c15db45 100644
    --- a/testTryExpression1_expected.txt
    +++ b/testTryExpression1_actual.txt
    @@ -5,16 +5,16 @@
                │             │      │         │  "{ \"name\": \"Tokyo Tower\" }"
                │             │      │         false
                │             │      Landmark(name: "Tokyo Tower", foundingYear: 1957, location: PowerAssertTests.Coordinate(latitude: 35.658581, longitude: 139.745438))
    -             │             Optional(99 bytes)
    +             │             Optional(116 bytes)
                Foundation.JSONEncoder
    
    --- [Optional<Data>] JSONEncoder().encode(landmark)
    +++ [Optional<Data>] #"{ "name": "Tokyo Tower" }"#.data(using: String.Encoding.utf8)
    -–Optional(99 bytes)
    +–Optional(116 bytes)
    +Optional(25 bytes)
    
    [Optional<Data>] JSONEncoder().encode(landmark)
    -=> Optional(99 bytes)
    +=> Optional(116 bytes)
    [Optional<Data>] #"{ "name": "Tokyo Tower" }"#.data(using: String.Encoding.utf8)
    => Optional(25 bytes)
    
    @@ -25,23 +25,23 @@
                │             │      │         │  "{ \"name\": \"Tokyo Tower\" }"
                │             │      │         false
                │             │      Landmark(name: "Tokyo Tower", foundingYear: 1957, location: PowerAssertTests.Coordinate(latitude: 35.658581, longitude: 139.745438))
    -             │             Optional(99 bytes)
    +             │             Optional(116 bytes)
                Foundation.JSONEncoder
    
    --- [Optional<Data>] JSONEncoder().encode(landmark)
    +++ [Optional<Data>] #"{ "name": "Tokyo Tower" }"#.data(using: .utf8)
    -–Optional(99 bytes)
    +–Optional(116 bytes)
    +Optional(25 bytes)
    
    [Optional<Data>] JSONEncoder().encode(landmark)
    -=> Optional(99 bytes)
    +=> Optional(116 bytes)
    [Optional<Data>] #"{ "name": "Tokyo Tower" }"#.data(using: .utf8)
    => Optional(25 bytes)
    
    #assert(try! #"{ "name": "Tokyo Tower" }"#.data(using: String.Encoding.utf8) == JSONEncoder().encode(landmark))
                │                             │           │      │        │     │  │             │      │
                │                             │           String Encoding │     │  │             │      Landmark(name: "Tokyo Tower", foundingYear: 1957, location: PowerAssertTests.Coordinate(latitude: 35.658581, longitude: 139.745438))
    -             │                             Optional(25 bytes)          │     │  │             Optional(99 bytes)
    +             │                             Optional(25 bytes)          │     │  │             Optional(116 bytes)
                "{ \"name\": \"Tokyo Tower\" }"                           │     │  Foundation.JSONEncoder
                                                                            │     false
                                                                            Unicode (UTF-8)
    @@ -49,9 +49,9 @@
    --- [Optional<Data>] #"{ "name": "Tokyo Tower" }"#.data(using: String.Encoding.utf8)
    +++ [Optional<Data>] JSONEncoder().encode(landmark)
    –Optional(25 bytes)
    -+Optional(99 bytes)
    ++Optional(116 bytes)
    
    [Optional<Data>] #"{ "name": "Tokyo Tower" }"#.data(using: String.Encoding.utf8)
    => Optional(25 bytes)
    [Optional<Data>] JSONEncoder().encode(landmark)
    -=> Optional(99 bytes)
    +=> Optional(116 bytes)
  2. testTryExpression1

    diff
    diff --git a/testTryExpression2_expected.txt b/testTryExpression2_actual.txt
    index f681dd6..23e8166 100644
    --- a/testTryExpression2_expected.txt
    +++ b/testTryExpression2_actual.txt
    @@ -1,12 +1,12 @@
    #assert(try JSONEncoder().encode(landmark).count > 200)
                │             │      │         │     │ │
    -            │             │      │         99    │ 200
    +            │             │      │         116   │ 200
                │             │      │               false
                │             │      Landmark(name: "Tokyo Tower", foundingYear: 1957, location: PowerAssertTests.Coordinate(latitude: 35.658581, longitude: 139.745438))
    -            │             99 bytes
    +            │             116 bytes
                Foundation.JSONEncoder
    
    [Int] JSONEncoder().encode(landmark).count
    -=> 99
    +=> 116
    [Int] 200
    => 200
  3. testRegexLiteral

    diff
    diff --git a/testRegexLiteral_expected.txt b/testRegexLiteral_actual.txt
    index aa2664e..52d49f5 100644
    --- a/testRegexLiteral_expected.txt
    +++ b/testRegexLiteral_actual.txt
    @@ -2,16 +2,16 @@
                │     │              │                                                             │  │
                │     │              "CREDIT    03/01/2022    Payroll from employer      $200.23"  │  _OptionalNilComparisonType()
                │     │                                                                            false
    -            │     Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655364)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724))))
    +            │     Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655623)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983))))
                Regex<(Substring, Substring, Substring)>(program: _StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Program)
    
    --- [Optional<Match>] regex.firstMatch(in: "CREDIT    03/01/2022    Payroll from employer      $200.23")
    +++ [_OptionalNilComparisonType] nil
    -–Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655364)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724))))
    +–Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655623)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983))))
    +_OptionalNilComparisonType()
    
    [Optional<Match>] regex.firstMatch(in: "CREDIT    03/01/2022    Payroll from employer      $200.23")
    -=> Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655364)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724))))
    +=> Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655623)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983))))
    [_OptionalNilComparisonType] nil
    => _OptionalNilComparisonType()
    
    @@ -19,11 +19,11 @@
                │                                            │              │                                                              │      │ │  │       │      │
                │                                            │              "CREDIT    03/01/2022    Payroll from employer      $200.23"   │      │ │  │       │      Optional("CREDIT")
                │                                            │                                                                             │      │ │  │       Optional(("CREDIT    03/01/2022", "CREDIT", "03/01/2022"))
    -            │                                            │                                                                             │      │ │  Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655364)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724))))
    +            │                                            │                                                                             │      │ │  Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655623)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983))))
                │                                            │                                                                             │      │ false
                │                                            │                                                                             │      Optional("CREDIT    03/01/2022")
                │                                            │                                                                             Optional(("CREDIT    03/01/2022", "CREDIT", "03/01/2022"))
    -            │                                            Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655364)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724))))
    +            │                                            Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655623)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983))))
                Regex<(Substring, Substring, Substring)>(program: _StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Program)
    
    --- [Optional<Substring>] #/(CREDIT|DEBIT)\s+(\d{1,2}/\d{1,2}/\d{4})/#.firstMatch(in: "CREDIT    03/01/2022    Payroll from employer      $200.23")?.output.0
    @@ -42,7 +42,7 @@
                │                                            │                                                                             │      │ false
                │                                            │                                                                             │      Optional("CREDIT")
                │                                            │                                                                             Optional(("CREDIT    03/01/2022", "CREDIT", "03/01/2022"))
    -            │                                            Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655364)..<Swift.String.Index(_rawBits: 1310724)), value: nil)), name: nil, referenceID: nil, visibleInTypedOutput: true)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310724))))
    +            │                                            Optional(_StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Match(anyRegexOutput: _StringProcessing.AnyRegexOutput(input: "CREDIT    03/01/2022    Payroll from employer      $200.23", _elements: [_StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 393221)), value: nil)), name: nil, referenceID: nil), _StringProcessing.AnyRegexOutput.ElementRepresentation(optionalDepth: 0, content: Optional((range: Range(Swift.String.Index(_rawBits: 655623)..<Swift.String.Index(_rawBits: 1310983)), value: nil)), name: nil, referenceID: nil)]), range: Range(Swift.String.Index(_rawBits: 15)..<Swift.String.Index(_rawBits: 1310983))))
                Regex<(Substring, Substring, Substring)>(program: _StringProcessing.Regex<(Swift.Substring, Swift.Substring, Swift.Substring)>.Program)
    
    --- [Optional<Substring>] #/(CREDIT|DEBIT)\s+(\d{1,2}/\d{1,2}/\d{4})/#.firstMatch(in: "CREDIT    03/01/2022    Payroll from employer      $200.23")?.output.1

My setup is nothing special, just the latest Xcode beta on macOS.

$ swift --version
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0

Have you seen this before? Should I investigate further?

The mismatch is due to a change in JSONEncoder/Decoder's handling of floating numbers in iOS 17 and Sonoma.

The Regex one is also an internal change by the OS as well, although I can't recall exactly.

FYI

iOS 17, Sonoma and Linux

{"foundingYear":1957,"location":{"longitude":139.745438,"latitude":35.658581},"name":"Tokyo Tower"}

iOS 16.x and macOS Monterey

{"name":"Tokyo Tower","location":{"longitude":139.74543800000001,"latitude":35.658580999999998},"foundingYear":1957}

Ahhh I suspected it might have something to do with Double formatting.

This is odd, do you know why this changed between Sonoma and Monterey?

Does it have something to do with the new native-Swift implementation of Foundation? https://www.swift.org/blog/future-of-foundation/

I don't know why. But the results were different from Linux, so they wanted to adapt to Linux. Perhaps there was some OS-dependent processing internally macOS and iOS.