diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-03 08:44:47 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-03 08:44:47 +0000 |
commit | 99171a94995b46692a7008a9f2f0548e4b38d29f (patch) | |
tree | c439e6403f5c1c787f9775542605c4cea24ce77e /chrome/common | |
parent | 21075b5dc4f91266175d92b46c004c24bf69f73e (diff) | |
download | chromium_src-99171a94995b46692a7008a9f2f0548e4b38d29f.zip chromium_src-99171a94995b46692a7008a9f2f0548e4b38d29f.tar.gz chromium_src-99171a94995b46692a7008a9f2f0548e4b38d29f.tar.bz2 |
Add global presubmit that JSON and IDL files can be parsed.
Sometimes, changes to JSON/IDL files make them invalid. It's easier to check these at presubmit time than discovering they can't be parsed at runtime.
This just moves the check from chrome/common/extensions/api to top-level.
This presubmit check excludes files in test/data directories.
BUG=366395
Review URL: https://codereview.chromium.org/239283008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
17 files changed, 0 insertions, 342 deletions
diff --git a/chrome/common/extensions/api/PRESUBMIT.py b/chrome/common/extensions/api/PRESUBMIT.py deleted file mode 100644 index 771f7fd..0000000 --- a/chrome/common/extensions/api/PRESUBMIT.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright 2013 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -def _GetJSONParseError(input_api, filename): - try: - contents = input_api.ReadFile(filename) - json_comment_eater = input_api.os_path.join( - input_api.PresubmitLocalPath(), - '..', '..', '..', '..', 'tools', - 'json_comment_eater', 'json_comment_eater.py') - process = input_api.subprocess.Popen( - [input_api.python_executable, json_comment_eater], - stdin=input_api.subprocess.PIPE, - stdout=input_api.subprocess.PIPE, - universal_newlines=True) - (nommed, _) = process.communicate(input=contents) - input_api.json.loads(nommed) - except ValueError as e: - return e - return None - - -def _GetIDLParseError(input_api, filename): - idl_schema = input_api.os_path.join( - input_api.PresubmitLocalPath(), - '..', '..', '..', '..', 'tools', - 'json_schema_compiler', 'idl_schema.py') - process = input_api.subprocess.Popen( - [input_api.python_executable, idl_schema, filename], - stdout=input_api.subprocess.PIPE, - stderr=input_api.subprocess.PIPE, - universal_newlines=True) - (_, error) = process.communicate() - return error or None - - -def _GetParseErrors(input_api, output_api): - # Run unit tests. - results = [] - if input_api.AffectedFiles( - file_filter=lambda f: 'PRESUBMIT' in f.LocalPath()): - results = input_api.canned_checks.RunUnitTestsInDirectory( - input_api, output_api, '.', whitelist=[r'^PRESUBMIT_test\.py$']) - - actions = { - '.idl': _GetIDLParseError, - '.json': _GetJSONParseError, - } - - def get_action(affected_file): - filename = affected_file.LocalPath() - return actions.get(input_api.os_path.splitext(filename)[1]) - - for affected_file in input_api.AffectedFiles( - file_filter= - lambda f: "test_presubmit" not in f.LocalPath() and get_action(f), - include_deletes=False): - parse_error = get_action(affected_file)(input_api, - affected_file.AbsoluteLocalPath()) - if parse_error: - results.append(output_api.PresubmitError('%s could not be parsed: %s' % - (affected_file.LocalPath(), parse_error))) - return results - - -def CheckChangeOnUpload(input_api, output_api): - return _GetParseErrors(input_api, output_api) - - -def CheckChangeOnCommit(input_api, output_api): - return _GetParseErrors(input_api, output_api) diff --git a/chrome/common/extensions/api/PRESUBMIT_test.py b/chrome/common/extensions/api/PRESUBMIT_test.py deleted file mode 100755 index 88d28e6..0000000 --- a/chrome/common/extensions/api/PRESUBMIT_test.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python -# Copyright 2013 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import glob -import json -import os -import subprocess -import sys -import unittest - -import PRESUBMIT - - -class MockInputApi(object): - def __init__(self): - self.json = json - self.os_path = os.path - self.subprocess = subprocess - self.python_executable = sys.executable - - def PresubmitLocalPath(self): - return os.path.dirname(__file__) - - def ReadFile(self, filename, mode='rU'): - with open(filename, mode=mode) as f: - return f.read() - - -class JSONParsingTest(unittest.TestCase): - def testSuccess(self): - input_api = MockInputApi() - filename = 'test_presubmit/valid_json.json' - self.assertEqual(None, - PRESUBMIT._GetJSONParseError(input_api, filename)) - - def testFailure(self): - input_api = MockInputApi() - expected_errors = [ - 'Expecting property name: line 8 column 3 (char 9)', - 'Invalid control character at: line 8 column 19 (char 25)', - 'Expecting property name: line 8 column 23 (char 29)', - 'Expecting , delimiter: line 8 column 12 (char 18)', - ] - actual_errors = [ - str(PRESUBMIT._GetJSONParseError(input_api, filename)) - for filename in sorted(glob.glob('test_presubmit/invalid_*.json')) - ] - self.assertEqual(expected_errors, actual_errors) - - -class IDLParsingTest(unittest.TestCase): - def testSuccess(self): - input_api = MockInputApi() - filename = 'test_presubmit/valid_idl_basics.idl' - self.assertEqual(None, - PRESUBMIT._GetIDLParseError(input_api, filename)) - - def testFailure(self): - input_api = MockInputApi() - expected_errors = [ - 'Unexpected "{" after keyword "dictionary".', - 'Unexpected symbol DOMString after symbol a.', - 'Unexpected symbol name2 after symbol name1.', - 'Trailing comma in block.', - 'Unexpected ";" after "(".', - 'Unexpected ")" after symbol long.', - 'Unexpected symbol Events after symbol interace.', - 'Did not process Interface Interface(NotEvent)', - 'Interface missing name.', - ] - actual_errors = [ - PRESUBMIT._GetIDLParseError(input_api, filename) - for filename in sorted(glob.glob('test_presubmit/invalid_*.idl')) - ] - for (expected_error, actual_error) in zip(expected_errors, actual_errors): - self.assertTrue(expected_error in actual_error) - - -if __name__ == "__main__": - unittest.main() diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_1.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_1.idl deleted file mode 100644 index 32a048e..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_1.idl +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Unexpected "{" after keyword "dictionary". - dictionary { - DOMString s; - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_2.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_2.idl deleted file mode 100644 index 72996ed3..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_2.idl +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Unexpected symbol DOMString after symbol a. - dictionary MissingSemicolon { - DOMString a - DOMString b; - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_3.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_3.idl deleted file mode 100644 index e70e095..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_3.idl +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Unexpected symbol name2 after symbol name1. - enum MissingComma { - name1 - name2 - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_4.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_4.idl deleted file mode 100644 index 28b42ff..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_4.idl +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Trailing comma in block. - enum TrailingComma { - name1, - name2, - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_5.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_5.idl deleted file mode 100644 index c3ed4f7..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_5.idl +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Unexpected ";" after "(". - callback Callback1 = void(; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_6.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_6.idl deleted file mode 100644 index 2b2ff68..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_6.idl +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Unexpected ")" after symbol long. - callback Callback1 = void(long ); -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_7.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_7.idl deleted file mode 100644 index da69c33..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_7.idl +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Unexpected symbol Events after symbol interace. - interace Events { - static void onFoo1(); - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_8.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_8.idl deleted file mode 100644 index 5cfc9ec..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_8.idl +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Did not process Interface Interface(NotEvent). - interface NotEvent { - static void onFoo1(); - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_idl_9.idl b/chrome/common/extensions/api/test_presubmit/invalid_idl_9.idl deleted file mode 100644 index 3f2905c..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_idl_9.idl +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid IDL file. - -namespace test { - // Interface missing name. - interface { - static void function1(); - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/invalid_json_1.json b/chrome/common/extensions/api/test_presubmit/invalid_json_1.json deleted file mode 100644 index fcaa875..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_json_1.json +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid JSON file. - -// Expecting property name: line 8 column 3 (char 9). -{ x } diff --git a/chrome/common/extensions/api/test_presubmit/invalid_json_2.json b/chrome/common/extensions/api/test_presubmit/invalid_json_2.json deleted file mode 100644 index d157424..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_json_2.json +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid JSON file. - -// Invalid control character at: line 8 column 19 (char 25). -{ "hello": "world } diff --git a/chrome/common/extensions/api/test_presubmit/invalid_json_3.json b/chrome/common/extensions/api/test_presubmit/invalid_json_3.json deleted file mode 100644 index 9dd3500..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_json_3.json +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid JSON file. - -// Expecting property name: line 8 column 23 (char 29). -{ "a": "b", "c": "d", } diff --git a/chrome/common/extensions/api/test_presubmit/invalid_json_4.json b/chrome/common/extensions/api/test_presubmit/invalid_json_4.json deleted file mode 100644 index af6a1a6..0000000 --- a/chrome/common/extensions/api/test_presubmit/invalid_json_4.json +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests an invalid JSON file. - -// Expecting , delimiter: line 8 column 12 (char 18). -{ "a": "b" "c": "d" } diff --git a/chrome/common/extensions/api/test_presubmit/valid_idl_basics.idl b/chrome/common/extensions/api/test_presubmit/valid_idl_basics.idl deleted file mode 100644 index d0071e1..0000000 --- a/chrome/common/extensions/api/test_presubmit/valid_idl_basics.idl +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests a valid IDL file. - -namespace idl_basics { - enum EnumType { - name1, - name2 - }; - - dictionary MyType1 { - DOMString a; - }; - - callback Callback1 = void(); - callback Callback2 = void(long x); - callback Callback3 = void(MyType1 arg); - callback Callback4 = void(EnumType type); - - interface Functions { - static void function1(); - static void function2(long x); - static void function3(MyType1 arg); - static void function4(Callback1 cb); - static void function5(Callback2 cb); - static void function6(Callback3 cb); - static void function7(Callback4 cb); - }; - - interface Events { - static void onFoo1(); - static void onFoo2(long x); - static void onFoo2(MyType1 arg); - static void onFoo3(EnumType type); - }; -}; diff --git a/chrome/common/extensions/api/test_presubmit/valid_json.json b/chrome/common/extensions/api/test_presubmit/valid_json.json deleted file mode 100644 index 615ea28..0000000 --- a/chrome/common/extensions/api/test_presubmit/valid_json.json +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Tests a valid IDL file. - -// This is a comment. -{ - "key1": ["value1", "value2"], - "key2": 3 // This is an inline comment. -} |