Add tests for new fail-on-error option
@@ -96,3 +96,76 @@ index 34cacb9..a727dd3 100644
app := NewReviewdog("tool name", p, c, d, FilterModeAdded, false)
app.Run(context.Background(), strings.NewReader(lintresult))
}
+
+func TestReviewdog_Run_returns_nil_if_fail_on_error_not_passed_and_some_errors_found(t *testing.T) {
+ difftext := `diff --git a/golint.old.go b/golint.new.go
+index 34cacb9..a727dd3 100644
+--- a/golint.old.go
++++ b/golint.new.go
+@@ -2,6 +2,12 @@ package test
+
+ var V int
+
++var NewError1 int
++
+ // invalid func comment
+ func F() {
+ }
++
++// invalid func comment2
++func F2() {
++}
+`
+ lintresult := `golint.new.go:3:5: exported var V should have comment or be unexported
+golint.new.go:5:5: exported var NewError1 should have comment or be unexported
+golint.new.go:7:1: comment on exported function F should be of the form "F ..."
+golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..."
+`
+
+ c := NewRawCommentWriter(os.Stdout)
+ efm, _ := errorformat.NewErrorformat([]string{`%f:%l:%c: %m`})
+ p := NewErrorformatParser(efm)
+ d := NewDiffString(difftext, 1)
+ app := NewReviewdog("tool name", p, c, d, FilterModeAdded, false)
+ err := app.Run(context.Background(), strings.NewReader(lintresult))
+
+ if err != nil {
+ t.Errorf("No errors expected, but got %v", err)
+ }
+}
+
+func TestReviewdog_Run_returns_error_if_fail_on_error_passed_and_some_errors_found(t *testing.T) {
+ difftext := `diff --git a/golint.old.go b/golint.new.go
+index 34cacb9..a727dd3 100644
+--- a/golint.old.go
++++ b/golint.new.go
+@@ -2,6 +2,12 @@ package test
+
+ var V int
+
++var NewError1 int
++
+ // invalid func comment
+ func F() {
+ }
++
++// invalid func comment2
++func F2() {
++}
+`
+ lintresult := `golint.new.go:3:5: exported var V should have comment or be unexported
+golint.new.go:5:5: exported var NewError1 should have comment or be unexported
+golint.new.go:7:1: comment on exported function F should be of the form "F ..."
+golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..."
+`
+ c := NewRawCommentWriter(os.Stdout)
+ efm, _ := errorformat.NewErrorformat([]string{`%f:%l:%c: %m`})
+ p := NewErrorformatParser(efm)
+ d := NewDiffString(difftext, 1)
+ app := NewReviewdog("tool name", p, c, d, FilterModeAdded, true)
+ err := app.Run(context.Background(), strings.NewReader(lintresult))
+
+ if err != nil && err.Error() != "input data has violations" {
+ t.Errorf("'input data has violations' expected, but got %v", err)
+ }
+}
