-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: error-strings custom funcs overwrites defaults (#1249)
- Loading branch information
1 parent
9177f50
commit 67d0a61
Showing
4 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package rule_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/mgechev/revive/lint" | ||
"github.com/mgechev/revive/rule" | ||
) | ||
|
||
func TestErrorStringsRule_Configure(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arguments lint.Arguments | ||
wantErr error | ||
}{ | ||
{ | ||
name: "Default configuration", | ||
arguments: lint.Arguments{}, | ||
}, | ||
{ | ||
name: "Valid custom functions", | ||
arguments: lint.Arguments{"mypkg.MyErrorFunc", "errors.New"}, | ||
}, | ||
{ | ||
name: "Argument not a string", | ||
arguments: lint.Arguments{123}, | ||
}, | ||
{ | ||
name: "Invalid package", | ||
arguments: lint.Arguments{".MyErrorFunc"}, | ||
wantErr: errors.New("found invalid custom function: .MyErrorFunc"), | ||
}, | ||
{ | ||
name: "Invalid function", | ||
arguments: lint.Arguments{"errors."}, | ||
wantErr: errors.New("found invalid custom function: errors."), | ||
}, | ||
{ | ||
name: "Invalid custom function", | ||
arguments: lint.Arguments{"invalidFunction"}, | ||
wantErr: errors.New("found invalid custom function: invalidFunction"), | ||
}, | ||
{ | ||
name: "Mixed valid and invalid custom functions", | ||
arguments: lint.Arguments{"mypkg.MyErrorFunc", "invalidFunction", "invalidFunction2"}, | ||
wantErr: errors.New("found invalid custom function: invalidFunction,invalidFunction2"), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var r rule.ErrorStringsRule | ||
|
||
err := r.Configure(tt.arguments) | ||
|
||
if tt.wantErr == nil { | ||
if err != nil { | ||
t.Errorf("Configure() unexpected non-nil error %q", err) | ||
} | ||
return | ||
} | ||
if err == nil || err.Error() != tt.wantErr.Error() { | ||
t.Errorf("Configure() unexpected error: got %q, want %q", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package fixtures | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func issue1243() { | ||
err := errors.New("An error occurred!") // MATCH /error strings should not be capitalized or end with punctuation or a newline/ | ||
fmt.Println(err) | ||
} |