1 # Copyright (C) 2009 Google Inc. All rights reserved.
2 # Copyright (C) 2012 Intel Corporation. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 from webkitpy.common.system.outputcapture import OutputCapture
33 from webkitpy.common.system.outputcapture import OutputCapture
34 from webkitpy.thirdparty.mock import Mock
35 from webkitpy.layout_tests.port.test import TestPort
36 from webkitpy.tool.commands.commandtest import CommandsTest
37 from webkitpy.tool.commands.queries import *
38 from webkitpy.tool.mocktool import MockTool, MockOptions
41 class PrintExpectationsTest(unittest.TestCase):
42 def run_test(self, tests, expected_stdout, platform='test-win-xp', **args):
43 options = MockOptions(all=False, csv=False, full=False, platform=platform,
44 include_keyword=[], exclude_keyword=[], paths=False).update(**args)
46 tool.port_factory.all_port_names = lambda: TestPort.ALL_BASELINE_VARIANTS
47 command = PrintExpectations()
48 command.bind_to_tool(tool)
53 command.execute(options, tests, tool)
55 stdout, _, _ = oc.restore_output()
56 self.assertMultiLineEqual(stdout, expected_stdout)
59 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
60 ('// For test-win-xp\n'
61 'failures/expected/image.html [ ImageOnlyFailure ]\n'
62 'failures/expected/text.html [ Failure ]\n'))
64 def test_multiple(self):
65 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
66 ('// For test-win-win7\n'
67 'failures/expected/image.html [ ImageOnlyFailure ]\n'
68 'failures/expected/text.html [ Failure ]\n'
70 '// For test-win-xp\n'
71 'failures/expected/image.html [ ImageOnlyFailure ]\n'
72 'failures/expected/text.html [ Failure ]\n'),
73 platform='test-win-*')
76 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
77 ('// For test-win-xp\n'
78 'Bug(test) failures/expected/image.html [ ImageOnlyFailure ]\n'
79 'Bug(test) failures/expected/text.html [ Failure ]\n'),
82 def test_exclude(self):
83 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
84 ('// For test-win-xp\n'
85 'failures/expected/text.html [ Failure ]\n'),
86 exclude_keyword=['image'])
88 def test_include(self):
89 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
90 ('// For test-win-xp\n'
91 'failures/expected/image.html\n'),
92 include_keyword=['image'])
95 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
96 ('test-win-xp,failures/expected/image.html,Bug(test),,IMAGE\n'
97 'test-win-xp,failures/expected/text.html,Bug(test),,FAIL\n'),
100 def test_paths(self):
102 ('/mock-checkout/LayoutTests/TestExpectations\n'
103 'LayoutTests/platform/test/TestExpectations\n'
104 'LayoutTests/platform/test-win-xp/TestExpectations\n'),
107 class PrintBaselinesTest(unittest.TestCase):
110 self.tool = MockTool()
111 self.test_port = self.tool.port_factory.get('test-win-xp')
112 self.tool.port_factory.get = lambda port_name=None: self.test_port
113 self.tool.port_factory.all_port_names = lambda: TestPort.ALL_BASELINE_VARIANTS
117 self.restore_output()
119 def capture_output(self):
120 self.oc = OutputCapture()
121 self.oc.capture_output()
123 def restore_output(self):
124 stdout, stderr, logs = self.oc.restore_output()
126 return (stdout, stderr, logs)
128 def test_basic(self):
129 command = PrintBaselines()
130 command.bind_to_tool(self.tool)
131 self.capture_output()
132 command.execute(MockOptions(all=False, include_virtual_tests=False, csv=False, platform=None), ['passes/text.html'], self.tool)
133 stdout, _, _ = self.restore_output()
134 self.assertMultiLineEqual(stdout,
135 ('// For test-win-xp\n'
136 'passes/text-expected.png\n'
137 'passes/text-expected.txt\n'))
139 def test_multiple(self):
140 command = PrintBaselines()
141 command.bind_to_tool(self.tool)
142 self.capture_output()
143 command.execute(MockOptions(all=False, include_virtual_tests=False, csv=False, platform='test-win-*'), ['passes/text.html'], self.tool)
144 stdout, _, _ = self.restore_output()
145 self.assertMultiLineEqual(stdout,
146 ('// For test-win-win7\n'
147 'passes/text-expected.png\n'
148 'passes/text-expected.txt\n'
150 '// For test-win-xp\n'
151 'passes/text-expected.png\n'
152 'passes/text-expected.txt\n'))
155 command = PrintBaselines()
156 command.bind_to_tool(self.tool)
157 self.capture_output()
158 command.execute(MockOptions(all=False, platform='*xp', csv=True, include_virtual_tests=False), ['passes/text.html'], self.tool)
159 stdout, _, _ = self.restore_output()
160 self.assertMultiLineEqual(stdout,
161 ('test-win-xp,passes/text.html,None,png,passes/text-expected.png,None\n'
162 'test-win-xp,passes/text.html,None,txt,passes/text-expected.txt,None\n'))