In the past there was some interest in taking inspiration from the tools in our CustomDump library to provide nicer test failure messages. Is this still the case?
As an example, the currently proposed test failure message:
Expectation failed: crushinator == truckasaurusRex
β³ crushinator == truckasaurusRex β false
β³ crushinator β MonsterTruck(color: MyLibraryTests.MonsterTruck.Color.red, numberOfWheels: 4)
β³ color β .red
β³ numberOfWheels β 4
β³ truckasaurusRex β MonsterTruck(color: MyLibraryTests.MonsterTruck.Color.green, numberOfWheels: 5)
β³ color β .green
β³ numberOfWheels β 5
β¦becomes this:
Issue recorded: Difference: β¦
MonsterTruck(
β color: .red,
+ color: .green,
β numberOfWheels: 4
+ numberOfWheels: 5
)
(First: β, Second: +)
And if there are more fields, things become more readable. For example, using a real world example from one of our demos, this test failure:
β³ Row(player: Player(id: UUID(-3), gameID: UUID(-1), name: "Blob Jr", score: 2)) == Row(player: Player(id: UUID(-3), gameID: UUID(-1), name: "Blob Jr.", score: 2)) β false
β³ Row(player: Player(id: UUID(-3), gameID: UUID(-1), name: "Blob Jr", score: 2)) β Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000003, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Jr", score: 2, nickname: "", recordHighScore: 0, age: 0, credits: 0), imageData: nil)
β³ player β Player(id: 00000000-0000-0001-0000-000000000003, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Jr", score: 2, nickname: "", recordHighScore: 0, age: 0, credits: 0)
β³ id β 00000000-0000-0001-0000-000000000003
β³ gameID β 00000000-0000-0001-0000-000000000001
β³ name β "Blob Jr"
β³ score β 2
β³ nickname β ""
β³ recordHighScore β 0
β³ age β 0
β³ credits β 0
β³ imageData β nil
β³ Row(player: Player(id: UUID(-3), gameID: UUID(-1), name: "Blob Jr.", score: 2)) β Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000003, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Jr.", score: 2, nickname: "", recordHighScore: 0, age: 0, credits: 0), imageData: nil)
β³ player β Player(id: 00000000-0000-0001-0000-000000000003, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Jr.", score: 2, nickname: "", recordHighScore: 0, age: 0, credits: 0)
β³ id β 00000000-0000-0001-0000-000000000003
β³ gameID β 00000000-0000-0001-0000-000000000001
β³ name β "Blob Jr."
β³ score β 2
β³ nickname β ""
β³ recordHighScore β 0
β³ age β 0
β³ credits β 0
β³ imageData β nil
β¦becomes this:
Issue recorded: Difference: β¦
Row(
player: Player(
id: UUID(00000000-0000-0001-0000-000000000003),
gameID: UUID(00000000-0000-0001-0000-000000000001),
β name: "Blob Jr",
+ name: "Blob Jr.",
score: 2,
nickname: "",
recordHighScore: 0,
age: 0,
credits: 0
),
imageData: nil
)
(First: β, Second: +)
Further, we can expand the nice printing of failure messages to more complex data structures, like arrays and dictionaries. So, a test failure like this:
β³ lhs == rhs β false
β³ lhs β [MyLibraryTests.Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000002, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Sr", score: 3), imageData: nil), MyLibraryTests.Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000003, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Jr", score: 2), imageData: nil), MyLibraryTests.Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000001, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob", score: 1), imageData: nil)]
β³ rhs β [MyLibraryTests.Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000002, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Sr", score: 3), imageData: nil), MyLibraryTests.Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000003, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob Jr.", score: 2), imageData: nil), MyLibraryTests.Row(player: MyLibraryTests.Player(id: 00000000-0000-0001-0000-000000000001, gameID: 00000000-0000-0001-0000-000000000001, name: "Blob", score: 1), imageData: nil)]
β¦becomes this:
Issue recorded: Difference: β¦
[
[0]: Row(
player: Player(
id: UUID(00000000-0000-0001-0000-000000000002),
gameID: UUID(00000000-0000-0001-0000-000000000001),
β name: "Blob Sr",
+ name: "Blob Sr.",
score: 3
),
imageData: nil
),
β¦ (2 unchanged)
]
(First: β, Second: +)
I also think it'd be nice for this protocol to live outside of Swift Testing. That would make it possible to expose private/internal data to the error messages, and would pave the way for better debugging tools in non-testing environments.