(t *testing.T)
| 118 | } |
| 119 | |
| 120 | func TestCustomParserIntegration(t *testing.T) { |
| 121 | conf := config.NewDefault() |
| 122 | conf.Rules = append(conf.Rules, "body-leading-blank", "breaking-change-exclamation-mark", "signed-off-by") |
| 123 | rules, err := config.GetEnabledRules(conf) |
| 124 | if err != nil { |
| 125 | t.Fatal(err) |
| 126 | } |
| 127 | |
| 128 | if _, err := lint.NewWithParser(conf, rules, nil); err == nil { |
| 129 | t.Fatal("expected error for nil parser in lint.NewWithParser") |
| 130 | } |
| 131 | if _, err := config.NewLinterWithParser(conf, nil); err == nil { |
| 132 | t.Fatal("expected error for nil parser in config.NewLinterWithParser") |
| 133 | } |
| 134 | |
| 135 | linter, err := config.NewLinterWithParser(conf, &customParser{}) |
| 136 | if err != nil { |
| 137 | t.Fatal(err) |
| 138 | } |
| 139 | |
| 140 | res, err := linter.ParseAndLint("bad") |
| 141 | if err != nil { |
| 142 | t.Fatal(err) |
| 143 | } |
| 144 | if len(res.Issues()) != 1 || res.Issues()[0].RuleName() != "parser" || len(res.Issues()[0].Infos()) != 0 { |
| 145 | t.Fatalf("unexpected custom error result: %v", res.Issues()) |
| 146 | } |
| 147 | |
| 148 | res, err = linter.ParseAndLint("warn: partial commit") |
| 149 | if err != nil { |
| 150 | t.Fatal(err) |
| 151 | } |
| 152 | if len(res.Issues()) < 2 || res.Issues()[0].RuleName() != "parser" { |
| 153 | t.Fatalf("expected parser error plus rule issues for partial commit, got: %v", res.Issues()) |
| 154 | } |
| 155 | |
| 156 | res, err = linter.ParseAndLint("feat: valid via custom parser\n\nBody line.") |
| 157 | if err != nil { |
| 158 | t.Fatal(err) |
| 159 | } |
| 160 | if len(res.Issues()) != 1 || res.Issues()[0].RuleName() != "signed-off-by" { |
| 161 | t.Fatalf("expected signed-off-by issue only, got: %v", res.Issues()) |
| 162 | } |
| 163 | } |
nothing calls this directly
no test coverage detected