Skip to content

Commit 0afa142

Browse files
committed
Added checks for tests.
PRESUBMIT will check: 1. a new test can NOT be added to Dart 1.0 the new test can only be added to DDC. 2. a existing Dart 1.0 test changed must have its corresponding DDC test updated too (if it exists). Presubmit errors may appear as: ** Presubmit ERRORS ** Error: If you change a Dart 1.0 test, you must also update the DDC test: 1. Dart 1.0 test changed: tests/corelib/symbol_map_helper.dart 1. DDC test must change: tests/corelib_2/symbol_map_helper.dart 2. Dart 1.0 test changed: tests/language/compiler_annotations.dart 2. DDC test must change: tests/language_2/compiler_annotations.dart R=jacobr@google.com, rnystrom@google.com Error: New Dart 1.0 test can not be added the test must be added as a DDC test: Fix tests: 1. New Dart 1.0 test: tests/corelib/new_test.dart 1. Should be DDC test: tests/corelib_2/new_test.dart 2. New Dart 1.0 test: tests/language/new_test.dart 2. Should be DDC test: tests/language_2/new_test.dart Review-Url: https://codereview.chromium.org/2982043002 .
1 parent b6d15d8 commit 0afa142

File tree

1 file changed

+81
-8
lines changed

1 file changed

+81
-8
lines changed

PRESUBMIT.py

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010

1111
import imp
1212
import os
13+
import os.path
1314
import scm
1415
import subprocess
1516
import tempfile
1617

1718
def _CheckBuildStatus(input_api, output_api):
18-
results = []
19-
status_check = input_api.canned_checks.CheckTreeIsOpen(
20-
input_api,
21-
output_api,
22-
json_url='http://dart-status.appspot.com/current?format=json')
23-
results.extend(status_check)
24-
return results
19+
results = []
20+
status_check = input_api.canned_checks.CheckTreeIsOpen(
21+
input_api,
22+
output_api,
23+
json_url='http://dart-status.appspot.com/current?format=json')
24+
results.extend(status_check)
25+
return results
2526

2627
def _CheckDartFormat(input_api, output_api):
2728
local_root = input_api.change.RepositoryRoot()
@@ -96,9 +97,81 @@ def HasFormatErrors(filename=None, contents=None):
9697

9798
return []
9899

100+
def _CheckNewTests(input_api, output_api):
101+
testsDirectories = [
102+
# Dart 1 tests DDC tests
103+
# ================= ==========================
104+
("tests/language/", "tests/language_2/"),
105+
("tests/corelib/", "tests/corelib_2/"),
106+
("tests/lib/", "tests/lib_2/"),
107+
("tests/html/", "tests/lib_2/html/"),
108+
]
109+
110+
result = []
111+
# Tuples of (new Dart 1 test path, expected DDC test path)
112+
dart1TestsAdded = []
113+
# Tuples of (original Dart test path, expected DDC test path)
114+
ddcTestsExists = []
115+
for f in input_api.AffectedFiles():
116+
for oldPath, newPath in testsDirectories:
117+
if f.LocalPath().startswith(oldPath):
118+
if f.Action() == 'A':
119+
# Compute where the new test should live.
120+
ddcTestPath = f.LocalPath().replace(oldPath, newPath)
121+
dart1TestsAdded.append((f.LocalPath(), ddcTestPath))
122+
elif f.Action() == 'M':
123+
# Find all modified tests in Dart 1.0
124+
filename = f.LocalPath()
125+
for oldPath, newPath in testsDirectories:
126+
if filename.find(oldPath) == 0:
127+
ddcTestFilePathAbs = "%s" % \
128+
f.AbsoluteLocalPath().replace(oldPath, newPath)
129+
if os.path.isfile(ddcTestFilePathAbs):
130+
#originalDart1Test.append(f.LocalPath())
131+
ddcTestsExists.append((f.LocalPath(),
132+
f.LocalPath().replace(oldPath, newPath)))
133+
134+
# Does a Dart 2.0 DDC test exist if so it must be changed too.
135+
missingDDCTestsChange = []
136+
for (dartTest, ddcTest) in ddcTestsExists:
137+
foundDDCTestModified = False
138+
for f in input_api.AffectedFiles():
139+
if f.LocalPath() == ddcTest:
140+
# Found corresponding DDC test - great.
141+
foundDDCTestModified = True
142+
break
143+
if not foundDDCTestModified:
144+
# Add the tuple (dart 1 test path, DDC test path)
145+
missingDDCTestsChange.append((dartTest, ddcTest))
146+
147+
if missingDDCTestsChange:
148+
errorList = []
149+
for idx, (orginalTest, ddcTest) in enumerate(missingDDCTestsChange):
150+
errorList.append(
151+
'%s. Dart 1.0 test changed: %s\n%s. DDC test must change: ' \
152+
'%s\n' % (idx + 1, orginalTest, idx + 1, ddcTest))
153+
result.append(output_api.PresubmitError(
154+
'Error: If you change a Dart 1.0 test, you must also update the DDC '
155+
'test:\n%s' % ''.join(errorList)))
156+
157+
if dart1TestsAdded:
158+
errorList = []
159+
for idx, (oldTestPath, newTestPath) in enumerate(dart1TestsAdded):
160+
errorList.append('%s. New Dart 1.0 test: %s\n'
161+
'%s. Should be DDC test: %s\n' % \
162+
(idx + 1, oldTestPath, idx + 1, newTestPath))
163+
result.append(output_api.PresubmitError(
164+
'Error: New Dart 1.0 test can not be added the test must be added as '
165+
'a DDC test:\n'
166+
'Fix tests:\n%s' % ''.join(errorList)))
167+
168+
return result
169+
99170
def CheckChangeOnCommit(input_api, output_api):
100171
return (_CheckBuildStatus(input_api, output_api) +
172+
_CheckNewTests(input_api, output_api) +
101173
_CheckDartFormat(input_api, output_api))
102174

103175
def CheckChangeOnUpload(input_api, output_api):
104-
return _CheckDartFormat(input_api, output_api)
176+
return (_CheckNewTests(input_api, output_api) +
177+
_CheckDartFormat(input_api, output_api))

0 commit comments

Comments
 (0)