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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 870062aee77e3a2c1a993c72af29792eac00e702..64d30c320755f00223435e713ae9d0f3a8ae9a29 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -10,18 +10,19 @@ for more details about the presubmit API built into gcl.
import imp
import os
+import os.path
import scm
import subprocess
import tempfile
def _CheckBuildStatus(input_api, output_api):
- results = []
- status_check = input_api.canned_checks.CheckTreeIsOpen(
- input_api,
- output_api,
- json_url='http://dart-status.appspot.com/current?format=json')
- results.extend(status_check)
- return results
+ results = []
+ status_check = input_api.canned_checks.CheckTreeIsOpen(
+ input_api,
+ output_api,
+ json_url='http://dart-status.appspot.com/current?format=json')
+ results.extend(status_check)
+ return results
def _CheckDartFormat(input_api, output_api):
local_root = input_api.change.RepositoryRoot()
@@ -96,9 +97,81 @@ def _CheckDartFormat(input_api, output_api):
return []
+def _CheckNewTests(input_api, output_api):
+ testsDirectories = [
+ # Dart 1 tests DDC tests
+ # ================= ==========================
+ ("tests/language/", "tests/language_2/"),
+ ("tests/corelib/", "tests/corelib_2/"),
+ ("tests/lib/", "tests/lib_2/"),
+ ("tests/html/", "tests/lib_2/html/"),
+ ]
+
+ result = []
+ # Tuples of (new Dart 1 test path, expected DDC 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)))
+
+ # Does a Dart 2.0 DDC test exist if so it must be changed too.
+ missingDDCTestsChange = []
+ for (dartTest, ddcTest) in ddcTestsExists:
+ foundDDCTestModified = False
+ for f in input_api.AffectedFiles():
+ if f.LocalPath() == ddcTest:
+ # Found corresponding DDC test - great.
+ foundDDCTestModified = True
+ break
+ if not foundDDCTestModified:
+ # Add the tuple (dart 1 test path, DDC test path)
+ missingDDCTestsChange.append((dartTest, ddcTest))
+
+ if missingDDCTestsChange:
+ errorList = []
+ for idx, (orginalTest, ddcTest) in enumerate(missingDDCTestsChange):
+ errorList.append(
+ '%s. Dart 1.0 test changed: %s\n%s. DDC test must change: ' \
+ '%s\n' % (idx + 1, orginalTest, idx + 1, ddcTest))
+ 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)))
+
+ 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' % \
+ (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)))
+
+ 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))
« 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