Report a presubmit error if a test file in Dart 1.0 is modified or added.

Only allow .status files in Dart 1.0 test directories to be changed.

R=rnystrom@google.com

Change-Id: Ic95b76eb53e7d5ab6b795425a7a97f0fded01a5b
Reviewed-on: https://dart-review.googlesource.com/14120
Commit-Queue: Terry Lucas <terry@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Terry Lucas <terry@google.com>
This commit is contained in:
Terry Lucas 2017-10-17 15:16:30 +00:00 committed by commit-bot@chromium.org
parent 60be83aed4
commit de187713ac

View file

@ -99,7 +99,7 @@ def _CheckDartFormat(input_api, output_api):
def _CheckNewTests(input_api, output_api):
testsDirectories = [
# Dart 1 tests DDC tests
# Dart 1 tests Dart 2.0 tests
# ================= ==========================
("tests/language/", "tests/language_2/"),
("tests/corelib/", "tests/corelib_2/"),
@ -108,62 +108,62 @@ def _CheckNewTests(input_api, output_api):
]
result = []
# Tuples of (new Dart 1 test path, expected DDC test path)
# Tuples of (new Dart 1 test path, expected Dart 2.0 test path)
dart1TestsAdded = []
# Tuples of (original Dart test path, expected DDC test path)
ddcTestsExists = []
for f in input_api.AffectedFiles():
for oldPath, newPath in testsDirectories:
if f.LocalPath().startswith(oldPath):
if f.Action() == 'A':
# Compute where the new test should live.
ddcTestPath = f.LocalPath().replace(oldPath, newPath)
dart1TestsAdded.append((f.LocalPath(), ddcTestPath))
elif f.Action() == 'M':
# Find all modified tests in Dart 1.0
filename = f.LocalPath()
for oldPath, newPath in testsDirectories:
if filename.find(oldPath) == 0:
ddcTestFilePathAbs = "%s" % \
f.AbsoluteLocalPath().replace(oldPath, newPath)
if os.path.isfile(ddcTestFilePathAbs):
#originalDart1Test.append(f.LocalPath())
ddcTestsExists.append((f.LocalPath(),
f.LocalPath().replace(oldPath, newPath)))
# Tuples of (original Dart test path, expected Dart 2.0 test path)
dart2TestsExists = []
for f in input_api.AffectedTextFiles():
localpath = f.LocalPath()
if not(localpath.endswith('.status')):
for oldPath, newPath in testsDirectories:
if localpath.startswith(oldPath):
if f.Action() == 'A':
# Compute where the new test should live.
dart2TestPath = localpath.replace(oldPath, newPath)
dart1TestsAdded.append((localpath, dart2TestPath))
elif f.Action() == 'M':
# Find all modified tests in Dart 1.0
for oldPath, newPath in testsDirectories:
if localpath.find(oldPath) == 0:
dart2TestFilePathAbs = "%s" % \
f.AbsoluteLocalPath().replace(oldPath, newPath)
if os.path.isfile(dart2TestFilePathAbs):
#originalDart1Test.append(localpath)
dart2TestsExists.append((localpath,
localpath.replace(oldPath, newPath)))
# Does a Dart 2.0 DDC test exist if so it must be changed too.
missingDDCTestsChange = []
for (dartTest, ddcTest) in ddcTestsExists:
foundDDCTestModified = False
# Does a Dart 2.0 test exist if so it must be changed too.
missingDart2TestsChange = []
for (dartTest, dart2Test) in dart2TestsExists:
foundDart2TestModified = False
for f in input_api.AffectedFiles():
if f.LocalPath() == ddcTest:
# Found corresponding DDC test - great.
foundDDCTestModified = True
if f.LocalPath() == dart2Test:
# Found corresponding Dart 2 test - great.
foundDart2TestModified = True
break
if not foundDDCTestModified:
# Add the tuple (dart 1 test path, DDC test path)
missingDDCTestsChange.append((dartTest, ddcTest))
if not foundDart2TestModified:
# Add the tuple (dart 1 test path, Dart 2.0 test path)
missingDart2TestsChange.append((dartTest, dart2Test))
if missingDDCTestsChange:
if missingDart2TestsChange:
errorList = []
for idx, (orginalTest, ddcTest) in enumerate(missingDDCTestsChange):
for idx, (orginalTest, dart2Test) in enumerate(missingDart2TestsChange):
errorList.append(
'%s. Dart 1.0 test changed: %s\n%s. DDC test must change: ' \
'%s\n' % (idx + 1, orginalTest, idx + 1, ddcTest))
'%s. Dart 1.0 test changed: %s\n%s. Only the Dart 2.0 test can '\
'change: %s\n' % (idx + 1, orginalTest, idx + 1, dart2Test))
result.append(output_api.PresubmitError(
'Error: If you change a Dart 1.0 test, you must also update the DDC '
'test:\n%s' % ''.join(errorList)))
'Error: Changed Dart 1.0 test detected - only 1.0 status files can '\
'change. Migrate test to Dart 2.0 tests:\n%s' % ''.join(errorList)))
if dart1TestsAdded:
errorList = []
for idx, (oldTestPath, newTestPath) in enumerate(dart1TestsAdded):
errorList.append('%s. New Dart 1.0 test: %s\n'
'%s. Should be DDC test: %s\n' % \
'%s. Should be Dart 2.0 test: %s\n' % \
(idx + 1, oldTestPath, idx + 1, newTestPath))
result.append(output_api.PresubmitError(
'Error: New Dart 1.0 test can not be added the test must be added as '
'a DDC test:\n'
'Fix tests:\n%s' % ''.join(errorList)))
'Error: New Dart 1.0 test can not be added the test must be added '\
'as a Dart 2.0 test:\nFix tests:\n%s' % ''.join(errorList)))
return result