blob: 58ca4027767377df42f14514da99b761320aa065 [file] [log] [blame]
[email protected]2299dcf2012-11-15 19:56:241#!/usr/bin/env python
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
[email protected]99171a92014-06-03 08:44:476import glob
7import json
[email protected]2299dcf2012-11-15 19:56:248import os
9import re
[email protected]99171a92014-06-03 08:44:4710import subprocess
11import sys
[email protected]2299dcf2012-11-15 19:56:2412import unittest
13
14import PRESUBMIT
gayane3dff8c22014-12-04 17:09:5115from PRESUBMIT_test_mocks import MockChange, MockFile
16from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi
[email protected]2299dcf2012-11-15 19:56:2417
[email protected]99171a92014-06-03 08:44:4718_TEST_DATA_DIR = 'base/test/data/presubmit'
19
[email protected]2299dcf2012-11-15 19:56:2420class IncludeOrderTest(unittest.TestCase):
21 def testSystemHeaderOrder(self):
22 scope = [(1, '#include <csystem.h>'),
23 (2, '#include <cppsystem>'),
24 (3, '#include "acustom.h"')]
25 all_linenums = [linenum for (linenum, _) in scope]
26 mock_input_api = MockInputApi()
27 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
28 '', all_linenums)
29 self.assertEqual(0, len(warnings))
30
31 def testSystemHeaderOrderMismatch1(self):
32 scope = [(10, '#include <cppsystem>'),
33 (20, '#include <csystem.h>'),
34 (30, '#include "acustom.h"')]
35 all_linenums = [linenum for (linenum, _) in scope]
36 mock_input_api = MockInputApi()
37 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
38 '', all_linenums)
39 self.assertEqual(1, len(warnings))
40 self.assertTrue('20' in warnings[0])
41
42 def testSystemHeaderOrderMismatch2(self):
43 scope = [(10, '#include <cppsystem>'),
44 (20, '#include "acustom.h"'),
45 (30, '#include <csystem.h>')]
46 all_linenums = [linenum for (linenum, _) in scope]
47 mock_input_api = MockInputApi()
48 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
49 '', all_linenums)
50 self.assertEqual(1, len(warnings))
51 self.assertTrue('30' in warnings[0])
52
53 def testSystemHeaderOrderMismatch3(self):
54 scope = [(10, '#include "acustom.h"'),
55 (20, '#include <csystem.h>'),
56 (30, '#include <cppsystem>')]
57 all_linenums = [linenum for (linenum, _) in scope]
58 mock_input_api = MockInputApi()
59 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
60 '', all_linenums)
61 self.assertEqual(2, len(warnings))
62 self.assertTrue('20' in warnings[0])
63 self.assertTrue('30' in warnings[1])
64
65 def testAlphabeticalOrderMismatch(self):
66 scope = [(10, '#include <csystem.h>'),
67 (15, '#include <bsystem.h>'),
68 (20, '#include <cppsystem>'),
69 (25, '#include <bppsystem>'),
70 (30, '#include "bcustom.h"'),
71 (35, '#include "acustom.h"')]
72 all_linenums = [linenum for (linenum, _) in scope]
73 mock_input_api = MockInputApi()
74 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
75 '', all_linenums)
76 self.assertEqual(3, len(warnings))
77 self.assertTrue('15' in warnings[0])
78 self.assertTrue('25' in warnings[1])
79 self.assertTrue('35' in warnings[2])
80
81 def testSpecialFirstInclude1(self):
82 mock_input_api = MockInputApi()
83 contents = ['#include "some/path/foo.h"',
84 '#include "a/header.h"']
85 mock_file = MockFile('some/path/foo.cc', contents)
86 warnings = PRESUBMIT._CheckIncludeOrderInFile(
[email protected]ac294a12012-12-06 16:38:4387 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]2299dcf2012-11-15 19:56:2488 self.assertEqual(0, len(warnings))
89
90 def testSpecialFirstInclude2(self):
91 mock_input_api = MockInputApi()
92 contents = ['#include "some/other/path/foo.h"',
93 '#include "a/header.h"']
94 mock_file = MockFile('some/path/foo.cc', contents)
95 warnings = PRESUBMIT._CheckIncludeOrderInFile(
[email protected]ac294a12012-12-06 16:38:4396 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]2299dcf2012-11-15 19:56:2497 self.assertEqual(0, len(warnings))
98
99 def testSpecialFirstInclude3(self):
100 mock_input_api = MockInputApi()
101 contents = ['#include "some/path/foo.h"',
102 '#include "a/header.h"']
103 mock_file = MockFile('some/path/foo_platform.cc', contents)
104 warnings = PRESUBMIT._CheckIncludeOrderInFile(
[email protected]ac294a12012-12-06 16:38:43105 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]2299dcf2012-11-15 19:56:24106 self.assertEqual(0, len(warnings))
107
108 def testSpecialFirstInclude4(self):
109 mock_input_api = MockInputApi()
110 contents = ['#include "some/path/bar.h"',
111 '#include "a/header.h"']
112 mock_file = MockFile('some/path/foo_platform.cc', contents)
113 warnings = PRESUBMIT._CheckIncludeOrderInFile(
[email protected]ac294a12012-12-06 16:38:43114 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]2299dcf2012-11-15 19:56:24115 self.assertEqual(1, len(warnings))
116 self.assertTrue('2' in warnings[0])
117
[email protected]ac294a12012-12-06 16:38:43118 def testSpecialFirstInclude5(self):
119 mock_input_api = MockInputApi()
120 contents = ['#include "some/other/path/foo.h"',
121 '#include "a/header.h"']
122 mock_file = MockFile('some/path/foo-suffix.h', contents)
123 warnings = PRESUBMIT._CheckIncludeOrderInFile(
124 mock_input_api, mock_file, range(1, len(contents) + 1))
125 self.assertEqual(0, len(warnings))
126
[email protected]3e83618c2013-10-09 22:32:33127 def testSpecialFirstInclude6(self):
128 mock_input_api = MockInputApi()
129 contents = ['#include "some/other/path/foo_win.h"',
130 '#include <set>',
131 '#include "a/header.h"']
132 mock_file = MockFile('some/path/foo_unittest_win.h', contents)
133 warnings = PRESUBMIT._CheckIncludeOrderInFile(
134 mock_input_api, mock_file, range(1, len(contents) + 1))
135 self.assertEqual(0, len(warnings))
136
[email protected]2299dcf2012-11-15 19:56:24137 def testOrderAlreadyWrong(self):
138 scope = [(1, '#include "b.h"'),
139 (2, '#include "a.h"'),
140 (3, '#include "c.h"')]
141 mock_input_api = MockInputApi()
142 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
143 '', [3])
144 self.assertEqual(0, len(warnings))
145
146 def testConflictAdded1(self):
147 scope = [(1, '#include "a.h"'),
148 (2, '#include "c.h"'),
149 (3, '#include "b.h"')]
150 mock_input_api = MockInputApi()
151 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
152 '', [2])
153 self.assertEqual(1, len(warnings))
154 self.assertTrue('3' in warnings[0])
155
156 def testConflictAdded2(self):
157 scope = [(1, '#include "c.h"'),
158 (2, '#include "b.h"'),
159 (3, '#include "d.h"')]
160 mock_input_api = MockInputApi()
161 warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api,
162 '', [2])
163 self.assertEqual(1, len(warnings))
164 self.assertTrue('2' in warnings[0])
165
[email protected]2309b0fa02012-11-16 12:18:27166 def testIfElifElseEndif(self):
167 mock_input_api = MockInputApi()
168 contents = ['#include "e.h"',
[email protected]ac294a12012-12-06 16:38:43169 '#define foo',
170 '#include "f.h"',
171 '#undef foo',
172 '#include "e.h"',
[email protected]2309b0fa02012-11-16 12:18:27173 '#if foo',
174 '#include "d.h"',
175 '#elif bar',
176 '#include "c.h"',
177 '#else',
178 '#include "b.h"',
179 '#endif',
180 '#include "a.h"']
181 mock_file = MockFile('', contents)
182 warnings = PRESUBMIT._CheckIncludeOrderInFile(
[email protected]ac294a12012-12-06 16:38:43183 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]2309b0fa02012-11-16 12:18:27184 self.assertEqual(0, len(warnings))
185
[email protected]23093b62013-09-20 12:16:30186 def testExcludedIncludes(self):
[email protected]962f117e2012-11-22 18:11:56187 # #include <sys/...>'s can appear in any order.
188 mock_input_api = MockInputApi()
189 contents = ['#include <sys/b.h>',
190 '#include <sys/a.h>']
191 mock_file = MockFile('', contents)
192 warnings = PRESUBMIT._CheckIncludeOrderInFile(
[email protected]ac294a12012-12-06 16:38:43193 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]962f117e2012-11-22 18:11:56194 self.assertEqual(0, len(warnings))
195
[email protected]23093b62013-09-20 12:16:30196 contents = ['#include <atlbase.h>',
197 '#include <aaa.h>']
198 mock_file = MockFile('', contents)
199 warnings = PRESUBMIT._CheckIncludeOrderInFile(
200 mock_input_api, mock_file, range(1, len(contents) + 1))
201 self.assertEqual(0, len(warnings))
202
203 contents = ['#include "build/build_config.h"',
204 '#include "aaa.h"']
205 mock_file = MockFile('', contents)
206 warnings = PRESUBMIT._CheckIncludeOrderInFile(
207 mock_input_api, mock_file, range(1, len(contents) + 1))
208 self.assertEqual(0, len(warnings))
209
[email protected]ac294a12012-12-06 16:38:43210 def testCheckOnlyCFiles(self):
211 mock_input_api = MockInputApi()
212 mock_output_api = MockOutputApi()
213 contents = ['#include <b.h>',
214 '#include <a.h>']
215 mock_file_cc = MockFile('something.cc', contents)
216 mock_file_h = MockFile('something.h', contents)
217 mock_file_other = MockFile('something.py', contents)
218 mock_input_api.files = [mock_file_cc, mock_file_h, mock_file_other]
219 warnings = PRESUBMIT._CheckIncludeOrder(mock_input_api, mock_output_api)
220 self.assertEqual(1, len(warnings))
221 self.assertEqual(2, len(warnings[0].items))
[email protected]f7051d52013-04-02 18:31:42222 self.assertEqual('promptOrNotify', warnings[0].type)
[email protected]ac294a12012-12-06 16:38:43223
[email protected]0e5c1852012-12-18 20:17:11224 def testUncheckableIncludes(self):
225 mock_input_api = MockInputApi()
226 contents = ['#include <windows.h>',
[email protected]4436c9e2014-01-07 23:19:54227 '#include "b.h"',
[email protected]0e5c1852012-12-18 20:17:11228 '#include "a.h"']
229 mock_file = MockFile('', contents)
230 warnings = PRESUBMIT._CheckIncludeOrderInFile(
231 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]4436c9e2014-01-07 23:19:54232 self.assertEqual(1, len(warnings))
[email protected]0e5c1852012-12-18 20:17:11233
234 contents = ['#include "gpu/command_buffer/gles_autogen.h"',
[email protected]4436c9e2014-01-07 23:19:54235 '#include "b.h"',
[email protected]0e5c1852012-12-18 20:17:11236 '#include "a.h"']
237 mock_file = MockFile('', contents)
238 warnings = PRESUBMIT._CheckIncludeOrderInFile(
239 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]4436c9e2014-01-07 23:19:54240 self.assertEqual(1, len(warnings))
[email protected]0e5c1852012-12-18 20:17:11241
242 contents = ['#include "gl_mock_autogen.h"',
[email protected]4436c9e2014-01-07 23:19:54243 '#include "b.h"',
[email protected]0e5c1852012-12-18 20:17:11244 '#include "a.h"']
245 mock_file = MockFile('', contents)
246 warnings = PRESUBMIT._CheckIncludeOrderInFile(
247 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]4436c9e2014-01-07 23:19:54248 self.assertEqual(1, len(warnings))
[email protected]0e5c1852012-12-18 20:17:11249
250 contents = ['#include "ipc/some_macros.h"',
[email protected]4436c9e2014-01-07 23:19:54251 '#include "b.h"',
[email protected]0e5c1852012-12-18 20:17:11252 '#include "a.h"']
253 mock_file = MockFile('', contents)
254 warnings = PRESUBMIT._CheckIncludeOrderInFile(
255 mock_input_api, mock_file, range(1, len(contents) + 1))
[email protected]4436c9e2014-01-07 23:19:54256 self.assertEqual(1, len(warnings))
[email protected]0e5c1852012-12-18 20:17:11257
[email protected]2299dcf2012-11-15 19:56:24258
[email protected]b00342e7f2013-03-26 16:21:54259class VersionControlConflictsTest(unittest.TestCase):
[email protected]70ca77752012-11-20 03:45:03260 def testTypicalConflict(self):
261 lines = ['<<<<<<< HEAD',
262 ' base::ScopedTempDir temp_dir_;',
263 '=======',
264 ' ScopedTempDir temp_dir_;',
265 '>>>>>>> master']
266 errors = PRESUBMIT._CheckForVersionControlConflictsInFile(
267 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
268 self.assertEqual(3, len(errors))
269 self.assertTrue('1' in errors[0])
270 self.assertTrue('3' in errors[1])
271 self.assertTrue('5' in errors[2])
272
273
[email protected]b8079ae4a2012-12-05 19:56:49274class BadExtensionsTest(unittest.TestCase):
275 def testBadRejFile(self):
276 mock_input_api = MockInputApi()
277 mock_input_api.files = [
278 MockFile('some/path/foo.cc', ''),
279 MockFile('some/path/foo.cc.rej', ''),
280 MockFile('some/path2/bar.h.rej', ''),
281 ]
282
283 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
284 self.assertEqual(1, len(results))
285 self.assertEqual(2, len(results[0].items))
286 self.assertTrue('foo.cc.rej' in results[0].items[0])
287 self.assertTrue('bar.h.rej' in results[0].items[1])
288
289 def testBadOrigFile(self):
290 mock_input_api = MockInputApi()
291 mock_input_api.files = [
292 MockFile('other/path/qux.h.orig', ''),
293 MockFile('other/path/qux.h', ''),
294 MockFile('other/path/qux.cc', ''),
295 ]
296
297 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
298 self.assertEqual(1, len(results))
299 self.assertEqual(1, len(results[0].items))
300 self.assertTrue('qux.h.orig' in results[0].items[0])
301
302 def testGoodFiles(self):
303 mock_input_api = MockInputApi()
304 mock_input_api.files = [
305 MockFile('other/path/qux.h', ''),
306 MockFile('other/path/qux.cc', ''),
307 ]
308 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
309 self.assertEqual(0, len(results))
310
[email protected]751b05f2013-01-10 23:12:17311 def testOnlyOwnersFiles(self):
312 mock_change = MockChange([
313 'some/path/OWNERS',
314 'A\Windows\Path\OWNERS',
315 ])
[email protected]7468ac522014-03-12 23:35:57316 results = PRESUBMIT.GetPreferredTryMasters(None, mock_change)
317 self.assertEqual({}, results)
[email protected]751b05f2013-01-10 23:12:17318
[email protected]b8079ae4a2012-12-05 19:56:49319
[email protected]b00342e7f2013-03-26 16:21:54320class InvalidOSMacroNamesTest(unittest.TestCase):
321 def testInvalidOSMacroNames(self):
322 lines = ['#if defined(OS_WINDOWS)',
323 ' #elif defined(OS_WINDOW)',
324 ' # if defined(OS_MACOSX) || defined(OS_CHROME)',
325 '# else // defined(OS_MAC)',
326 '#endif // defined(OS_MACOS)']
327 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
328 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
329 self.assertEqual(len(lines), len(errors))
330 self.assertTrue(':1 OS_WINDOWS' in errors[0])
331 self.assertTrue('(did you mean OS_WIN?)' in errors[0])
332
333 def testValidOSMacroNames(self):
334 lines = ['#if defined(%s)' % m for m in PRESUBMIT._VALID_OS_MACROS]
335 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
336 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
337 self.assertEqual(0, len(errors))
338
339
lliabraa35bab3932014-10-01 12:16:44340class InvalidIfDefinedMacroNamesTest(unittest.TestCase):
341 def testInvalidIfDefinedMacroNames(self):
342 lines = ['#if defined(TARGET_IPHONE_SIMULATOR)',
343 '#if !defined(TARGET_IPHONE_SIMULATOR)',
344 '#elif defined(TARGET_IPHONE_SIMULATOR)',
345 '#ifdef TARGET_IPHONE_SIMULATOR',
346 ' # ifdef TARGET_IPHONE_SIMULATOR',
347 '# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)',
348 '# else // defined(TARGET_IPHONE_SIMULATOR)',
349 '#endif // defined(TARGET_IPHONE_SIMULATOR)',]
350 errors = PRESUBMIT._CheckForInvalidIfDefinedMacrosInFile(
351 MockInputApi(), MockFile('some/path/source.mm', lines))
352 self.assertEqual(len(lines), len(errors))
353
354 def testValidIfDefinedMacroNames(self):
355 lines = ['#if defined(FOO)',
356 '#ifdef BAR',]
357 errors = PRESUBMIT._CheckForInvalidIfDefinedMacrosInFile(
358 MockInputApi(), MockFile('some/path/source.cc', lines))
359 self.assertEqual(0, len(errors))
360
361
[email protected]f32e2d1e2013-07-26 21:39:08362class CheckAddedDepsHaveTetsApprovalsTest(unittest.TestCase):
[email protected]14a6131c2014-01-08 01:15:41363 def testFilesToCheckForIncomingDeps(self):
[email protected]f32e2d1e2013-07-26 21:39:08364 changed_lines = [
365 '"+breakpad",',
366 '"+chrome/installer",',
367 '"+chrome/plugin/chrome_content_plugin_client.h",',
368 '"+chrome/utility/chrome_content_utility_client.h",',
369 '"+chromeos/chromeos_paths.h",',
philipj3f9d5bde2014-08-28 14:09:09370 '"+components/crash",',
[email protected]f32e2d1e2013-07-26 21:39:08371 '"+components/nacl/common",',
372 '"+content/public/browser/render_process_host.h",',
[email protected]14a6131c2014-01-08 01:15:41373 '"+jni/fooblat.h",',
[email protected]f32e2d1e2013-07-26 21:39:08374 '"+grit", # For generated headers',
375 '"+grit/generated_resources.h",',
376 '"+grit/",',
377 '"+policy", # For generated headers and source',
378 '"+sandbox",',
379 '"+tools/memory_watcher",',
380 '"+third_party/lss/linux_syscall_support.h",',
381 ]
[email protected]14a6131c2014-01-08 01:15:41382 files_to_check = PRESUBMIT._FilesToCheckForIncomingDeps(re, changed_lines)
[email protected]f32e2d1e2013-07-26 21:39:08383 expected = set([
384 'breakpad/DEPS',
385 'chrome/installer/DEPS',
[email protected]14a6131c2014-01-08 01:15:41386 'chrome/plugin/chrome_content_plugin_client.h',
387 'chrome/utility/chrome_content_utility_client.h',
388 'chromeos/chromeos_paths.h',
Robert Sesekabcd8102014-08-27 16:12:44389 'components/crash/DEPS',
[email protected]f32e2d1e2013-07-26 21:39:08390 'components/nacl/common/DEPS',
[email protected]14a6131c2014-01-08 01:15:41391 'content/public/browser/render_process_host.h',
[email protected]f32e2d1e2013-07-26 21:39:08392 'policy/DEPS',
393 'sandbox/DEPS',
394 'tools/memory_watcher/DEPS',
[email protected]14a6131c2014-01-08 01:15:41395 'third_party/lss/linux_syscall_support.h',
[email protected]f32e2d1e2013-07-26 21:39:08396 ])
397 self.assertEqual(expected, files_to_check);
398
399
[email protected]99171a92014-06-03 08:44:47400class JSONParsingTest(unittest.TestCase):
401 def testSuccess(self):
402 input_api = MockInputApi()
403 filename = 'valid_json.json'
404 contents = ['// This is a comment.',
405 '{',
406 ' "key1": ["value1", "value2"],',
407 ' "key2": 3 // This is an inline comment.',
408 '}'
409 ]
410 input_api.files = [MockFile(filename, contents)]
411 self.assertEqual(None,
412 PRESUBMIT._GetJSONParseError(input_api, filename))
413
414 def testFailure(self):
415 input_api = MockInputApi()
416 test_data = [
417 ('invalid_json_1.json',
418 ['{ x }'],
[email protected]a3343272014-06-17 11:41:53419 'Expecting property name:'),
[email protected]99171a92014-06-03 08:44:47420 ('invalid_json_2.json',
421 ['// Hello world!',
422 '{ "hello": "world }'],
[email protected]a3343272014-06-17 11:41:53423 'Unterminated string starting at:'),
[email protected]99171a92014-06-03 08:44:47424 ('invalid_json_3.json',
425 ['{ "a": "b", "c": "d", }'],
[email protected]a3343272014-06-17 11:41:53426 'Expecting property name:'),
[email protected]99171a92014-06-03 08:44:47427 ('invalid_json_4.json',
428 ['{ "a": "b" "c": "d" }'],
[email protected]a3343272014-06-17 11:41:53429 'Expecting , delimiter:'),
[email protected]99171a92014-06-03 08:44:47430 ]
431
432 input_api.files = [MockFile(filename, contents)
433 for (filename, contents, _) in test_data]
434
435 for (filename, _, expected_error) in test_data:
436 actual_error = PRESUBMIT._GetJSONParseError(input_api, filename)
[email protected]a3343272014-06-17 11:41:53437 self.assertTrue(expected_error in str(actual_error),
438 "'%s' not found in '%s'" % (expected_error, actual_error))
[email protected]99171a92014-06-03 08:44:47439
440 def testNoEatComments(self):
441 input_api = MockInputApi()
442 file_with_comments = 'file_with_comments.json'
443 contents_with_comments = ['// This is a comment.',
444 '{',
445 ' "key1": ["value1", "value2"],',
446 ' "key2": 3 // This is an inline comment.',
447 '}'
448 ]
449 file_without_comments = 'file_without_comments.json'
450 contents_without_comments = ['{',
451 ' "key1": ["value1", "value2"],',
452 ' "key2": 3',
453 '}'
454 ]
455 input_api.files = [MockFile(file_with_comments, contents_with_comments),
456 MockFile(file_without_comments,
457 contents_without_comments)]
458
459 self.assertEqual('No JSON object could be decoded',
460 str(PRESUBMIT._GetJSONParseError(input_api,
461 file_with_comments,
462 eat_comments=False)))
463 self.assertEqual(None,
464 PRESUBMIT._GetJSONParseError(input_api,
465 file_without_comments,
466 eat_comments=False))
467
468
469class IDLParsingTest(unittest.TestCase):
470 def testSuccess(self):
471 input_api = MockInputApi()
472 filename = 'valid_idl_basics.idl'
473 contents = ['// Tests a valid IDL file.',
474 'namespace idl_basics {',
475 ' enum EnumType {',
476 ' name1,',
477 ' name2',
478 ' };',
479 '',
480 ' dictionary MyType1 {',
481 ' DOMString a;',
482 ' };',
483 '',
484 ' callback Callback1 = void();',
485 ' callback Callback2 = void(long x);',
486 ' callback Callback3 = void(MyType1 arg);',
487 ' callback Callback4 = void(EnumType type);',
488 '',
489 ' interface Functions {',
490 ' static void function1();',
491 ' static void function2(long x);',
492 ' static void function3(MyType1 arg);',
493 ' static void function4(Callback1 cb);',
494 ' static void function5(Callback2 cb);',
495 ' static void function6(Callback3 cb);',
496 ' static void function7(Callback4 cb);',
497 ' };',
498 '',
499 ' interface Events {',
500 ' static void onFoo1();',
501 ' static void onFoo2(long x);',
502 ' static void onFoo2(MyType1 arg);',
503 ' static void onFoo3(EnumType type);',
504 ' };',
505 '};'
506 ]
507 input_api.files = [MockFile(filename, contents)]
508 self.assertEqual(None,
509 PRESUBMIT._GetIDLParseError(input_api, filename))
510
511 def testFailure(self):
512 input_api = MockInputApi()
513 test_data = [
514 ('invalid_idl_1.idl',
515 ['//',
516 'namespace test {',
517 ' dictionary {',
518 ' DOMString s;',
519 ' };',
520 '};'],
521 'Unexpected "{" after keyword "dictionary".\n'),
522 # TODO(yoz): Disabled because it causes the IDL parser to hang.
523 # See crbug.com/363830.
524 # ('invalid_idl_2.idl',
525 # (['namespace test {',
526 # ' dictionary MissingSemicolon {',
527 # ' DOMString a',
528 # ' DOMString b;',
529 # ' };',
530 # '};'],
531 # 'Unexpected symbol DOMString after symbol a.'),
532 ('invalid_idl_3.idl',
533 ['//',
534 'namespace test {',
535 ' enum MissingComma {',
536 ' name1',
537 ' name2',
538 ' };',
539 '};'],
540 'Unexpected symbol name2 after symbol name1.'),
541 ('invalid_idl_4.idl',
542 ['//',
543 'namespace test {',
544 ' enum TrailingComma {',
545 ' name1,',
546 ' name2,',
547 ' };',
548 '};'],
549 'Trailing comma in block.'),
550 ('invalid_idl_5.idl',
551 ['//',
552 'namespace test {',
553 ' callback Callback1 = void(;',
554 '};'],
555 'Unexpected ";" after "(".'),
556 ('invalid_idl_6.idl',
557 ['//',
558 'namespace test {',
559 ' callback Callback1 = void(long );',
560 '};'],
561 'Unexpected ")" after symbol long.'),
562 ('invalid_idl_7.idl',
563 ['//',
564 'namespace test {',
565 ' interace Events {',
566 ' static void onFoo1();',
567 ' };',
568 '};'],
569 'Unexpected symbol Events after symbol interace.'),
570 ('invalid_idl_8.idl',
571 ['//',
572 'namespace test {',
573 ' interface NotEvent {',
574 ' static void onFoo1();',
575 ' };',
576 '};'],
577 'Did not process Interface Interface(NotEvent)'),
578 ('invalid_idl_9.idl',
579 ['//',
580 'namespace test {',
581 ' interface {',
582 ' static void function1();',
583 ' };',
584 '};'],
585 'Interface missing name.'),
586 ]
587
588 input_api.files = [MockFile(filename, contents)
589 for (filename, contents, _) in test_data]
590
591 for (filename, _, expected_error) in test_data:
592 actual_error = PRESUBMIT._GetIDLParseError(input_api, filename)
593 self.assertTrue(expected_error in str(actual_error),
594 "'%s' not found in '%s'" % (expected_error, actual_error))
595
596
[email protected]0bb112362014-07-26 04:38:32597class TryServerMasterTest(unittest.TestCase):
598 def testTryServerMasters(self):
599 bots = {
600 'tryserver.chromium.gpu': [
[email protected]0bb112362014-07-26 04:38:32601 'win_gpu',
602 'win_gpu_triggered_tests',
603 ],
604 'tryserver.chromium.mac': [
605 'ios_dbg_simulator',
606 'ios_rel_device',
607 'ios_rel_device_ninja',
608 'mac_asan',
609 'mac_asan_64',
610 'mac_chromium_compile_dbg',
611 'mac_chromium_compile_rel',
612 'mac_chromium_dbg',
613 'mac_chromium_rel',
[email protected]0bb112362014-07-26 04:38:32614 'mac_nacl_sdk',
615 'mac_nacl_sdk_build',
616 'mac_rel_naclmore',
617 'mac_valgrind',
618 'mac_x64_rel',
619 'mac_xcodebuild',
620 ],
621 'tryserver.chromium.linux': [
622 'android_aosp',
623 'android_chromium_gn_compile_dbg',
624 'android_chromium_gn_compile_rel',
625 'android_clang_dbg',
626 'android_dbg',
627 'android_dbg_recipe',
628 'android_dbg_triggered_tests',
629 'android_dbg_triggered_tests_recipe',
630 'android_fyi_dbg',
631 'android_fyi_dbg_triggered_tests',
632 'android_rel',
633 'android_rel_triggered_tests',
634 'android_x86_dbg',
635 'blink_android_compile_dbg',
636 'blink_android_compile_rel',
637 'blink_presubmit',
638 'chromium_presubmit',
639 'linux_arm_cross_compile',
640 'linux_arm_tester',
[email protected]0bb112362014-07-26 04:38:32641 'linux_chromeos_asan',
642 'linux_chromeos_browser_asan',
643 'linux_chromeos_valgrind',
[email protected]0bb112362014-07-26 04:38:32644 'linux_chromium_chromeos_dbg',
645 'linux_chromium_chromeos_rel',
[email protected]0bb112362014-07-26 04:38:32646 'linux_chromium_compile_dbg',
647 'linux_chromium_compile_rel',
648 'linux_chromium_dbg',
649 'linux_chromium_gn_dbg',
650 'linux_chromium_gn_rel',
651 'linux_chromium_rel',
[email protected]0bb112362014-07-26 04:38:32652 'linux_chromium_trusty32_dbg',
653 'linux_chromium_trusty32_rel',
654 'linux_chromium_trusty_dbg',
655 'linux_chromium_trusty_rel',
656 'linux_clang_tsan',
657 'linux_ecs_ozone',
658 'linux_layout',
659 'linux_layout_asan',
660 'linux_layout_rel',
661 'linux_layout_rel_32',
662 'linux_nacl_sdk',
663 'linux_nacl_sdk_bionic',
664 'linux_nacl_sdk_bionic_build',
665 'linux_nacl_sdk_build',
666 'linux_redux',
667 'linux_rel_naclmore',
668 'linux_rel_precise32',
669 'linux_valgrind',
670 'tools_build_presubmit',
671 ],
672 'tryserver.chromium.win': [
673 'win8_aura',
674 'win8_chromium_dbg',
675 'win8_chromium_rel',
676 'win_chromium_compile_dbg',
677 'win_chromium_compile_rel',
678 'win_chromium_dbg',
679 'win_chromium_rel',
680 'win_chromium_rel',
[email protected]0bb112362014-07-26 04:38:32681 'win_chromium_x64_dbg',
682 'win_chromium_x64_rel',
683 'win_drmemory',
684 'win_nacl_sdk',
685 'win_nacl_sdk_build',
686 'win_rel_naclmore',
687 ],
688 }
689 for master, bots in bots.iteritems():
690 for bot in bots:
691 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot),
692 'bot=%s: expected %s, computed %s' % (
693 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot)))
694
695
[email protected]2299dcf2012-11-15 19:56:24696if __name__ == '__main__':
697 unittest.main()