Skip to content

Commit 297012c

Browse files
test: update test cases without testify suite
* removes all dependencies for test cases * update go.mod and go.sum
1 parent aa80a2e commit 297012c

4 files changed

Lines changed: 68 additions & 93 deletions

File tree

go.mod

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
module github.com/conventionalcommit/parser
22

33
go 1.17
4-
5-
require github.com/stretchr/testify v1.7.0
6-
7-
require (
8-
github.com/davecgh/go-spew v1.1.0 // indirect
9-
github.com/pmezard/go-difflib v1.0.0 // indirect
10-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
11-
)

go.sum

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
6-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
7-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
9-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
11-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

parser_header_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"strconv"
55
"strings"
66
"testing"
7-
8-
"github.com/stretchr/testify/assert"
97
)
108

119
func TestParseHeaderValid(t *testing.T) {
@@ -28,7 +26,10 @@ func TestParseHeaderValid(t *testing.T) {
2826
headerLine := strings.Split(validCase, "\n")[0]
2927
commit := &Commit{}
3028
err := parseHeader(headerLine, commit)
31-
assert.NoError(innerT, err, headerLine)
29+
if err != nil {
30+
innerT.Error("parseHeader failed for", headerLine, err)
31+
return
32+
}
3233
})
3334
}
3435
}
@@ -53,7 +54,9 @@ func TestParseHeaderInvalid(t *testing.T) {
5354
headerLine := strings.Split(validCase, "\n")[0]
5455
commit := &Commit{}
5556
err := parseHeader(headerLine, commit)
56-
assert.Error(innerT, err, headerLine)
57+
if err == nil {
58+
innerT.Error("parseHeader passed without error for", headerLine)
59+
}
5760
})
5861
}
5962
}

parser_test.go

Lines changed: 61 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/conventionalcommit/parser"
10-
"github.com/stretchr/testify/suite"
1110
)
1211

1312
const (
@@ -61,48 +60,39 @@ message is here
6160
},
6261
}
6362

