OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import glob | |
6 import json | 7 import json |
7 import os | 8 import os |
8 import subprocess | 9 import subprocess |
9 import sys | 10 import sys |
10 import unittest | 11 import unittest |
11 | 12 |
12 import PRESUBMIT | 13 import PRESUBMIT |
13 | 14 |
14 | 15 |
15 class MockInputApi(object): | 16 class MockInputApi(object): |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 self.assertEqual( | 52 self.assertEqual( |
52 'Expecting property name: line 1 column 22 (char 22)', | 53 'Expecting property name: line 1 column 22 (char 22)', |
53 str(PRESUBMIT._GetJSONParseError(input_api, input_json))) | 54 str(PRESUBMIT._GetJSONParseError(input_api, input_json))) |
54 | 55 |
55 input_json = '{ "a": "b" "c": "d" }' | 56 input_json = '{ "a": "b" "c": "d" }' |
56 self.assertEqual( | 57 self.assertEqual( |
57 'Expecting , delimiter: line 1 column 11 (char 11)', | 58 'Expecting , delimiter: line 1 column 11 (char 11)', |
58 str(PRESUBMIT._GetJSONParseError(input_api, input_json))) | 59 str(PRESUBMIT._GetJSONParseError(input_api, input_json))) |
59 | 60 |
60 | 61 |
62 class IDLParsingTest(unittest.TestCase): | |
63 def testSuccess(self): | |
64 input_api = MockInputApi() | |
65 filename = 'test_presubmit/valid_idl_basics.idl' | |
66 self.assertEqual(None, | |
67 PRESUBMIT._GetIDLParseError(input_api, filename)) | |
68 | |
69 def testFailure(self): | |
70 input_api = MockInputApi() | |
71 expected_errors = [ | |
72 '''Unexpected "{" after keyword "dictionary".''', | |
73 '''Unexpected symbol DOMString after symbol a.''', | |
74 '''Unexpected symbol name2 after symbol name1.''', | |
75 '''Trailing comma in block.''', | |
76 '''Unexpected ";" after "(".''', | |
77 '''Unexpected ")" after symbol long.''', | |
78 '''Unexpected symbol Events after symbol interace.''', | |
79 '''Did not process Interface Interface(NotEvent)''', | |
80 '''Interface missing name.''' | |
81 ] | |
82 | |
83 for i in range(0, len(glob.glob('test_presubmit/invalid_*.idl'))): | |
84 filename = 'test_presubmit/invalid_idl_' + str(i+1) + '.idl' | |
Yoyo Zhou
2013/09/09 17:19:27
Why not simply
for filename in glob.glob(...)
Haojian Wu
2013/09/10 02:51:04
Done.
| |
85 error = PRESUBMIT._GetIDLParseError(input_api, filename) | |
86 self.assertTrue(expected_errors[i] in error) | |
87 | |
88 | |
61 if __name__ == "__main__": | 89 if __name__ == "__main__": |
62 unittest.main() | 90 unittest.main() |
OLD | NEW |