2 # Copyright 2020 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 """Tests for protoc_wrapper."""
7 from __future__ import print_function
13 if sys.version_info.major == 2:
14 from StringIO import StringIO
17 from io import StringIO
18 from unittest import mock
23 class ProtocWrapperTest(unittest.TestCase):
24 @mock.patch('subprocess.call', return_value=0)
25 def test_minimal_arguments(self, mock_call):
27 ['--proto-in-dir', './', '--protoc', '/foo/protoc', 'foo.proto'])
28 mock_call.assert_called_once_with(
29 ['/foo/protoc', '--proto_path', '.', './foo.proto'])
31 @mock.patch('subprocess.call', return_value=0)
32 def test_kythe_no_out(self, mock_call):
34 '--proto-in-dir', './', '--enable-kythe-annotation', '--protoc',
35 '/foo/protoc', 'foo.proto'
37 mock_call.assert_called_once_with(
38 ['/foo/protoc', '--proto_path', '.', './foo.proto'])
40 @mock.patch('subprocess.call', return_value=0)
41 def test_kythe_cpp_out_no_options(self, mock_call):
43 '--proto-in-dir', './', '--enable-kythe-annotation', '--cc-out-dir',
44 './bar', '--protoc', '/foo/protoc', 'foo.proto'
46 mock_call.assert_called_once_with([
47 '/foo/protoc', '--cpp_out',
48 'annotate_headers,annotation_pragma_name=kythe_metadata,annotation_guard_name=KYTHE_IS_RUNNING:./bar',
49 '--proto_path', '.', './foo.proto'
52 @mock.patch('subprocess.call', return_value=0)
53 def test_kythe_cpp_out_with_options(self, mock_call):
55 '--proto-in-dir', './', '--enable-kythe-annotation', '--cc-options',
56 'foo=bar:', '--cc-out-dir', './bar', '--protoc', '/foo/protoc',
59 mock_call.assert_called_once_with([
60 '/foo/protoc', '--cpp_out',
61 'annotate_headers,annotation_pragma_name=kythe_metadata,annotation_guard_name=KYTHE_IS_RUNNING,foo=bar:./bar',
62 '--proto_path', '.', './foo.proto'
65 @mock.patch('subprocess.call', return_value=0)
66 def test_kythe_cpp_out_with_options_no_colon(self, mock_call):
68 '--proto-in-dir', './', '--enable-kythe-annotation', '--cc-options',
69 'foo=bar', '--cc-out-dir', './bar', '--protoc', '/foo/protoc',
72 mock_call.assert_called_once_with([
73 '/foo/protoc', '--cpp_out',
74 'annotate_headers,annotation_pragma_name=kythe_metadata,annotation_guard_name=KYTHE_IS_RUNNING,foo=bar:./bar',
75 '--proto_path', '.', './foo.proto'
78 @mock.patch('subprocess.call', return_value=0)
79 def test_cpp_out_with_options_no_colon(self, mock_call):
81 '--proto-in-dir', './', '--cc-options', 'foo=bar:', '--cc-out-dir',
82 './bar', '--protoc', '/foo/protoc', 'foo.proto'
84 mock_call.assert_called_once_with([
85 '/foo/protoc', '--cpp_out', 'foo=bar:./bar', '--proto_path', '.',
90 if __name__ == '__main__':
92 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)