Skip to content

Commit

Permalink
require-error: skip calls in else-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonboom committed Feb 9, 2024
1 parent 049b11c commit fa49328
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,38 @@ func TestService_DeclareFixedRoles(t *testing.T) {
}
}

func TestIssue62(t *testing.T) {
cases := []struct {
name string
expectedError error
failureDetails any
}{
{},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
failureDetails, err := operationWithResult()

if tc.expectedError != nil {
assert.Error(t, err)
} else {
require.NoError(t, err)
if tc.failureDetails != nil {
assert.Error(t, err) // want "require-error: for error assertions use require"
assert.Equal(t, failureDetails, tc.failureDetails)
} else if false {
assert.Error(t, err)
} else if true {
assert.Error(t, err)
} else {
assert.Equal(t, failureDetails, tc.failureDetails)
}
}
})
}
}

func createTempPackageJson(t *testing.T, version string) error {
t.Helper()

Expand Down
15 changes: 14 additions & 1 deletion internal/checkers/require_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,20 @@ func needToSkipBasedOnContext(
_, blockEndWithReturn := block.List[len(block.List)-1].(*ast.ReturnStmt)
if !blockEndWithReturn {
for i := currCallIndex + 1; i < len(otherCalls); i++ {
if (otherCalls[i].rootIf == nil) || (otherCalls[i].rootIf != currCall.rootIf) {
nextCall := otherCalls[i]
nextCallInElseBlock := false

if pIf := currCall.parentIf; pIf != nil && pIf.Else != nil {
ast.Inspect(pIf.Else, func(n ast.Node) bool {
if n == nextCall.call {
nextCallInElseBlock = true
return false
}
return true
})
}

if !nextCallInElseBlock {
noCallsAfter = false
break
}
Expand Down

0 comments on commit fa49328

Please sign in to comment.