| OLD | NEW |
| 1 # Copyright (c) 2009 Google Inc. All rights reserved. | 1 # Copyright (c) 2009 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 import unittest | 29 import unittest |
| 30 | 30 |
| 31 from optparse import make_option | 31 from optparse import make_option |
| 32 | 32 |
| 33 from webkitpy.common.system.outputcapture import OutputCapture | 33 from webkitpy.common.system.outputcapture import OutputCapture |
| 34 from webkitpy.tool.multi_command_tool import MultiCommandTool | 34 from webkitpy.tool.multi_command_tool import MultiCommandTool |
| 35 from webkitpy.tool.commands import Command | 35 from webkitpy.tool.commands.command import Command |
| 36 | 36 |
| 37 | 37 |
| 38 class TrivialCommand(Command): | 38 class TrivialCommand(Command): |
| 39 name = "trivial" | 39 name = "trivial" |
| 40 help_text = "help text" | 40 help_text = "help text" |
| 41 long_help = "trivial command long help text" | 41 long_help = "trivial command long help text" |
| 42 show_in_main_help = True | 42 show_in_main_help = True |
| 43 | 43 |
| 44 def __init__(self, **kwargs): | 44 def __init__(self, **kwargs): |
| 45 super(TrivialCommand, self).__init__(**kwargs) | 45 super(TrivialCommand, self).__init__(**kwargs) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 full_args = [] | 79 full_args = [] |
| 80 full_args_expected = (None, []) | 80 full_args_expected = (None, []) |
| 81 self._assert_split(full_args, full_args_expected) | 81 self._assert_split(full_args, full_args_expected) |
| 82 | 82 |
| 83 full_args = ["command", "arg"] | 83 full_args = ["command", "arg"] |
| 84 full_args_expected = ("command", ["arg"]) | 84 full_args_expected = ("command", ["arg"]) |
| 85 self._assert_split(full_args, full_args_expected) | 85 self._assert_split(full_args, full_args_expected) |
| 86 | 86 |
| 87 def test_command_by_name(self): | 87 def test_command_by_name(self): |
| 88 # This also tests Command auto-discovery. | 88 tool = TrivialTool(commands=[TrivialCommand(), UncommonCommand()]) |
| 89 tool = TrivialTool() | |
| 90 self.assertEqual(tool.command_by_name("trivial").name, "trivial") | 89 self.assertEqual(tool.command_by_name("trivial").name, "trivial") |
| 91 self.assertIsNone(tool.command_by_name("bar")) | 90 self.assertIsNone(tool.command_by_name("bar")) |
| 92 | 91 |
| 93 def _assert_tool_main_outputs(self, tool, main_args, expected_stdout, expect
ed_stderr="", expected_exit_code=0): | 92 def _assert_tool_main_outputs(self, tool, main_args, expected_stdout, expect
ed_stderr="", expected_exit_code=0): |
| 94 exit_code = OutputCapture().assert_outputs( | 93 exit_code = OutputCapture().assert_outputs( |
| 95 self, tool.main, [main_args], expected_stdout=expected_stdout, expec
ted_stderr=expected_stderr) | 94 self, tool.main, [main_args], expected_stdout=expected_stdout, expec
ted_stderr=expected_stderr) |
| 96 self.assertEqual(exit_code, expected_exit_code) | 95 self.assertEqual(exit_code, expected_exit_code) |
| 97 | 96 |
| 98 def test_global_help(self): | 97 def test_global_help(self): |
| 99 tool = TrivialTool(commands=[TrivialCommand(), UncommonCommand()]) | 98 tool = TrivialTool(commands=[TrivialCommand(), UncommonCommand()]) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 tool = TrivialTool(commands=[command_with_options]) | 133 tool = TrivialTool(commands=[command_with_options]) |
| 135 expected_subcommand_help = """trivial [options] help text | 134 expected_subcommand_help = """trivial [options] help text |
| 136 | 135 |
| 137 trivial command long help text | 136 trivial command long help text |
| 138 | 137 |
| 139 Options: | 138 Options: |
| 140 --my_option=MY_OPTION | 139 --my_option=MY_OPTION |
| 141 | 140 |
| 142 """ | 141 """ |
| 143 self._assert_tool_main_outputs(tool, ["tool", "help", "trivial"], expect
ed_subcommand_help) | 142 self._assert_tool_main_outputs(tool, ["tool", "help", "trivial"], expect
ed_subcommand_help) |
| OLD | NEW |