MCPcopy Create free account
hub / github.com/conventionalcommit/commitlint / TestCustomParserIntegration

Function TestCustomParserIntegration

test/syntax_parser_test.go:120–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func 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}

Callers

nothing calls this directly

Calls 8

NewDefaultFunction · 0.92
GetEnabledRulesFunction · 0.92
NewWithParserFunction · 0.92
NewLinterWithParserFunction · 0.92
ParseAndLintMethod · 0.80
IssuesMethod · 0.80
RuleNameMethod · 0.80
InfosMethod · 0.80

Tested by

no test coverage detected