15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Copyright (C) 2010 Google Inc. All rights reserved. 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# Redistribution and use in source and binary forms, with or without 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# modification, are permitted provided that the following conditions are 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# met: 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# * Redistributions of source code must retain the above copyright 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# notice, this list of conditions and the following disclaimer. 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# * Redistributions in binary form must reproduce the above 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# copyright notice, this list of conditions and the following disclaimer 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# in the documentation and/or other materials provided with the 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# distribution. 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# * Neither the name of Google Inc. nor the names of its 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# contributors may be used to endorse or promote products derived from 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# this software without specific prior written permission. 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)import logging 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)import optparse 315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)import sys 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)import tempfile 337757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdochimport webkitpy.thirdparty.unittest2 as unittest 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system.executive import Executive, ScriptError 365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system import executive_mock 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system.filesystem_mock import MockFileSystem 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system.outputcapture import OutputCapture 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system.path import abspath_to_uri 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.thirdparty.mock import Mock 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.tool.mocktool import MockOptions 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.common.system.systemhost_mock import MockSystemHost 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.layout_tests.port import Port, Driver, DriverOutput 461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)from webkitpy.layout_tests.port.base import VirtualTestSuite 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)from webkitpy.layout_tests.port.test import add_unit_tests_to_mock_filesystem, TestPort 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class PortTest(unittest.TestCase): 50926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) def make_port(self, executive=None, with_tests=False, port_name=None, **kwargs): 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) host = MockSystemHost() 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if executive: 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) host.executive = executive 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if with_tests: 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) add_unit_tests_to_mock_filesystem(host.filesystem) 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return TestPort(host, **kwargs) 57926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return Port(host, port_name or 'baseport', **kwargs) 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_default_child_processes(self): 605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 61926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIsNotNone(port.default_child_processes()) 625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_format_wdiff_output_as_html(self): 645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) output = "OUTPUT %s %s %s" % (Port._WDIFF_DEL, Port._WDIFF_ADD, Port._WDIFF_END) 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) html = self.make_port()._format_wdiff_output_as_html(output) 665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) expected_html = "<head><style>.del { background: #faa; } .add { background: #afa; }</style></head><pre>OUTPUT <span class=del> <span class=add> </span></pre>" 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(html, expected_html) 685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_wdiff_command(self): 705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._path_to_wdiff = lambda: "/path/to/wdiff" 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) command = port._wdiff_command("/actual/path", "/expected/path") 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) expected_command = [ 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "/path/to/wdiff", 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "--start-delete=##WDIFF_DEL##", 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "--end-delete=##WDIFF_END##", 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "--start-insert=##WDIFF_ADD##", 785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "--end-insert=##WDIFF_END##", 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "/actual/path", 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "/expected/path", 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ] 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(command, expected_command) 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def _file_with_contents(self, contents, encoding="utf-8"): 855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) new_file = tempfile.NamedTemporaryFile() 865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) new_file.write(contents.encode(encoding)) 875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) new_file.flush() 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return new_file 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_pretty_patch_os_error(self): 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(executive=executive_mock.MockExecutive2(exception=OSError)) 925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) oc = OutputCapture() 935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) oc.capture_output() 945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.pretty_patch_text("patch.txt"), 955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._pretty_patch_error_html) 965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # This tests repeated calls to make sure we cache the result. 985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.pretty_patch_text("patch.txt"), 995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._pretty_patch_error_html) 1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) oc.restore_output() 1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_pretty_patch_script_error(self): 1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # FIXME: This is some ugly white-box test hacking ... 1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(executive=executive_mock.MockExecutive2(exception=ScriptError)) 1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._pretty_patch_available = True 1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.pretty_patch_text("patch.txt"), 1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._pretty_patch_error_html) 1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # This tests repeated calls to make sure we cache the result. 1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.pretty_patch_text("patch.txt"), 1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._pretty_patch_error_html) 1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_wdiff_text(self): 1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.wdiff_available = lambda: True 1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._run_wdiff = lambda a, b: 'PASS' 1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual('PASS', port.wdiff_text(None, None)) 1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_diff_text(self): 1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # Make sure that we don't run into decoding exceptions when the 1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # filenames are unicode, with regular or malformed input (expected or 1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # actual input is always raw bytes, not unicode). 1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.diff_text('exp', 'act', 'exp.txt', 'act.txt') 1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.diff_text('exp', 'act', u'exp.txt', 'act.txt') 1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.diff_text('exp', 'act', u'a\xac\u1234\u20ac\U00008000', 'act.txt') 1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.diff_text('exp' + chr(255), 'act', 'exp.txt', 'act.txt') 1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.diff_text('exp' + chr(255), 'act', u'exp.txt', 'act.txt') 1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # Though expected and actual files should always be read in with no 1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # encoding (and be stored as str objects), test unicode inputs just to 1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # be safe. 1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.diff_text(u'exp', 'act', 'exp.txt', 'act.txt') 1355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.diff_text( 1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) u'a\xac\u1234\u20ac\U00008000', 'act', 'exp.txt', 'act.txt') 1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # And make sure we actually get diff output. 1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) diff = port.diff_text('foo', 'bar', 'exp.txt', 'act.txt') 140926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('foo', diff) 141926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('bar', diff) 142926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('exp.txt', diff) 143926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('act.txt', diff) 144926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertNotIn('nosuchthing', diff) 1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_setup_test_run(self): 1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 1485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # This routine is a no-op. We just test it for coverage. 1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.setup_test_run() 1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_test_dirs(self): 1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 1535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.host.filesystem.write_text_file(port.layout_tests_dir() + '/canvas/test', '') 1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.host.filesystem.write_text_file(port.layout_tests_dir() + '/css2.1/test', '') 1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) dirs = port.test_dirs() 156926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('canvas', dirs) 157926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('css2.1', dirs) 1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_skipped_perf_tests(self): 1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def add_text_file(dirname, filename, content='some content'): 1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) dirname = port.host.filesystem.join(port.perf_tests_dir(), dirname) 1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.host.filesystem.maybe_make_directory(dirname) 1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.host.filesystem.write_text_file(port.host.filesystem.join(dirname, filename), content) 1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) add_text_file('inspector', 'test1.html') 1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) add_text_file('inspector', 'unsupported_test1.html') 1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) add_text_file('inspector', 'test2.html') 1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) add_text_file('inspector/resources', 'resource_file.html') 1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) add_text_file('unsupported', 'unsupported_test2.html') 1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) add_text_file('', 'Skipped', '\n'.join(['Layout', '', 'SunSpider', 'Supported/some-test.html'])) 1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.skipped_perf_tests(), ['Layout', 'SunSpider', 'Supported/some-test.html']) 1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_get_option__set(self): 1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) options, args = optparse.OptionParser().parse_args([]) 1775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) options.foo = 'bar' 1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(options=options) 1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.get_option('foo'), 'bar') 1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_get_option__unset(self): 1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 183926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIsNone(port.get_option('foo')) 1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_get_option__default(self): 1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.get_option('foo', 'bar'), 'bar') 1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_additional_platform_directory(self): 1905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(port_name='foo') 1915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.default_baseline_search_path = lambda: ['LayoutTests/platform/foo'] 1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) layout_test_dir = port.layout_tests_dir() 1935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) test_file = 'fast/test.html' 1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # No additional platform directory 1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual( 1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.expected_baselines(test_file, '.txt'), 1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) [(None, 'fast/test-expected.txt')]) 1995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.baseline_path(), 'LayoutTests/platform/foo') 2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # Simple additional platform directory 2025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._options.additional_platform_directory = ['/tmp/local-baselines'] 2035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._filesystem.write_text_file('/tmp/local-baselines/fast/test-expected.txt', 'foo') 2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual( 2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.expected_baselines(test_file, '.txt'), 2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) [('/tmp/local-baselines', 'fast/test-expected.txt')]) 2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.baseline_path(), '/tmp/local-baselines') 2085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) # Multiple additional platform directories 2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._options.additional_platform_directory = ['/foo', '/tmp/local-baselines'] 2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual( 2125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.expected_baselines(test_file, '.txt'), 2135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) [('/tmp/local-baselines', 'fast/test-expected.txt')]) 2145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.baseline_path(), '/foo') 2155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_nonexistant_expectations(self): 2175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(port_name='foo') 2181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) port.expectations_files = lambda: ['/mock-checkout/third_party/WebKit/LayoutTests/platform/exists/TestExpectations', '/mock-checkout/third_party/WebKit/LayoutTests/platform/nonexistant/TestExpectations'] 2191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) port._filesystem.write_text_file('/mock-checkout/third_party/WebKit/LayoutTests/platform/exists/TestExpectations', '') 2201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual('\n'.join(port.expectations_dict().keys()), '/mock-checkout/third_party/WebKit/LayoutTests/platform/exists/TestExpectations') 2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_additional_expectations(self): 2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(port_name='foo') 2245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.port_name = 'foo' 2251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) port._filesystem.write_text_file('/mock-checkout/third_party/WebKit/LayoutTests/platform/foo/TestExpectations', '') 2265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._filesystem.write_text_file( 2275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) '/tmp/additional-expectations-1.txt', 'content1\n') 2285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._filesystem.write_text_file( 2295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) '/tmp/additional-expectations-2.txt', 'content2\n') 2305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 231926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertEqual('\n'.join(port.expectations_dict().values()), '') 2325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._options.additional_expectations = [ 2345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) '/tmp/additional-expectations-1.txt'] 2351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual('\n'.join(port.expectations_dict().values()), 'content1\n') 2365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._options.additional_expectations = [ 2385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) '/tmp/nonexistent-file', '/tmp/additional-expectations-1.txt'] 2391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual('\n'.join(port.expectations_dict().values()), 'content1\n') 2405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._options.additional_expectations = [ 2425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) '/tmp/additional-expectations-1.txt', '/tmp/additional-expectations-2.txt'] 2431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual('\n'.join(port.expectations_dict().values()), 'content1\n\ncontent2\n') 2445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_additional_env_var(self): 2465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(options=optparse.Values({'additional_env_var': ['FOO=BAR', 'BAR=FOO']})) 2475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.get_option('additional_env_var'), ['FOO=BAR', 'BAR=FOO']) 2485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) environment = port.setup_environ_for_server() 2495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(('FOO' in environment) & ('BAR' in environment)) 2505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(environment['FOO'], 'BAR') 2515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(environment['BAR'], 'FOO') 2525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_find_no_paths_specified(self): 2545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 2555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) layout_tests_dir = port.layout_tests_dir() 2565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests([]) 2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertNotEqual(len(tests), 0) 2585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_find_one_test(self): 2605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 2615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests(['failures/expected/image.html']) 2625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(len(tests), 1) 2635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_find_glob(self): 2655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 2665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests(['failures/expected/im*']) 2675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(len(tests), 2) 2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_find_with_skipped_directories(self): 2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests(['userscripts']) 272926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertNotIn('userscripts/resources/iframe.html', tests) 2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_find_with_skipped_directories_2(self): 2755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 2765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests(['userscripts/resources']) 277926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertEqual(tests, []) 2785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_is_test_file(self): 2805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) filesystem = MockFileSystem() 28153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertTrue(Port.is_test_file(filesystem, '', 'foo.html')) 28253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertTrue(Port.is_test_file(filesystem, '', 'foo.svg')) 28353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertTrue(Port.is_test_file(filesystem, '', 'test-ref-test.html')) 28453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo.png')) 28553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-expected.html')) 28653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-expected.svg')) 28753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-expected.xht')) 28853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-expected-mismatch.html')) 28953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-expected-mismatch.svg')) 29053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-expected-mismatch.xhtml')) 29153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-ref.html')) 29253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-notref.html')) 29353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-notref.xht')) 29453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'foo-ref.xhtml')) 29553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'ref-foo.html')) 29653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) self.assertFalse(Port.is_test_file(filesystem, '', 'notref-foo.xhr')) 2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_parse_reftest_list(self): 2995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.host.filesystem.files['bar/reftest.list'] = "\n".join(["== test.html test-ref.html", 3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "", 3025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "# some comment", 3035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "!= test-2.html test-notref.html # more comments", 3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "== test-3.html test-ref.html", 3055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "== test-3.html test-ref2.html", 3065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) "!= test-3.html test-notref.html"]) 3075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) reftest_list = Port._parse_reftest_list(port.host.filesystem, 'bar') 3095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(reftest_list, {'bar/test.html': [('==', 'bar/test-ref.html')], 3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 'bar/test-2.html': [('!=', 'bar/test-notref.html')], 3115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 'bar/test-3.html': [('==', 'bar/test-ref.html'), ('==', 'bar/test-ref2.html'), ('!=', 'bar/test-notref.html')]}) 3125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_reference_files(self): 3145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 3155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.reference_files('passes/svgreftest.svg'), [('==', port.layout_tests_dir() + '/passes/svgreftest-expected.svg')]) 3165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.reference_files('passes/xhtreftest.svg'), [('==', port.layout_tests_dir() + '/passes/xhtreftest-expected.html')]) 3175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.reference_files('passes/phpreftest.php'), [('!=', port.layout_tests_dir() + '/passes/phpreftest-expected-mismatch.svg')]) 3185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_operating_system(self): 3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual('mac', self.make_port().operating_system()) 3215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_http_server_supports_ipv6(self): 3235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 3245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.http_server_supports_ipv6()) 3255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.host.platform.os_name = 'cygwin' 3265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.http_server_supports_ipv6()) 3275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port.host.platform.os_name = 'win' 3285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.http_server_supports_ipv6()) 3295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_check_httpd_success(self): 3315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(executive=MockExecutive2()) 3325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._path_to_apache = lambda: '/usr/sbin/httpd' 3335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) capture = OutputCapture() 3345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) capture.capture_output() 3355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.check_httpd()) 3365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) _, _, logs = capture.restore_output() 3375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual('', logs) 3385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_httpd_returns_error_code(self): 3405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(executive=MockExecutive2(exit_code=1)) 3415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port._path_to_apache = lambda: '/usr/sbin/httpd' 3425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) capture = OutputCapture() 3435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) capture.capture_output() 3445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.check_httpd()) 3455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) _, _, logs = capture.restore_output() 3465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual('httpd seems broken. Cannot run http tests.\n', logs) 3475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_test_exists(self): 3495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 3505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_exists('passes')) 3515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_exists('passes/text.html')) 3525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_exists('passes/does_not_exist.html')) 3535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_exists('virtual')) 3555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_exists('virtual/does_not_exist.html')) 3565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_exists('virtual/passes/text.html')) 3575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_test_isfile(self): 3595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 3605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isfile('passes')) 3615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_isfile('passes/text.html')) 3625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isfile('passes/does_not_exist.html')) 3635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isfile('virtual')) 3655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_isfile('virtual/passes/text.html')) 3665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isfile('virtual/does_not_exist.html')) 3675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_test_isdir(self): 3695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 3705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_isdir('passes')) 3715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isdir('passes/text.html')) 3725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isdir('passes/does_not_exist.html')) 3735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isdir('passes/does_not_exist/')) 3745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertTrue(port.test_isdir('virtual')) 3765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isdir('virtual/does_not_exist.html')) 3775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isdir('virtual/does_not_exist/')) 3785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertFalse(port.test_isdir('virtual/passes/text.html')) 3795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_tests(self): 3815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(with_tests=True) 3825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests([]) 383926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('passes/text.html', tests) 384926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('virtual/passes/text.html', tests) 3855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests(['passes']) 387926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('passes/text.html', tests) 388926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('passes/passes/test-virtual-passes.html', tests) 389926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertNotIn('virtual/passes/text.html', tests) 3905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) tests = port.tests(['virtual/passes']) 392926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertNotIn('passes/text.html', tests) 393926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('virtual/passes/test-virtual-passes.html', tests) 394926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertIn('virtual/passes/passes/test-virtual-passes.html', tests) 395926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertNotIn('virtual/passes/test-virtual-virtual/passes.html', tests) 396926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertNotIn('virtual/passes/virtual/passes/test-virtual-passes.html', tests) 3975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_build_path(self): 3995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port(options=optparse.Values({'build_directory': '/my-build-directory/'})) 4005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port._build_path(), '/my-build-directory/Release') 4015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) def test_dont_require_http_server(self): 4035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) port = self.make_port() 4045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) self.assertEqual(port.requires_http_server(), False) 4055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 406926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 407926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)class NaturalCompareTest(unittest.TestCase): 408926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) def setUp(self): 409926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self._port = TestPort(MockSystemHost()) 410926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 411926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) def assert_cmp(self, x, y, result): 412926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertEqual(cmp(self._port._natural_sort_key(x), self._port._natural_sort_key(y)), result) 413926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 414926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) def test_natural_compare(self): 415926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('a', 'a', 0) 416926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('ab', 'a', 1) 417926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('a', 'ab', -1) 418926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('', '', 0) 419926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('', 'ab', -1) 420926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('1', '2', -1) 421926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('2', '1', 1) 422926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('1', '10', -1) 423926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('2', '10', -1) 424926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('foo_1.html', 'foo_2.html', -1) 425926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('foo_1.1.html', 'foo_2.html', -1) 426926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('foo_1.html', 'foo_10.html', -1) 427926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('foo_2.html', 'foo_10.html', -1) 428926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('foo_23.html', 'foo_10.html', 1) 429926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('foo_23.html', 'foo_100.html', -1) 430926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 431926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 432926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)class KeyCompareTest(unittest.TestCase): 433926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) def setUp(self): 434926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self._port = TestPort(MockSystemHost()) 435926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 436926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) def assert_cmp(self, x, y, result): 437926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assertEqual(cmp(self._port.test_key(x), self._port.test_key(y)), result) 438926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 439926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) def test_test_key(self): 440926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/a', '/a', 0) 441926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/a', '/b', -1) 442926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/a2', '/a10', -1) 443926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/a2/foo', '/a10/foo', -1) 444926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/a/foo11', '/a/foo2', 1) 445926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/ab', '/a/a/b', -1) 446926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/a/a/b', '/ab', 1) 447926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) self.assert_cmp('/foo-bar/baz', '/foo/baz', -1) 4481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 4491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 4501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class VirtualTestSuiteTest(unittest.TestCase): 4511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) def test_basic(self): 4521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) suite = VirtualTestSuite('suite', 'base/foo', ['--args']) 4531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual(suite.name, 'virtual/suite/base/foo') 4541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual(suite.base, 'base/foo') 4551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual(suite.args, ['--args']) 4561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 4571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) def test_no_slash(self): 4581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) suite = VirtualTestSuite('suite/bar', 'base/foo', ['--args']) 4591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertFalse(hasattr(suite, 'name')) 4601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertFalse(hasattr(suite, 'base')) 4611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertFalse(hasattr(suite, 'args')) 4621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 4631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) def test_legacy(self): 4641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) suite = VirtualTestSuite('suite/bar', 'base/foo', ['--args'], use_legacy_naming=True) 4651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual(suite.name, 'virtual/suite/bar') 4661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual(suite.base, 'base/foo') 4671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) self.assertEqual(suite.args, ['--args']) 468