Skip to content

Commit e7b6c90

Browse files
committed
feat: expose Diff() function
1 parent fe12b41 commit e7b6c90

File tree

9 files changed

+28
-7
lines changed

9 files changed

+28
-7
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ linters:
5252
- structcheck
5353
- deadcode
5454
- nosnakecase
55+
- mnd
56+
- perfsprint
5557

5658
linters-settings:
5759
govet:

assert.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func Equal[T any](t testing.TB, expected, actual T, msgArgsAndCompareOptions ...
8787
}
8888
t.Helper()
8989
msg := formatMsgAndArgs("Expected values to be equal:", msgArgsAndCompareOptions...)
90-
t.Fatalf("%s\n%s", msg, diff(expected, actual, compareOptions...))
90+
t.Fatalf("%s\n%s", msg, Diff(expected, actual, compareOptions...))
9191
}
9292

9393
// NotEqual asserts that "expected" is not equal to "actual".
@@ -165,7 +165,7 @@ func EqualError(t testing.TB, err error, errString string, msgAndArgs ...any) {
165165
}
166166
if err.Error() != errString {
167167
msg := formatMsgAndArgs("Error message not as expected:", msgAndArgs...)
168-
t.Fatalf("%s\n%s", msg, diff(errString, err.Error()))
168+
t.Fatalf("%s\n%s", msg, Diff(errString, err.Error()))
169169
}
170170
}
171171

@@ -248,7 +248,8 @@ func NotPanics(t testing.TB, fn func(), msgAndArgs ...any) {
248248
fn()
249249
}
250250

251-
func diff[T any](before, after T, compareOptions ...CompareOption) string {
251+
// Diff returns a unified diff of the string representation of two values.
252+
func Diff[T any](before, after T, compareOptions ...CompareOption) string {
252253
var lhss, rhss string
253254
// Special case strings so we get nice diffs.
254255
if l, ok := any(before).(string); ok {

assert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestNotIsError(t *testing.T) {
173173
}
174174

175175
func TestDiff(t *testing.T) {
176-
Equal(t, "-before\n+after\n", diff("before", "after"))
176+
Equal(t, "-before\n+after\n", Diff("before", "after"))
177177
}
178178

179179
func TestHasSuffix(t *testing.T) {
File renamed without changes.

bin/go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.go-1.20.5.pkg
1+
.go-1.22.3.pkg

bin/gofmt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.go-1.20.5.pkg
1+
.go-1.22.3.pkg

bin/golangci-lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.golangci-lint-1.53.2.pkg
1+
.golangci-lint-1.58.2.pkg

renovate.json5

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
$schema: "https://docs.renovatebot.com/renovate-schema.json",
3+
extends: [
4+
"config:recommended",
5+
":semanticCommits",
6+
":semanticCommitTypeAll(chore)",
7+
":semanticCommitScope(deps)",
8+
"group:allNonMajor",
9+
"schedule:earlyMondays", // Run once a week.
10+
],
11+
packageRules: [
12+
{
13+
matchPackageNames: ["golangci-lint"],
14+
matchManagers: ["hermit"],
15+
enabled: false,
16+
},
17+
],
18+
}

0 commit comments

Comments
 (0)