Index: PRESUBMIT.py |
diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
index 870062aee77e3a2c1a993c72af29792eac00e702..6f3211a41e559e1fcda6330c1f7896993a45e79d 100644 |
--- a/PRESUBMIT.py |
+++ b/PRESUBMIT.py |
@@ -10,6 +10,8 @@ for more details about the presubmit API built into gcl. |
import imp |
import os |
+import os.path |
+import re |
import scm |
import subprocess |
import tempfile |
@@ -96,9 +98,68 @@ def _CheckDartFormat(input_api, output_api): |
return [] |
+def _CheckNewTests(input_api, output_api): |
+ testsDirectories = [ |
+ # Dart 1 tests Dart 2.0 tests |
Bob Nystrom
2017/07/17 20:38:23
I would say "DDC tests" instead of "Dart 2.0", sin
terry
2017/07/18 13:48:49
Done.
|
+ # ================= ========================== |
+ ("tests/language/", "tests/language_strong/"), |
+ ("tests/corelib/", "tests/corelib_strong/"), |
+ ("tests/lib/", "tests/lib_strong/"), |
+ ("tests/html/", "tests/lib_strong/html/"), |
+ ] |
+ |
+ result = [] |
+ old_locations = re.compile('tests/(language|corelib|lib|html|)/.*\.(dart)') |
+ |
+ dart1TestsAdded = [] |
+ strongTestsExists = [] |
+ for f in input_api.AffectedFiles(): |
Jacob
2017/07/17 20:16:34
Indentation seems strange. Ident two spaces by def
terry
2017/07/18 13:48:49
Yes didn't notice that the 2 functions have differ
terry
2017/07/18 13:48:49
Acknowledged.
terry
2017/07/18 13:48:50
Done.
|
+ if old_locations.match(f.LocalPath()): |
Jacob
2017/07/17 20:16:34
I believe you should be able to match relative to
terry
2017/07/18 13:48:50
Done.
|
+ if f.Action() == 'A': |
+ dart1TestsAdded.append(f.LocalPath()) |
+ elif f.Action() == 'M': |
+ # Find all modified tests in Dart 1.0 |
+ filename = f.LocalPath() |
+ for oldDir, newDir in testsDirectories: |
+ if filename.find(oldDir) == 0: |
+ strongTestFilePathAbs = "%s" % \ |
+ f.AbsoluteLocalPath().replace(oldDir, newDir) |
+ if os.path.isfile(strongTestFilePathAbs): |
+ strongTestsExists.append(f.LocalPath().replace(oldDir, |
+ newDir)) |
+ |
+ # Does a Dart 2.0 strong mode test exist if not its a problem. |
+ missingStrongTestsChange = [] |
+ for strongTest in strongTestsExists: |
+ foundStrongTestModified = False |
+ for f in input_api.AffectedFiles(): |
+ if f.LocalPath() == strongTest: |
+ # Found corresponding strong mode test, great. |
+ foundStrongTestModified = True |
+ break; |
Bob Nystrom
2017/07/17 20:38:24
No ";" in Python. :)
terry
2017/07/18 13:48:50
Done.
|
+ if not foundStrongTestModified: |
+ missingStrongTestsChange.append(strongTest) |
+ |
+ if missingStrongTestsChange: |
+ errorList = '%s\n'.join(missingStrongTestsChange) |
+ result.append(output_api.PresubmitError( |
+ 'Error: Test(s) changed in Dart 1.0 must be changed in the Dart 2.0 ' |
+ 'test too.\n' |
Bob Nystrom
2017/07/17 20:38:23
How about:
"If you change a Dart 1.0 test, you mu
terry
2017/07/18 13:48:50
Done.
|
+ 'Fix tests:\n%s' % errorList)) |
+ if dart1TestsAdded: |
+ errorList = '%s\n'.join(dart1TestsAdded) |
+ result.append(output_api.PresubmitError( |
+ 'Error: New Dart 1.0 test can not be added the test must be added ' |
Jacob
2017/07/17 20:16:34
maybe remind users where the dart 2.0 test should
Bob Nystrom
2017/07/17 20:38:24
+1.
It will be the same as the DDC path but with
terry
2017/07/18 13:48:49
Done.
|
+ 'only to Dart 2.0:\n' |
+ 'Fix tests:\n%s' % errorList)) |
+ |
+ return result |
+ |
def CheckChangeOnCommit(input_api, output_api): |
return (_CheckBuildStatus(input_api, output_api) + |
+ _CheckNewTests(input_api, output_api) + |
_CheckDartFormat(input_api, output_api)) |
def CheckChangeOnUpload(input_api, output_api): |
- return _CheckDartFormat(input_api, output_api) |
+ return (_CheckNewTests(input_api, output_api) + |
+ _CheckDartFormat(input_api, output_api)) |