64-
func TestParser(t *testing.T) {
65-
ps := &parserSuite{}
66-
suite.Run(t, ps)
67-
}
68-
69-
type parserSuite struct {
70-
suite.Suite
71-
}
72-
73-
func (s *parserSuite) TestDescription() {
63+
func TestParserDescription(t *testing.T) {
7464
expectedCommit := &parser.Commit{
7565
Header: parser.Header{
7666
Type: commitType,
7767
Description: commitDescription,
7868
},
7969
}
80-
s.parseMsgAndCompare("description", expectedCommit)
70+
parseMsgAndCompare(t, "description", expectedCommit)
8171
}
8272

83-
func (s *parserSuite) TestDescriptionScope() {
73+
func TestParserDescriptionScope(t *testing.T) {
8474
expectedCommit := &parser.Commit{
8575
Header: parser.Header{
8676
Type: commitType,
8777
Scope: commitScope,
8878
Description: commitDescription,
8979
},
9080
}
91-
s.parseMsgAndCompare("description_scope", expectedCommit)
81+
parseMsgAndCompare(t, "description_scope", expectedCommit)
9282
}
9383

94-
func (s *parserSuite) TestBreakingChangeDescription() {
84+
func TestParserBreakingChangeDescription(t *testing.T) {
9585
expectedCommit := &parser.Commit{
9686
Header: parser.Header{
9787
Type: commitType,
9888
Description: commitDescription,
9989
},
10090
BreakingChange: true,
10191
}
102-
s.parseMsgAndCompare("breaking_change_description", expectedCommit)
92+
parseMsgAndCompare(t, "breaking_change_description", expectedCommit)
10393
}
10494

105-
func (s *parserSuite) TestBreakingChangeDescriptionScope() {
95+
func TestParserBreakingChangeDescriptionScope(t *testing.T) {
10696
expectedCommit := &parser.Commit{
10797
Header: parser.Header{
10898
Type: commitType,
@@ -111,21 +101,21 @@ func (s *parserSuite) TestBreakingChangeDescriptionScope() {
111101
},
112102
BreakingChange: true,
113103
}
114-
s.parseMsgAndCompare("breaking_change_description_scope", expectedCommit)
104+
parseMsgAndCompare(t, "breaking_change_description_scope", expectedCommit)
115105
}
116106

117-
func (s *parserSuite) TestDescriptionBody() {
107+
func TestParserDescriptionBody(t *testing.T) {
118108
expectedCommit := &parser.Commit{
119109
Header: parser.Header{
120110
Type: commitType,
121111
Description: commitDescription,
122112
},
123113
Body: commitBody,
124114
}
125-
s.parseMsgAndCompare("description_body", expectedCommit)
115+
parseMsgAndCompare(t, "description_body", expectedCommit)
126116
}
127117

128-
func (s *parserSuite) TestDescriptionScopeBody() {
118+
func TestParserDescriptionScopeBody(t *testing.T) {
129119
expectedCommit := &parser.Commit{
130120
Header: parser.Header{
131121
Type: commitType,
@@ -134,10 +124,10 @@ func (s *parserSuite) TestDescriptionScopeBody() {
134124
},
135125
Body: commitBody,
136126
}
137-
s.parseMsgAndCompare("description_scope_body", expectedCommit)
127+
parseMsgAndCompare(t, "description_scope_body", expectedCommit)
138128
}
139129

140-
func (s *parserSuite) TestBreakingChangeDescriptionBody() {
130+
func TestParserBreakingChangeDescriptionBody(t *testing.T) {
141131
expectedCommit := &parser.Commit{
142132
Header: parser.Header{
143133
Type: commitType,
@@ -146,10 +136,10 @@ func (s *parserSuite) TestBreakingChangeDescriptionBody() {
146136
Body: commitBody,
147137
BreakingChange: true,
148138
}
149-
s.parseMsgAndCompare("breaking_change_description_body", expectedCommit)
139+
parseMsgAndCompare(t, "breaking_change_description_body", expectedCommit)
150140
}
151141

152-
func (s *parserSuite) TestBreakingChangeDescriptionScopeBody() {
142+
func TestParserBreakingChangeDescriptionScopeBody(t *testing.T) {
153143
expectedCommit := &parser.Commit{
154144
Header: parser.Header{
155145
Type: commitType,
@@ -159,21 +149,21 @@ func (s *parserSuite) TestBreakingChangeDescriptionScopeBody() {
159149
Body: commitBody,
160150
BreakingChange: true,
161151
}
162-
s.parseMsgAndCompare("breaking_change_description_scope_body", expectedCommit)
152+
parseMsgAndCompare(t, "breaking_change_description_scope_body", expectedCommit)
163153
}
164154

165-
func (s *parserSuite) TestDescriptionFooters() {
155+
func TestParserDescriptionFooters(t *testing.T) {
166156
expectedCommit := &parser.Commit{
167157
Header: parser.Header{
168158
Type: commitType,
169159
Description: commitDescription,
170160
},
171161
Footer: commitFooters,
172162
}
173-
s.parseMsgAndCompare("description_footers", expectedCommit)
163+
parseMsgAndCompare(t, "description_footers", expectedCommit)
174164
}
175165

176-
func (s *parserSuite) TestDescriptionScopeFooters() {
166+
func TestParserDescriptionScopeFooters(t *testing.T) {
177167
expectedCommit := &parser.Commit{
178168
Header: parser.Header{
179169
Type: commitType,
@@ -182,10 +172,10 @@ func (s *parserSuite) TestDescriptionScopeFooters() {
182172
},
183173
Footer: commitFooters,
184174
}
185-
s.parseMsgAndCompare("description_scope_footers", expectedCommit)
175+
parseMsgAndCompare(t, "description_scope_footers", expectedCommit)
186176
}
187177

188-
func (s *parserSuite) TestDescriptionBodyFooters() {
178+
func TestParserDescriptionBodyFooters(t *testing.T) {
189179
expectedCommit := &parser.Commit{
190180
Header: parser.Header{
191181
Type: commitType,
@@ -194,10 +184,10 @@ func (s *parserSuite) TestDescriptionBodyFooters() {
194184
Body: commitBody,
195185
Footer: commitFooters,
196186
}
197-
s.parseMsgAndCompare("description_body_footers", expectedCommit)
187+
parseMsgAndCompare(t, "description_body_footers", expectedCommit)
198188
}
199189

200-
func (s *parserSuite) TestDescriptionScopeBodyFooters() {
190+
func TestParserDescriptionScopeBodyFooters(t *testing.T) {
201191
expectedCommit := &parser.Commit{
202192
Header: parser.Header{
203193
Type: commitType,
@@ -207,10 +197,10 @@ func (s *parserSuite) TestDescriptionScopeBodyFooters() {
207197
Body: commitBody,
208198
Footer: commitFooters,
209199
}
210-
s.parseMsgAndCompare("description_scope_body_footers", expectedCommit)
200+
parseMsgAndCompare(t, "description_scope_body_footers", expectedCommit)
211201
}
212202

213-
func (s *parserSuite) TestDescriptionFootersBreakingChange() {
203+
func TestParserDescriptionFootersBreakingChange(t *testing.T) {
214204
expectedCommit := &parser.Commit{
215205
Header: parser.Header{
216206
Type: commitType,
@@ -219,10 +209,10 @@ func (s *parserSuite) TestDescriptionFootersBreakingChange() {
219209
Footer: breakingChangeFooter,
220210
BreakingChange: true,
221211
}
222-
s.parseMsgAndCompare("description_footers_breaking_change", expectedCommit)
212+
parseMsgAndCompare(t, "description_footers_breaking_change", expectedCommit)
223213
}
224214

225-
func (s *parserSuite) TestBreakingChangeDescriptionFooters() {
215+
func TestParserBreakingChangeDescriptionFooters(t *testing.T) {
226216
expectedCommit := &parser.Commit{
227217
BreakingChange: true,
228218
Header: parser.Header{
@@ -231,10 +221,10 @@ func (s *parserSuite) TestBreakingChangeDescriptionFooters() {
231221
},
232222
Footer: commitFooters,
233223
}
234-
s.parseMsgAndCompare("breaking_change_description_footers", expectedCommit)
224+
parseMsgAndCompare(t, "breaking_change_description_footers", expectedCommit)
235225
}
236226

237-
func (s *parserSuite) TestBreakingChangeDescriptionBodyFooters() {
227+
func TestParserBreakingChangeDescriptionBodyFooters(t *testing.T) {
238228
expectedCommit := &parser.Commit{
239229
BreakingChange: true,
240230
Header: parser.Header{
@@ -244,10 +234,10 @@ func (s *parserSuite) TestBreakingChangeDescriptionBodyFooters() {
244234
Body: commitBody,
245235
Footer: commitFooters,
246236
}
247-
s.parseMsgAndCompare("breaking_change_description_body_footers", expectedCommit)
237+
parseMsgAndCompare(t, "breaking_change_description_body_footers", expectedCommit)
248238
}
249239

250-
func (s *parserSuite) TestBreakingChangeDescriptionScopeFooters() {
240+
func TestParserBreakingChangeDescriptionScopeFooters(t *testing.T) {
251241
expectedCommit := &parser.Commit{
252242
Header: parser.Header{
253243
Type: commitType,
@@ -257,10 +247,10 @@ func (s *parserSuite) TestBreakingChangeDescriptionScopeFooters() {
257247
Footer: commitFooters,
258248
BreakingChange: true,
259249
}
260-
s.parseMsgAndCompare("breaking_change_description_scope_footers", expectedCommit)
250+
parseMsgAndCompare(t, "breaking_change_description_scope_footers", expectedCommit)
261251
}
262252

263-
func (s *parserSuite) TestBreakingChangeDescriptionScopeBodyFooters() {
253+
func TestParserBreakingChangeDescriptionScopeBodyFooters(t *testing.T) {
264254
expectedCommit := &parser.Commit{
265255
Header: parser.Header{
266256
Type: commitType,
@@ -271,27 +261,29 @@ func (s *parserSuite) TestBreakingChangeDescriptionScopeBodyFooters() {
271261
Footer: commitFooters,
272262
BreakingChange: true,
273263
}
274-
s.parseMsgAndCompare("breaking_change_description_scope_body_footers", expectedCommit)
264+
parseMsgAndCompare(t, "breaking_change_description_scope_body_footers", expectedCommit)
275265
}
276266

277-
func (s *parserSuite) TestFooterMultiLine() {
267+
func TestParserFooterMultiLine(t *testing.T) {
278268
expectedCommit := &parser.Commit{
279269
Header: parser.Header{
280270
Type: commitType,
281271
Description: commitDescription,
282272
},
283273
Footer: multiLineFooters,
284274
}
285-
s.parseMsgAndCompare("footer_multi_line", expectedCommit)
275+
parseMsgAndCompare(t, "footer_multi_line", expectedCommit)
286276
}
287277

288-
func (s *parserSuite) TestErrNoBlankLine() {
289-
t := s.T()
290-
278+
func TestParserErrNoBlankLine(t *testing.T) {
291279
fileName := "err_no_blank_line"
292280

293-
commitMsg := s.loadCommitMsgFromFile(filepath.Join(testDataDir, fileName))
294-
_, err := parser.Parse(commitMsg)
281+
commitMsg, err := loadCommitMsgFromFile(filepath.Join(testDataDir, fileName))
282+
if err != nil {
283+
t.Error(err)
284+
}
285+
286+
_, err = parser.Parse(commitMsg)
295287
if err == nil {
296288
t.Errorf("no error: test file %v passed", fileName)
297289
return
@@ -302,13 +294,15 @@ func (s *parserSuite) TestErrNoBlankLine() {
302294
}
303295
}
304296

305-
func (s *parserSuite) TestErrHeaderLine() {
306-
t := s.T()
307-
297+
func TestParserErrHeaderLine(t *testing.T) {
308298
fileName := "err_header_line"
309299

310-
commitMsg := s.loadCommitMsgFromFile(filepath.Join(testDataDir, fileName))
311-
_, err := parser.Parse(commitMsg)
300+
commitMsg, err := loadCommitMsgFromFile(filepath.Join(testDataDir, fileName))
301+
if err != nil {
302+
t.Error(err)
303+
}
304+
305+
_, err = parser.Parse(commitMsg)
312306
if err == nil {
313307
t.Errorf("no error: test file %v passed", fileName)
314308
return
@@ -319,39 +313,36 @@ func (s *parserSuite) TestErrHeaderLine() {
319313
}
320314
}
321315

322-
func (s *parserSuite) parseMsgAndCompare(fileName string, expectedCommit *parser.Commit) {
323-
t := s.T()
324-
t.Helper()
316+
func parseMsgAndCompare(t *testing.T, fileName string, expectedCommit *parser.Commit) {
317+
commitMsg, err := loadCommitMsgFromFile(filepath.Join(testDataDir, fileName))
318+
if err != nil {
319+
t.Errorf("Received unexpected error:\n%+v", err)
320+
return
321+
}
325322

326-
commitMsg := s.loadCommitMsgFromFile(filepath.Join(testDataDir, fileName))
327323
actualCommit, err := parser.Parse(commitMsg)
328324
if err != nil {
329325
t.Errorf("Received unexpected error:\n%+v", err)
330326
return
331327
}
332328

333-
if !s.compareCommit(actualCommit, expectedCommit) {
329+
if !compareCommit(t, actualCommit, expectedCommit) {
334330
t.Errorf("Commit not equal :\n\tExpected: %v,\n\tActual: %v", expectedCommit, actualCommit)
335331
return
336332
}
337333
}
338334

339335
// loadCommitMsgFromFile loads a file and returns the entire contents as a string. Any
340336
// leading or trailing whitespace is removed
341-
func (s *parserSuite) loadCommitMsgFromFile(fileName string) string {
342-
t := s.T()
343-
t.Helper()
344-
337+
func loadCommitMsgFromFile(fileName string) (string, error) {
345338
out, err := os.ReadFile(fileName)
346339
if err != nil {
347-
t.Errorf("error in test setup; unable to load file %s", fileName)
340+
return "", err
348341
}
349-
return strings.TrimSpace(string(out))
342+
return strings.TrimSpace(string(out)), nil
350343
}
351344

352-
func (s *parserSuite) compareCommit(a, b *parser.Commit) bool {
353-
t := s.T()
354-
345+
func compareCommit(t *testing.T, a, b *parser.Commit) bool {
355346
if a.Header.Type != b.Header.Type {
356347
t.Log("Header Type Not Equal")
357348
return false

0 commit comments

Comments
 (0)