Skip to content

Commit bd0a638

Browse files
committed
StdlibUnittest: improve error messages in checkEquatable() and checkHashable()
1 parent 61fcdf5 commit bd0a638

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,14 +1951,23 @@ public func checkEquatable<Instances : Collection>(
19511951
let y = instances[j]
19521952

19531953
let xy = x == y
1954-
expectEqual(predictedXY, xy, ${trace})
1954+
expectEqual(
1955+
predictedXY, xy,
1956+
"lhs (at index \(i)): \(x)\nrhs (at index \(j)): \(y)",
1957+
stackTrace: ${stackTrace})
19551958

19561959
// Not-equal is an inverse of equal
1957-
expectNotEqual(xy, x != y, ${trace})
1958-
1960+
expectNotEqual(
1961+
xy, x != y,
1962+
"lhs (at index \(i)): \(x)\nrhs (at index \(j)): \(y)",
1963+
stackTrace: ${stackTrace})
1964+
19591965
// Symmetry
1960-
expectEqual(xy, y == x, ${trace})
1961-
1966+
expectEqual(
1967+
xy, y == x,
1968+
"lhs (at index \(i)): \(x)\nrhs (at index \(j)): \(y)",
1969+
stackTrace: ${stackTrace})
1970+
19621971
for k in instances.indices {
19631972
let z = instances[k]
19641973
// Transitivity
@@ -1998,10 +2007,15 @@ public func checkHashable<Instances : Collection>(
19982007

19992008
checkEquatable(instances, oracle: equalityOracle, ${trace})
20002009

2001-
for x in instances {
2002-
for y in instances {
2010+
for i in instances.indices {
2011+
let x = instances[i]
2012+
for j in instances.indices {
2013+
let y = instances[j]
20032014
if x == y {
2004-
expectEqual(x.hashValue, y.hashValue, ${trace})
2015+
expectEqual(
2016+
x.hashValue, y.hashValue,
2017+
"lhs (at index \(i)): \(x)\nrhs (at index \(j)): \(y)",
2018+
stackTrace: ${stackTrace})
20052019
}
20062020
}
20072021
}

0 commit comments

Comments
 (0)