From e7b6c90a6cea1ee9ba57befdfea77e499191f0e8 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Mon, 27 May 2024 11:10:26 +1000 Subject: [PATCH] feat: expose Diff() function --- .golangci.yml | 2 ++ assert.go | 7 ++++--- assert_test.go | 2 +- bin/{.go-1.20.5.pkg => .go-1.22.3.pkg} | 0 ...nt-1.53.2.pkg => .golangci-lint-1.58.2.pkg} | 0 bin/go | 2 +- bin/gofmt | 2 +- bin/golangci-lint | 2 +- renovate.json5 | 18 ++++++++++++++++++ 9 files changed, 28 insertions(+), 7 deletions(-) rename bin/{.go-1.20.5.pkg => .go-1.22.3.pkg} (100%) rename bin/{.golangci-lint-1.53.2.pkg => .golangci-lint-1.58.2.pkg} (100%) create mode 100644 renovate.json5 diff --git a/.golangci.yml b/.golangci.yml index 0d8cd48..de26bb0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -52,6 +52,8 @@ linters: - structcheck - deadcode - nosnakecase + - mnd + - perfsprint linters-settings: govet: diff --git a/assert.go b/assert.go index 9dce84e..864cdf6 100644 --- a/assert.go +++ b/assert.go @@ -87,7 +87,7 @@ func Equal[T any](t testing.TB, expected, actual T, msgArgsAndCompareOptions ... } t.Helper() msg := formatMsgAndArgs("Expected values to be equal:", msgArgsAndCompareOptions...) - t.Fatalf("%s\n%s", msg, diff(expected, actual, compareOptions...)) + t.Fatalf("%s\n%s", msg, Diff(expected, actual, compareOptions...)) } // NotEqual asserts that "expected" is not equal to "actual". @@ -165,7 +165,7 @@ func EqualError(t testing.TB, err error, errString string, msgAndArgs ...any) { } if err.Error() != errString { msg := formatMsgAndArgs("Error message not as expected:", msgAndArgs...) - t.Fatalf("%s\n%s", msg, diff(errString, err.Error())) + t.Fatalf("%s\n%s", msg, Diff(errString, err.Error())) } } @@ -248,7 +248,8 @@ func NotPanics(t testing.TB, fn func(), msgAndArgs ...any) { fn() } -func diff[T any](before, after T, compareOptions ...CompareOption) string { +// Diff returns a unified diff of the string representation of two values. +func Diff[T any](before, after T, compareOptions ...CompareOption) string { var lhss, rhss string // Special case strings so we get nice diffs. if l, ok := any(before).(string); ok { diff --git a/assert_test.go b/assert_test.go index cc49c8e..6b8e023 100644 --- a/assert_test.go +++ b/assert_test.go @@ -173,7 +173,7 @@ func TestNotIsError(t *testing.T) { } func TestDiff(t *testing.T) { - Equal(t, "-before\n+after\n", diff("before", "after")) + Equal(t, "-before\n+after\n", Diff("before", "after")) } func TestHasSuffix(t *testing.T) { diff --git a/bin/.go-1.20.5.pkg b/bin/.go-1.22.3.pkg similarity index 100% rename from bin/.go-1.20.5.pkg rename to bin/.go-1.22.3.pkg diff --git a/bin/.golangci-lint-1.53.2.pkg b/bin/.golangci-lint-1.58.2.pkg similarity index 100% rename from bin/.golangci-lint-1.53.2.pkg rename to bin/.golangci-lint-1.58.2.pkg diff --git a/bin/go b/bin/go index be7dd9d..764d174 120000 --- a/bin/go +++ b/bin/go @@ -1 +1 @@ -.go-1.20.5.pkg \ No newline at end of file +.go-1.22.3.pkg \ No newline at end of file diff --git a/bin/gofmt b/bin/gofmt index be7dd9d..764d174 120000 --- a/bin/gofmt +++ b/bin/gofmt @@ -1 +1 @@ -.go-1.20.5.pkg \ No newline at end of file +.go-1.22.3.pkg \ No newline at end of file diff --git a/bin/golangci-lint b/bin/golangci-lint index 54cd8fa..0af4397 120000 --- a/bin/golangci-lint +++ b/bin/golangci-lint @@ -1 +1 @@ -.golangci-lint-1.53.2.pkg \ No newline at end of file +.golangci-lint-1.58.2.pkg \ No newline at end of file diff --git a/renovate.json5 b/renovate.json5 new file mode 100644 index 0000000..77c7b01 --- /dev/null +++ b/renovate.json5 @@ -0,0 +1,18 @@ +{ + $schema: "https://docs.renovatebot.com/renovate-schema.json", + extends: [ + "config:recommended", + ":semanticCommits", + ":semanticCommitTypeAll(chore)", + ":semanticCommitScope(deps)", + "group:allNonMajor", + "schedule:earlyMondays", // Run once a week. + ], + packageRules: [ + { + matchPackageNames: ["golangci-lint"], + matchManagers: ["hermit"], + enabled: false, + }, + ], +}