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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- errcheck
- errorlint
Expand Down
8 changes: 5 additions & 3 deletions assert/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ func TestAssertWithBoolMultiLineFailure(t *testing.T) {
fakeT := &fakeTestingT{}

Assert(fakeT, func() bool {
for range []int{1, 2, 3, 4} {
for i := range []int{1, 2, 3, 4} {
_ = i
}
return false
}())
expectFailNowed(t, fakeT, `assertion failed: expression is false: func() bool {
for range []int{1, 2, 3, 4} {
for i := range []int{1, 2, 3, 4} {
_ = i
}
return false
}()`)
Expand Down Expand Up @@ -244,7 +246,7 @@ func TestCheckEqualFailure(t *testing.T) {
func TestCheck_MultipleFunctionsOnTheSameLine(t *testing.T) {
fakeT := &fakeTestingT{}

f := func(b bool) {}
f := func(bool) {}
f(Check(fakeT, false))
// TODO: update the expected when there is a more correct fix
expectFailed(t, fakeT,
Expand Down
2 changes: 1 addition & 1 deletion assert/cmp/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ type causer interface {
}

func formatErrorMessage(err error) string {
//nolint:errorlint // unwrapping is not appropriate here
//nolint:errorlint,nolintlint // unwrapping is not appropriate here
if _, ok := err.(causer); ok {
return fmt.Sprintf("%q\n%+v", err, err)
}
Expand Down
2 changes: 1 addition & 1 deletion assert/opt/opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,5 @@ func TestPathDebug(t *testing.T) {
"label1": {},
},
}
gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore()))
assert.Check(t, gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore())))
}
4 changes: 2 additions & 2 deletions fs/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func errProblem(reason string, err error) problem {
return problem(fmt.Sprintf("%s: %s", reason, err))
}

