| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Top-level presubmit script for depot tools. | |
| 6 | |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | |
| 8 details on the presubmit API built into gcl. | |
| 9 """ | |
| 10 | |
| 11 | |
| 12 def CheckChangeOnUpload(input_api, output_api): | |
| 13 return RunTests(input_api, output_api) | |
| 14 | |
| 15 | |
| 16 def CheckChangeOnCommit(input_api, output_api): | |
| 17 return RunTests(input_api, output_api) | |
| 18 | |
| 19 | |
| 20 def RunTests(input_api, output_api): | |
| 21 """Run all the shells scripts in the directory test. | |
| 22 """ | |
| 23 # Not exposed from InputApi. | |
| 24 from os import listdir | |
| 25 | |
| 26 # First loads a local Rietveld instance. | |
| 27 import sys | |
| 28 old_sys_path = sys.path | |
| 29 try: | |
| 30 sys.path = [input_api.PresubmitLocalPath()] + sys.path | |
| 31 from test import local_rietveld # pylint: disable=W0403 | |
| 32 server = local_rietveld.LocalRietveld() | |
| 33 finally: | |
| 34 sys.path = old_sys_path | |
| 35 | |
| 36 # Set to True for testing. | |
| 37 verbose = False | |
| 38 if verbose: | |
| 39 stdout = None | |
| 40 stderr = None | |
| 41 else: | |
| 42 stdout = input_api.subprocess.PIPE | |
| 43 stderr = input_api.subprocess.STDOUT | |
| 44 output = [] | |
| 45 try: | |
| 46 # Start a local rietveld instance to test against. | |
| 47 server.start_server() | |
| 48 test_path = input_api.os_path.abspath( | |
| 49 input_api.os_path.join(input_api.PresubmitLocalPath(), 'test')) | |
| 50 for test in listdir(test_path): | |
| 51 # test-lib.sh is not an actual test so it should not be run. The other | |
| 52 # tests are tests known to fail. | |
| 53 DISABLED_TESTS = ( | |
| 54 'owners.sh', 'push-from-logs.sh', 'rename.sh', 'test-lib.sh') | |
| 55 if test in DISABLED_TESTS or not test.endswith('.sh'): | |
| 56 continue | |
| 57 | |
| 58 print('Running %s' % test) | |
| 59 proc = input_api.subprocess.Popen( | |
| 60 [input_api.os_path.join(test_path, test)], | |
| 61 cwd=test_path, | |
| 62 stdout=stdout, | |
| 63 stderr=stderr) | |
| 64 proc.communicate() | |
| 65 if proc.returncode != 0: | |
| 66 output.append(output_api.PresubmitError('%s failed' % test)) | |
| 67 except local_rietveld.Failure, e: | |
| 68 output.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args))) | |
| 69 finally: | |
| 70 server.stop_server() | |
| 71 return output | |
| OLD | NEW |