Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1032)

Side by Side Diff: PRESUBMIT.py

Issue 2982043002: Added presubmit checks for tests. (Closed)
Patch Set: Updated Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 4
5 """Top-level presubmit script for Dart. 5 """Top-level presubmit script for Dart.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl. 8 for more details about the presubmit API built into gcl.
9 """ 9 """
10 10
11 import imp 11 import imp
12 import os 12 import os
13 import os.path
13 import scm 14 import scm
14 import subprocess 15 import subprocess
15 import tempfile 16 import tempfile
16 17
17 def _CheckBuildStatus(input_api, output_api): 18 def _CheckBuildStatus(input_api, output_api):
18 results = [] 19 results = []
19 status_check = input_api.canned_checks.CheckTreeIsOpen( 20 status_check = input_api.canned_checks.CheckTreeIsOpen(
20 input_api, 21 input_api,
21 output_api, 22 output_api,
22 json_url='http://dart-status.appspot.com/current?format=json') 23 json_url='http://dart-status.appspot.com/current?format=json')
23 results.extend(status_check) 24 results.extend(status_check)
24 return results 25 return results
25 26
26 def _CheckDartFormat(input_api, output_api): 27 def _CheckDartFormat(input_api, output_api):
27 local_root = input_api.change.RepositoryRoot() 28 local_root = input_api.change.RepositoryRoot()
28 upstream = input_api.change._upstream 29 upstream = input_api.change._upstream
29 utils = imp.load_source('utils', 30 utils = imp.load_source('utils',
30 os.path.join(local_root, 'tools', 'utils.py')) 31 os.path.join(local_root, 'tools', 'utils.py'))
31 32
32 prebuilt_dartfmt = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dartfmt') 33 prebuilt_dartfmt = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dartfmt')
33 34
34 windows = utils.GuessOS() == 'win32' 35 windows = utils.GuessOS() == 'win32'
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 unformatted_files.append(filename) 90 unformatted_files.append(filename)
90 91
91 if unformatted_files: 92 if unformatted_files:
92 return [output_api.PresubmitError( 93 return [output_api.PresubmitError(
93 'File output does not match dartfmt.\n' 94 'File output does not match dartfmt.\n'
94 'Fix these issues with:\n' 95 'Fix these issues with:\n'
95 '%s -w \\\n%s' % (prebuilt_dartfmt, ' \\\n'.join(unformatted_files)))] 96 '%s -w \\\n%s' % (prebuilt_dartfmt, ' \\\n'.join(unformatted_files)))]
96 97
97 return [] 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 def CheckChangeOnCommit(input_api, output_api): 170 def CheckChangeOnCommit(input_api, output_api):
100 return (_CheckBuildStatus(input_api, output_api) + 171 return (_CheckBuildStatus(input_api, output_api) +
172 _CheckNewTests(input_api, output_api) +
101 _CheckDartFormat(input_api, output_api)) 173 _CheckDartFormat(input_api, output_api))
102 174
103 def CheckChangeOnUpload(input_api, output_api): 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))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698