|
10 | 10 |
|
11 | 11 | import imp |
12 | 12 | import os |
| 13 | +import os.path |
13 | 14 | import scm |
14 | 15 | import subprocess |
15 | 16 | import tempfile |
16 | 17 |
|
17 | 18 | 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 |
25 | 26 |
|
26 | 27 | def _CheckDartFormat(input_api, output_api): |
27 | 28 | local_root = input_api.change.RepositoryRoot() |
@@ -96,9 +97,81 @@ def HasFormatErrors(filename=None, contents=None): |
96 | 97 |
|
97 | 98 | return [] |
98 | 99 |
|
| 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 | + |
99 | 170 | def CheckChangeOnCommit(input_api, output_api): |
100 | 171 | return (_CheckBuildStatus(input_api, output_api) + |
| 172 | + _CheckNewTests(input_api, output_api) + |
101 | 173 | _CheckDartFormat(input_api, output_api)) |
102 | 174 |
|
103 | 175 | 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