Skip to content

Commit 88c03c7

Browse files
committed
Merge pull request rust-lang#44 from PythonNut/master
Check for the presence of tests in more PRs
2 parents 9a9067c + 6054d88 commit 88c03c7

File tree

2 files changed

+74
-10
lines changed

2 files changed

+74
-10
lines changed

handlers/missing_test/__init__.py

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
from eventhandler import EventHandler
22

3-
reftest_required_msg = 'These commits modify layout code, but no reftests are modified. Please consider adding a reftest!'
3+
TEST_REQUIRED_MSG = 'These commits modify {0} code, but no tests are modified. Please consider adding a test!'
44

55
class MissingTestHandler(EventHandler):
6+
COMPONENT_DIRS_TO_CHECK = ('layout', 'script', 'gfx', 'style', 'net')
7+
TEST_DIRS_TO_CHECK = ('ref', 'wpt', 'unit')
8+
69
def on_pr_opened(self, api, payload):
710
diff = api.get_diff()
8-
layout_changed = False
11+
components_changed = set()
12+
913
for line in diff.split('\n'):
10-
if line.startswith('diff --git') and line.find('components/layout/') > -1:
11-
layout_changed = True
12-
if line.startswith('diff --git') and \
13-
(line.find('tests/ref') > -1 or line.find('tests/wpt') > -1):
14-
return
15-
16-
if layout_changed:
17-
self.warn(reftest_required_msg)
14+
if line.startswith('diff --git'):
15+
for component in self.COMPONENT_DIRS_TO_CHECK:
16+
if 'components/{0}/'.format(component) in line:
17+
components_changed.add(component)
18+
19+
for directory in self.TEST_DIRS_TO_CHECK:
20+
if 'tests/{0}'.format(directory) in line:
21+
return
22+
23+
if components_changed:
24+
# Build a readable list of changed components
25+
if len(components_changed) == 1:
26+
components_msg = components_changed.pop()
27+
elif len(components_changed) == 2:
28+
components_msg = '{} and {}'.format(*components_changed)
29+
else:
30+
components_msg = ', '.join(components_changed)
31+
components_msg = ", and ".join(components_msg.rsplit(", ", 1))
32+
33+
self.warn(TEST_REQUIRED_MSG.format(components_msg))
1834

1935

2036
handler_interface = MissingTestHandler

handlers/missing_test/tests/new_pr.json

+48
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,60 @@
22
"initial": [{
33
"diff": "diff --git components/layout/"
44
},
5+
{
6+
"diff": "diff --git components/script/"
7+
},
8+
{
9+
"diff": "diff --git components/gfx/"
10+
},
11+
{
12+
"diff": "diff --git components/style/"
13+
},
14+
{
15+
"diff": "diff --git components/net/"
16+
},
517
{
618
"diff": "diff --git components/layout/\ndiff --git tests/wpt"
19+
},
20+
{
21+
"diff": "diff --git components/gfx/\ndiff --git tests/unit"
22+
},
23+
{
24+
"diff": "diff --git components/style/\ndiff --git tests/unit"
25+
},
26+
{
27+
"diff": "diff --git components/net/\ndiff --git tests/unit"
28+
},
29+
{
30+
"diff": "diff --git components/script/\ndiff --git tests/unit"
731
}],
832
"expected": [{
933
"comments": 1
1034
},
35+
{
36+
"comments": 1
37+
},
38+
{
39+
"comments": 1
40+
},
41+
{
42+
"comments": 1
43+
},
44+
{
45+
"comments": 1
46+
},
47+
{
48+
"comments": 0
49+
},
50+
{
51+
"comments": 0
52+
},
53+
{
54+
"comments": 0
55+
},
56+
{
57+
"comments": 0
58+
},
1159
{
1260
"comments": 0
1361
}],

0 commit comments

Comments
 (0)