Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/assertions/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func SliceNotSubsetT[Slice ~[]E, E comparable](t T, list, subset Slice, msgAndAr
}
}

return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%q", subset), truncatingFormat("%q", list)), msgAndArgs...)
return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%#v", subset), truncatingFormat("%#v", list)), msgAndArgs...)
}

// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
Expand Down Expand Up @@ -805,7 +805,7 @@ func isNotSubsetMap(t T, list, subset any, subsetMap, actualMap reflect.Value, m
}
}

return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%q", subset), truncatingFormat("%q", list)), msgAndArgs...)
return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%#v", subset), truncatingFormat("%#v", list)), msgAndArgs...)
}

func isSubsetList(t T, list any, subsetList reflect.Value, msgAndArgs ...any) bool {
Expand All @@ -829,7 +829,7 @@ func isNotSubsetList(t T, list, subset any, subsetList reflect.Value, msgAndArgs
}
}

return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%q", subset), truncatingFormat("%q", list)), msgAndArgs...)
return Fail(t, fmt.Sprintf("%s is a subset of %s", truncatingFormat("%#v", subset), truncatingFormat("%#v", list)), msgAndArgs...)
}

// containsElement tries to loop over the list check if the list includes the element.
Expand Down
39 changes: 35 additions & 4 deletions internal/assertions/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,8 @@ func collectionErrorMessageCases() iter.Seq[failCase] {
name: "truncation/NotSubset(longSlice)",
assertion: func(t T) bool { return NotSubset(t, longSlice, longSlice) },
wantContains: []string{
`['\x00' '\x00' '\x00'`,
`<... truncated> is a subset of ['\x00' '\x00' '\x00'`,
`[]int{0, 0, 0,`,
`<... truncated> is a subset of []int{0, 0, 0,`,
},
},
{
Expand All @@ -1282,9 +1282,40 @@ func collectionErrorMessageCases() iter.Seq[failCase] {
return NotSubset(t, map[int][]int{1: longSlice}, map[int][]int{1: longSlice})
},
wantContains: []string{
`map['\x01':['\x00' '\x00' '\x00'`,
`<... truncated> is a subset of map['\x01':['\x00' '\x00' '\x00'`,
`map[int][]int{1:[]int{0, 0, 0,`,
`<... truncated> is a subset of map[int][]int{1:[]int{0, 0, 0,`,
},
},

// NotSubset/SliceNotSubsetT fail messages — regression coverage for
// upstream stretchr/testify#1800 / #1848: previously %q produced
// broken output like "%!q(bool=true)" or "'\x01'" for non-string types.
{
name: "NotSubset(bools)",
assertion: func(t T) bool { return NotSubset(t, []bool{true}, []bool{true}) },
wantContains: []string{`[]bool{true} is a subset of []bool{true}`},
},
{
name: "NotSubset(ints)",
assertion: func(t T) bool { return NotSubset(t, []int{1, 2, 3}, []int{1, 2}) },
wantContains: []string{`[]int{1, 2} is a subset of []int{1, 2, 3}`},
},
{
name: "NotSubset(map-int)",
assertion: func(t T) bool {
return NotSubset(t, map[int]string{1: "one"}, map[int]string{1: "one"})
},
wantContains: []string{`map[int]string{1:"one"} is a subset of map[int]string{1:"one"}`},
},
{
name: "SliceNotSubsetT(bools)",
assertion: func(t T) bool { return SliceNotSubsetT(t, []bool{true}, []bool{true}) },
wantContains: []string{`[]bool{true} is a subset of []bool{true}`},
},
{
name: "SliceNotSubsetT(ints)",
assertion: func(t T) bool { return SliceNotSubsetT(t, []int{1, 2, 3}, []int{1, 2}) },
wantContains: []string{`[]int{1, 2} is a subset of []int{1, 2, 3}`},
},
})
}
Loading