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.layout_tests.port.test import TestPort
34 from webkitpy.tool.commands.queries import *
35 from webkitpy.tool.mocktool import MockTool, MockOptions
38 class PrintExpectationsTest(unittest.TestCase):
39 def run_test(self, tests, expected_stdout, platform='test-win-xp', **args):
40 options = MockOptions(all=False, csv=False, full=False, platform=platform,
41 include_keyword=[], exclude_keyword=[], paths=False).update(**args)
43 tool.port_factory.all_port_names = lambda: TestPort.ALL_BASELINE_VARIANTS
44 command = PrintExpectations()
45 command.bind_to_tool(tool)
50 command.execute(options, tests, tool)
52 stdout, _, _ = oc.restore_output()
53 self.assertMultiLineEqual(stdout, expected_stdout)
56 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
57 ('// For test-win-xp\n'
58 'failures/expected/image.html [ ImageOnlyFailure ]\n'
59 'failures/expected/text.html [ Failure ]\n'))
61 def test_multiple(self):
62 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
63 ('// For test-win-win7\n'
64 'failures/expected/image.html [ ImageOnlyFailure ]\n'
65 'failures/expected/text.html [ Failure ]\n'
67 '// For test-win-xp\n'
68 'failures/expected/image.html [ ImageOnlyFailure ]\n'
69 'failures/expected/text.html [ Failure ]\n'),
70 platform='test-win-*')
73 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
74 ('// For test-win-xp\n'
75 'Bug(test) failures/expected/image.html [ ImageOnlyFailure ]\n'
76 'Bug(test) failures/expected/text.html [ Failure ]\n'),
79 def test_exclude(self):
80 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
81 ('// For test-win-xp\n'
82 'failures/expected/text.html [ Failure ]\n'),
83 exclude_keyword=['image'])
85 def test_include(self):
86 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
87 ('// For test-win-xp\n'
88 'failures/expected/image.html\n'),
89 include_keyword=['image'])
92 self.run_test(['failures/expected/text.html', 'failures/expected/image.html'],
93 ('test-win-xp,failures/expected/image.html,Bug(test),,IMAGE\n'
94 'test-win-xp,failures/expected/text.html,Bug(test),,FAIL\n'),
99 ('/mock-checkout/LayoutTests/TestExpectations\n'
100 'LayoutTests/platform/test/TestExpectations\n'
101 'LayoutTests/platform/test-win-xp/TestExpectations\n'),
104 class PrintBaselinesTest(unittest.TestCase):
107 self.tool = MockTool()
108 self.test_port = self.tool.port_factory.get('test-win-xp')
109 self.tool.port_factory.get = lambda port_name=None: self.test_port
110 self.tool.port_factory.all_port_names = lambda: TestPort.ALL_BASELINE_VARIANTS
114 self.restore_output()
116 def capture_output(self):
117 self.oc = OutputCapture()
118 self.oc.capture_output()
120 def restore_output(self):
121 stdout, stderr, logs = self.oc.restore_output()
123 return (stdout, stderr, logs)
125 def test_basic(self):
126 command = PrintBaselines()
127 command.bind_to_tool(self.tool)
128 self.capture_output()
129 command.execute(MockOptions(all=False, include_virtual_tests=False, csv=False, platform=None), ['passes/text.html'], self.tool)
130 stdout, _, _ = self.restore_output()
131 self.assertMultiLineEqual(stdout,
132 ('// For test-win-xp\n'
133 'passes/text-expected.png\n'
134 'passes/text-expected.txt\n'))
136 def test_multiple(self):
137 command = PrintBaselines()
138 command.bind_to_tool(self.tool)
139 self.capture_output()
140 command.execute(MockOptions(all=False, include_virtual_tests=False, csv=False, platform='test-win-*'), ['passes/text.html'], self.tool)
141 stdout, _, _ = self.restore_output()
142 self.assertMultiLineEqual(stdout,
143 ('// For test-win-win7\n'
144 'passes/text-expected.png\n'
145 'passes/text-expected.txt\n'
147 '// For test-win-xp\n'
148 'passes/text-expected.png\n'
149 'passes/text-expected.txt\n'))
152 command = PrintBaselines()
153 command.bind_to_tool(self.tool)
154 self.capture_output()
155 command.execute(MockOptions(all=False, platform='*xp', csv=True, include_virtual_tests=False), ['passes/text.html'], self.tool)
156 stdout, _, _ = self.restore_output()
157 self.assertMultiLineEqual(stdout,
158 ('test-win-xp,passes/text.html,None,png,passes/text-expected.png,None\n'
159 'test-win-xp,passes/text.html,None,txt,passes/text-expected.txt,None\n'))