swiftlang / swift-corelibs-xctest

The XCTest Project, A Swift core library for providing unit test support
swift.org
Apache License 2.0
1.15k stars 267 forks source link

Misleading string-ified test failure output #473

Open dabrahams opened 10 months ago

dabrahams commented 10 months ago

When this test fails:

      XCTAssertEqual(g.rules.count, 1)

The output is

XCTAssertEqual failed: ("3") is not equal to ("1")

The quotes around the values are both needless and misleading; they give the impression that I was testing for string equality.

grynspan commented 10 months ago

I think we'd still want the quotes for anything conforming to StringProtocol, but I agree they (and probably the parentheses too?) aren't immediately meaningful for other data types.

abrarShariar commented 8 months ago

The parenthesis might be helpful to separate out the value we are asserting vs. the logging text.

However, the quotes could be misleading because it wraps everything with quotes regardless to type..

Maybe we can include the data type in the assertion message too? So, the final output would look sth like this:

XCTAssertEqual failed: Int(3) is not equal to Int(1)
XCTAssertEqual failed: String("Hello World") is not equal to String("hello")

what does everyone think? @grynspan @dabrahams

I've taken my PR to draft while we discuss it

grynspan commented 8 months ago

I don't morally object, though I know a lot of code that integrates with XCTest is sensitive to formatting changes. @briancroom what do you think?