func existenceProblem(filename, reason string, args ...interface{}) problem {
return problem(filename + ": " + fmt.Sprintf(reason, args...))
func existenceProblem(filename string, msgAndArgs ...interface{}) problem {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you coule use ...any instead of ...interface{}

return problem(filename + ": " + format.Message(msgAndArgs...))
}

func eqResource(x, y resource) []problem {
Expand Down
4 changes: 2 additions & 2 deletions fs/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestMatchFileContent(t *testing.T) {
defer dir.Remove()

t.Run("content matches", func(t *testing.T) {
matcher := func(b []byte) CompareResult {
matcher := func([]byte) CompareResult {
return is.ResultSuccess
}
manifest := Expected(t,
Expand All @@ -193,7 +193,7 @@ func TestMatchFileContent(t *testing.T) {
})

t.Run("content does not match", func(t *testing.T) {
matcher := func(b []byte) CompareResult {
matcher := func([]byte) CompareResult {
return is.ResultFailure("data content differs from expected")
}
manifest := Expected(t,
Expand Down
9 changes: 3 additions & 6 deletions internal/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getNodeAtLine(fileset *token.FileSet, astFile ast.Node, lineNum int) (ast.N
return node, err
}
}
return nil, nil
return nil, errors.New("failed to find expression")
}

func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node {
Expand All @@ -92,19 +92,16 @@ func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node {

func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast.Expr, error) {
node, err := getNodeAtLine(fileset, astFile, line)
switch {
case err != nil:
if err != nil {
return nil, err
case node == nil:
return nil, fmt.Errorf("failed to find an expression")
}

debug("found node: %s", debugFormatNode{node})

visitor := &callExprVisitor{}
ast.Walk(visitor, node)
if visitor.expr == nil {
return nil, errors.New("failed to find call expression")
return nil, errors.New("failed to find an expression")
}
debug("callExpr: %s", debugFormatNode{visitor.expr})
return visitor.expr.Args, nil
Expand Down
22 changes: 11 additions & 11 deletions internal/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func shim(_, _, _ string) (string, error) {

func TestFormattedCallExprArg_InDefer(t *testing.T) {
skip.If(t, isGoVersion18)
cap := &capture{}
c := &capture{}
func() {
defer cap.shim("first", "second")
defer c.shim("first", "second")
}()

assert.NilError(t, cap.err)
assert.Equal(t, cap.value, `"second"`)
assert.NilError(t, c.err)
assert.Equal(t, c.value, `"second"`)
}

func isGoVersion18() bool {
Expand All @@ -70,25 +70,25 @@ func (c *capture) shim(_, _ string) {
}

func TestFormattedCallExprArg_InAnonymousDefer(t *testing.T) {
cap := &capture{}
c := &capture{}
func() {
fmt.Println()
defer fmt.Println()
defer func() { cap.shim("first", "second") }()
defer func() { c.shim("first", "second") }()
}()

assert.NilError(t, cap.err)
assert.Equal(t, cap.value, `"second"`)
assert.NilError(t, c.err)
assert.Equal(t, c.value, `"second"`)
}

func TestFormattedCallExprArg_InDeferMultipleDefers(t *testing.T) {
skip.If(t, isGoVersion18)
cap := &capture{}
c := &capture{}
func() {
fmt.Println()
defer fmt.Println()
defer cap.shim("first", "second")
defer c.shim("first", "second")
}()

assert.ErrorContains(t, cap.err, "ambiguous call expression")
assert.ErrorContains(t, c.err, "ambiguous call expression")
}
2 changes: 1 addition & 1 deletion poll/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func isDesiredState() bool { return false }
func getState() string { return "" }

func ExampleSettingOp() {
check := func(t poll.LogT) poll.Result {
check := func(poll.LogT) poll.Result {
if isDesiredState() {
return poll.Success()
}
Expand Down
2 changes: 1 addition & 1 deletion poll/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func Compare(compare cmp.Comparison) Result {
if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) {
return Success()
}
return Continue(buf.String())
return Continue("%v", buf.String())
}

type logBuffer struct {
Expand Down
14 changes: 7 additions & 7 deletions poll/poll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func (t *fakeT) Fatalf(format string, args ...interface{}) {
panic("exit wait on")
}

func (t *fakeT) Log(args ...interface{}) {}
func (t *fakeT) Log(...interface{}) {}

func (t *fakeT) Logf(format string, args ...interface{}) {}
func (t *fakeT) Logf(string, ...interface{}) {}
Comment on lines 20 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you coule use any instead of interface{}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept interface{} for now, so that we didn't have to raise the go version in go.mod;

go 1.17

(any would require go1.18 as minimum; https://go.dev/ref/spec#Go_1.18)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know 😬 but Go 1.18 is now not only old, but no longer supported

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, more than aware; I also know that it's not uncommon for companies to maintain an (internal) LTS version of older Go versions. Not all of those will be visible publicly on GitHub. (e.g. I know Google for a long time required compatibility with go1.13 for some of their systems - they maintained their own version for that).


func TestWaitOn(t *testing.T) {
counter := 0
end := 4
check := func(t LogT) Result {
check := func(LogT) Result {
if counter == end {
return Success()
}
Expand All @@ -40,7 +40,7 @@ func TestWaitOn(t *testing.T) {
func TestWaitOnWithTimeout(t *testing.T) {
fakeT := &fakeT{}

check := func(t LogT) Result {
check := func(LogT) Result {
return Continue("not done")
}

Expand All @@ -53,7 +53,7 @@ func TestWaitOnWithTimeout(t *testing.T) {
func TestWaitOnWithCheckTimeout(t *testing.T) {
fakeT := &fakeT{}

check := func(t LogT) Result {
check := func(LogT) Result {
time.Sleep(1 * time.Second)
return Continue("not done")
}
Expand All @@ -65,7 +65,7 @@ func TestWaitOnWithCheckTimeout(t *testing.T) {
func TestWaitOnWithCheckError(t *testing.T) {
fakeT := &fakeT{}

check := func(t LogT) Result {
check := func(LogT) Result {
return Error(fmt.Errorf("broke"))
}

Expand All @@ -76,7 +76,7 @@ func TestWaitOnWithCheckError(t *testing.T) {
func TestWaitOn_WithCompare(t *testing.T) {
fakeT := &fakeT{}

check := func(t LogT) Result {
check := func(LogT) Result {
return Compare(cmp.Equal(3, 4))
}

Expand Down
2 changes: 1 addition & 1 deletion x/subtest/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ExampleRun_tableTest() {
}
}

func startFakeService(t subtest.TestContext) string {
func startFakeService(_ subtest.TestContext) string {
return "url"
}

Expand Down