1d0825bca7fe65beaee391d30da42e937db621564Steve Block# Copyright (C) 2010 Google Inc. All rights reserved.
2d0825bca7fe65beaee391d30da42e937db621564Steve Block#
30bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# Redistribution and use in source and binary forms, with or without
40bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# modification, are permitted provided that the following conditions are
50bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# met:
60bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#
70bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#     * Redistributions of source code must retain the above copyright
80bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# notice, this list of conditions and the following disclaimer.
90bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#     * Redistributions in binary form must reproduce the above
100bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# copyright notice, this list of conditions and the following disclaimer
110bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# in the documentation and/or other materials provided with the
120bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# distribution.
130bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#     * Neither the name of Google Inc. nor the names of its
140bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# contributors may be used to endorse or promote products derived from
150bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# this software without specific prior written permission.
160bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch#
170bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
180bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
190bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
200bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
210bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
220bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
230bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
240bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
250bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
260bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
270bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
280bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
290bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdochimport unittest
300bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
31dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.common.system.outputcapture import OutputCapture
326c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsenfrom webkitpy.common.config.ports import WebKitPort
33e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarkefrom webkitpy.tool.mocktool import MockOptions, MockTool
34dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.tool.steps.update import Update
356c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsenfrom webkitpy.tool.steps.runtests import RunTests
36dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockfrom webkitpy.tool.steps.promptforbugortitle import PromptForBugOrTitle
37d0825bca7fe65beaee391d30da42e937db621564Steve Block
38d0825bca7fe65beaee391d30da42e937db621564Steve Block
39d0825bca7fe65beaee391d30da42e937db621564Steve Blockclass StepsTest(unittest.TestCase):
40a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    def _step_options(self):
41a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        options = MockOptions()
42a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        options.non_interactive = True
43a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        options.port = 'MOCK port'
44a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        options.quiet = True
45a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        options.test = True
46a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        return options
47a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
48d0825bca7fe65beaee391d30da42e937db621564Steve Block    def _run_step(self, step, tool=None, options=None, state=None):
49d0825bca7fe65beaee391d30da42e937db621564Steve Block        if not tool:
50dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block            tool = MockTool()
51d0825bca7fe65beaee391d30da42e937db621564Steve Block        if not options:
52a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch            options = self._step_options()
53d0825bca7fe65beaee391d30da42e937db621564Steve Block        if not state:
54d0825bca7fe65beaee391d30da42e937db621564Steve Block            state = {}
55d0825bca7fe65beaee391d30da42e937db621564Steve Block        step(tool, options).run(state)
56d0825bca7fe65beaee391d30da42e937db621564Steve Block
57d0825bca7fe65beaee391d30da42e937db621564Steve Block    def test_update_step(self):
58a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        tool = MockTool()
59a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        options = self._step_options()
60d0825bca7fe65beaee391d30da42e937db621564Steve Block        options.update = True
6121939df44de1705786c545cd1bf519d47250322dBen Murdoch        expected_stderr = "Updating working directory\n"
62a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        OutputCapture().assert_outputs(self, self._run_step, [Update, tool, options], expected_stderr=expected_stderr)
630bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
64d0825bca7fe65beaee391d30da42e937db621564Steve Block    def test_prompt_for_bug_or_title_step(self):
65dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block        tool = MockTool()
66d0825bca7fe65beaee391d30da42e937db621564Steve Block        tool.user.prompt = lambda message: 42
67d0825bca7fe65beaee391d30da42e937db621564Steve Block        self._run_step(PromptForBugOrTitle, tool=tool)
686c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen
692daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    def test_runtests_args(self):
70a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        mock_options = self._step_options()
716c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        step = RunTests(MockTool(log_executive=True), mock_options)
726c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        # FIXME: We shouldn't use a real port-object here, but there is too much to mock at the moment.
736c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        mock_port = WebKitPort()
746c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        mock_port.name = lambda: "Mac"
75a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        tool = MockTool(log_executive=True)
76a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        tool.port = lambda: mock_port
77a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        step = RunTests(tool, mock_options)
786c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        expected_stderr = """Running Python unit tests
79f05b935882198ccf7d81675736e3aeb089c5113aBen MurdochMOCK run_and_throw_if_fail: ['Tools/Scripts/test-webkitpy']
806c2af9490927c3c5959b5cb07461b646f8b32f6cKristian MonsenRunning Perl unit tests
81f05b935882198ccf7d81675736e3aeb089c5113aBen MurdochMOCK run_and_throw_if_fail: ['Tools/Scripts/test-webkitperl']
826c2af9490927c3c5959b5cb07461b646f8b32f6cKristian MonsenRunning JavaScriptCore tests
83f05b935882198ccf7d81675736e3aeb089c5113aBen MurdochMOCK run_and_throw_if_fail: ['Tools/Scripts/run-javascriptcore-tests']
846c2af9490927c3c5959b5cb07461b646f8b32f6cKristian MonsenRunning run-webkit-tests
852daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochMOCK run_and_throw_if_fail: ['Tools/Scripts/run-webkit-tests', '--no-new-test-results', '--no-launch-safari', '--exit-after-n-failures=10', '--wait-for-httpd', '--quiet']
866c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen"""
876c2af9490927c3c5959b5cb07461b646f8b32f6cKristian Monsen        OutputCapture().assert_outputs(self, step.run, [{}], expected_stderr=expected_stderr)
88