-
Notifications
You must be signed in to change notification settings - Fork 2
/
commit-msg-test
132 lines (102 loc) · 3.72 KB
/
commit-msg-test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
"""Contains tests for the commit-msg script.
To run this:
1. Give commit-msg and commit-msg-test executable permissions.
2. Run ./commit-msg-test
"""
import imp
cm = imp.load_source('commit-msg', 'commit-msg')
def test_remove_lines_starting_with_hashtag():
sample_commit_file_contents = [
'#Ignore',
'#Ignore1\n#Ignore2',
'#Ignore1\n#Ignore2\n\n#Ignore3',
'\n# Ignore\n',
'Do not ignore\nDo not ignore',
'Do not ignore\nDo not ignore\n',
'Do not #ignore\n#Ignore\nDo not ignore\n',
]
target = [
'',
'',
'\n',
'\n',
'Do not ignore\nDo not ignore',
'Do not ignore\nDo not ignore\n',
'Do not #ignore\nDo not ignore\n',
]
i = 0
for sample in sample_commit_file_contents:
assert cm.remove_lines_starting_with_hashtag(sample) == target[i]
i += 1
def test_extract_subject_and_body():
sample_commit_file_contents = [
'Add subject',
'Add subject\n\nBody paragraph 1\n\nBody paragraph 2',
'Add \nsubject\n\nBody paragraph 1\n\nBody paragraph 2\n\n\n',
'Add subject\n\nBody paragraph 1\n\n#Ignore\n#Ignore me\n\n',
'Add subject\n\nBody paragraph 1\n\n#Ignore',
'Add subject\n\nBody paragraph 1\n\n\n#Ignore\nDo not #Ignore\n\n',
]
target = [
('Add subject', None),
('Add subject', 'Body paragraph 1\n\nBody paragraph 2'),
('Add \nsubject', 'Body paragraph 1\n\nBody paragraph 2'),
('Add subject', 'Body paragraph 1'),
('Add subject', 'Body paragraph 1'),
('Add subject', 'Body paragraph 1\n\n\nDo not #Ignore'),
]
i = 0
for sample in sample_commit_file_contents:
subject, body = cm.extract_subject_and_body(sample)
assert subject == target[i][0]
assert body == target[i][1]
i += 1
def test_has_valid_subject():
valid_subjects = [
'Add subject',
'Create project',
]
invalid_subjects = [
'',
'Adds subject',
'Add subject.',
'add subject',
'Added subject',
'Adding subject',
'Add subject. There is another sentence',
'Add subject\nThere is another sentence',
'Add quote: Measuring programming progress by lines of code is like measuring aircraft building progress by weight',
]
for subject in valid_subjects:
assert cm.has_valid_subject(subject)
for subject in invalid_subjects:
assert not cm.has_valid_subject(subject)
def test_has_long_lines():
short_lines = ['Line 1', 'Measuring programming progress by lines of code is like measuring']
long_lines = ['Line 1', 'Measuring programming progress by lines of code is like measuring aircraft']
assert not cm.has_long_lines(short_lines)
assert cm.has_long_lines(long_lines)
def test_has_consecutive_blank_lines():
valid_lines = ['Line 1', '', 'Line 2', '']
invalid_lines_1 = ['Line 1', '', '', 'Line 2']
invalid_lines_2 = ['', '', 'Line 1']
assert not cm.has_consecutive_blank_lines(valid_lines)
assert cm.has_consecutive_blank_lines(invalid_lines_1)
assert cm.has_consecutive_blank_lines(invalid_lines_2)
def test_has_valid_commit_msg():
# TODO: Add test cases
valid_commit_file_contents = [
]
invalid_commit_file_contents = [
]
for file_contents in valid_commit_file_contents:
assert cm.has_valid_commit_msg(file_contents)
for file_contents in invalid_commit_file_contents:
assert not cm.has_valid_commit_msg(file_contents)
test_remove_lines_starting_with_hashtag()
test_extract_subject_and_body()
test_has_valid_subject()
test_has_long_lines()
test_has_consecutive_blank_lines()
test_has_valid_commit_msg()