base_unittest.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. # Copyright (C) 2010 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  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.
  28. import logging
  29. import optparse
  30. import sys
  31. import tempfile
  32. import unittest2 as unittest
  33. from webkitpy.common.system.executive import Executive, ScriptError
  34. from webkitpy.common.system import executive_mock
  35. from webkitpy.common.system.filesystem_mock import MockFileSystem
  36. from webkitpy.common.system.outputcapture import OutputCapture
  37. from webkitpy.common.system.path import abspath_to_uri
  38. from webkitpy.thirdparty.mock import Mock
  39. from webkitpy.tool.mocktool import MockOptions
  40. from webkitpy.common.system.executive_mock import MockExecutive, MockExecutive2
  41. from webkitpy.common.system.systemhost_mock import MockSystemHost
  42. from webkitpy.port import Port, Driver, DriverOutput
  43. from webkitpy.port.test import add_unit_tests_to_mock_filesystem, TestPort
  44. class PortTest(unittest.TestCase):
  45. def make_port(self, executive=None, with_tests=False, port_name=None, **kwargs):
  46. host = MockSystemHost()
  47. if executive:
  48. host.executive = executive
  49. if with_tests:
  50. add_unit_tests_to_mock_filesystem(host.filesystem)
  51. return TestPort(host, **kwargs)
  52. return Port(host, port_name or 'baseport', **kwargs)
  53. def test_default_child_processes(self):
  54. port = self.make_port()
  55. self.assertIsNotNone(port.default_child_processes())
  56. def test_format_wdiff_output_as_html(self):
  57. output = "OUTPUT %s %s %s" % (Port._WDIFF_DEL, Port._WDIFF_ADD, Port._WDIFF_END)
  58. html = self.make_port()._format_wdiff_output_as_html(output)
  59. expected_html = "<head><style>.del { background: #faa; } .add { background: #afa; }</style></head><pre>OUTPUT <span class=del> <span class=add> </span></pre>"
  60. self.assertEqual(html, expected_html)
  61. def test_wdiff_command(self):
  62. port = self.make_port()
  63. port._path_to_wdiff = lambda: "/path/to/wdiff"
  64. command = port._wdiff_command("/actual/path", "/expected/path")
  65. expected_command = [
  66. "/path/to/wdiff",
  67. "--start-delete=##WDIFF_DEL##",
  68. "--end-delete=##WDIFF_END##",
  69. "--start-insert=##WDIFF_ADD##",
  70. "--end-insert=##WDIFF_END##",
  71. "/actual/path",
  72. "/expected/path",
  73. ]
  74. self.assertEqual(command, expected_command)
  75. def _file_with_contents(self, contents, encoding="utf-8"):
  76. new_file = tempfile.NamedTemporaryFile()
  77. new_file.write(contents.encode(encoding))
  78. new_file.flush()
  79. return new_file
  80. def test_pretty_patch_os_error(self):
  81. port = self.make_port(executive=executive_mock.MockExecutive2(exception=OSError))
  82. oc = OutputCapture()
  83. oc.capture_output()
  84. self.assertEqual(port.pretty_patch_text("patch.txt"),
  85. port._pretty_patch_error_html)
  86. # This tests repeated calls to make sure we cache the result.
  87. self.assertEqual(port.pretty_patch_text("patch.txt"),
  88. port._pretty_patch_error_html)
  89. oc.restore_output()
  90. def test_pretty_patch_script_error(self):
  91. # FIXME: This is some ugly white-box test hacking ...
  92. port = self.make_port(executive=executive_mock.MockExecutive2(exception=ScriptError))
  93. port._pretty_patch_available = True
  94. self.assertEqual(port.pretty_patch_text("patch.txt"),
  95. port._pretty_patch_error_html)
  96. # This tests repeated calls to make sure we cache the result.
  97. self.assertEqual(port.pretty_patch_text("patch.txt"),
  98. port._pretty_patch_error_html)
  99. def integration_test_run_wdiff(self):
  100. executive = Executive()
  101. # This may fail on some systems. We could ask the port
  102. # object for the wdiff path, but since we don't know what
  103. # port object to use, this is sufficient for now.
  104. try:
  105. wdiff_path = executive.run_command(["which", "wdiff"]).rstrip()
  106. except Exception, e:
  107. wdiff_path = None
  108. port = self.make_port(executive=executive)
  109. port._path_to_wdiff = lambda: wdiff_path
  110. if wdiff_path:
  111. # "with tempfile.NamedTemporaryFile() as actual" does not seem to work in Python 2.5
  112. actual = self._file_with_contents(u"foo")
  113. expected = self._file_with_contents(u"bar")
  114. wdiff = port._run_wdiff(actual.name, expected.name)
  115. expected_wdiff = "<head><style>.del { background: #faa; } .add { background: #afa; }</style></head><pre><span class=del>foo</span><span class=add>bar</span></pre>"
  116. self.assertEqual(wdiff, expected_wdiff)
  117. # Running the full wdiff_text method should give the same result.
  118. port._wdiff_available = True # In case it's somehow already disabled.
  119. wdiff = port.wdiff_text(actual.name, expected.name)
  120. self.assertEqual(wdiff, expected_wdiff)
  121. # wdiff should still be available after running wdiff_text with a valid diff.
  122. self.assertTrue(port._wdiff_available)
  123. actual.close()
  124. expected.close()
  125. # Bogus paths should raise a script error.
  126. self.assertRaises(ScriptError, port._run_wdiff, "/does/not/exist", "/does/not/exist2")
  127. self.assertRaises(ScriptError, port.wdiff_text, "/does/not/exist", "/does/not/exist2")
  128. # wdiff will still be available after running wdiff_text with invalid paths.
  129. self.assertTrue(port._wdiff_available)
  130. # If wdiff does not exist _run_wdiff should throw an OSError.
  131. port._path_to_wdiff = lambda: "/invalid/path/to/wdiff"
  132. self.assertRaises(OSError, port._run_wdiff, "foo", "bar")
  133. # wdiff_text should not throw an error if wdiff does not exist.
  134. self.assertEqual(port.wdiff_text("foo", "bar"), "")
  135. # However wdiff should not be available after running wdiff_text if wdiff is missing.
  136. self.assertFalse(port._wdiff_available)
  137. def test_wdiff_text(self):
  138. port = self.make_port()
  139. port.wdiff_available = lambda: True
  140. port._run_wdiff = lambda a, b: 'PASS'
  141. self.assertEqual('PASS', port.wdiff_text(None, None))
  142. def test_diff_text(self):
  143. port = self.make_port()
  144. # Make sure that we don't run into decoding exceptions when the
  145. # filenames are unicode, with regular or malformed input (expected or
  146. # actual input is always raw bytes, not unicode).
  147. port.diff_text('exp', 'act', 'exp.txt', 'act.txt')
  148. port.diff_text('exp', 'act', u'exp.txt', 'act.txt')
  149. port.diff_text('exp', 'act', u'a\xac\u1234\u20ac\U00008000', 'act.txt')
  150. port.diff_text('exp' + chr(255), 'act', 'exp.txt', 'act.txt')
  151. port.diff_text('exp' + chr(255), 'act', u'exp.txt', 'act.txt')
  152. # Though expected and actual files should always be read in with no
  153. # encoding (and be stored as str objects), test unicode inputs just to
  154. # be safe.
  155. port.diff_text(u'exp', 'act', 'exp.txt', 'act.txt')
  156. port.diff_text(
  157. u'a\xac\u1234\u20ac\U00008000', 'act', 'exp.txt', 'act.txt')
  158. # And make sure we actually get diff output.
  159. diff = port.diff_text('foo', 'bar', 'exp.txt', 'act.txt')
  160. self.assertIn('foo', diff)
  161. self.assertIn('bar', diff)
  162. self.assertIn('exp.txt', diff)
  163. self.assertIn('act.txt', diff)
  164. self.assertNotIn('nosuchthing', diff)
  165. def test_setup_test_run(self):
  166. port = self.make_port()
  167. # This routine is a no-op. We just test it for coverage.
  168. port.setup_test_run()
  169. def test_test_dirs(self):
  170. port = self.make_port()
  171. port.host.filesystem.write_text_file(port.layout_tests_dir() + '/canvas/test', '')
  172. port.host.filesystem.write_text_file(port.layout_tests_dir() + '/css2.1/test', '')
  173. dirs = port.test_dirs()
  174. self.assertIn('canvas', dirs)
  175. self.assertIn('css2.1', dirs)
  176. def test_skipped_perf_tests(self):
  177. port = self.make_port()
  178. def add_text_file(dirname, filename, content='some content'):
  179. dirname = port.host.filesystem.join(port.perf_tests_dir(), dirname)
  180. port.host.filesystem.maybe_make_directory(dirname)
  181. port.host.filesystem.write_text_file(port.host.filesystem.join(dirname, filename), content)
  182. add_text_file('inspector', 'test1.html')
  183. add_text_file('inspector', 'unsupported_test1.html')
  184. add_text_file('inspector', 'test2.html')
  185. add_text_file('inspector/resources', 'resource_file.html')
  186. add_text_file('unsupported', 'unsupported_test2.html')
  187. add_text_file('', 'Skipped', '\n'.join(['Layout', '', 'SunSpider', 'Supported/some-test.html']))
  188. self.assertEqual(port.skipped_perf_tests(), ['Layout', 'SunSpider', 'Supported/some-test.html'])
  189. def test_get_option__set(self):
  190. options, args = optparse.OptionParser().parse_args([])
  191. options.foo = 'bar'
  192. port = self.make_port(options=options)
  193. self.assertEqual(port.get_option('foo'), 'bar')
  194. def test_get_option__unset(self):
  195. port = self.make_port()
  196. self.assertIsNone(port.get_option('foo'))
  197. def test_get_option__default(self):
  198. port = self.make_port()
  199. self.assertEqual(port.get_option('foo', 'bar'), 'bar')
  200. def test_additional_platform_directory(self):
  201. port = self.make_port(port_name='foo')
  202. port.default_baseline_search_path = lambda: ['LayoutTests/platform/foo']
  203. layout_test_dir = port.layout_tests_dir()
  204. test_file = 'fast/test.html'
  205. # No additional platform directory
  206. self.assertEqual(
  207. port.expected_baselines(test_file, '.txt'),
  208. [(None, 'fast/test-expected.txt')])
  209. self.assertEqual(port.baseline_path(), 'LayoutTests/platform/foo')
  210. # Simple additional platform directory
  211. port._options.additional_platform_directory = ['/tmp/local-baselines']
  212. port._filesystem.write_text_file('/tmp/local-baselines/fast/test-expected.txt', 'foo')
  213. self.assertEqual(
  214. port.expected_baselines(test_file, '.txt'),
  215. [('/tmp/local-baselines', 'fast/test-expected.txt')])
  216. self.assertEqual(port.baseline_path(), '/tmp/local-baselines')
  217. # Multiple additional platform directories
  218. port._options.additional_platform_directory = ['/foo', '/tmp/local-baselines']
  219. self.assertEqual(
  220. port.expected_baselines(test_file, '.txt'),
  221. [('/tmp/local-baselines', 'fast/test-expected.txt')])
  222. self.assertEqual(port.baseline_path(), '/foo')
  223. def test_nonexistant_expectations(self):
  224. port = self.make_port(port_name='foo')
  225. port.expectations_files = lambda: ['/mock-checkout/LayoutTests/platform/exists/TestExpectations', '/mock-checkout/LayoutTests/platform/nonexistant/TestExpectations']
  226. port._filesystem.write_text_file('/mock-checkout/LayoutTests/platform/exists/TestExpectations', '')
  227. self.assertEqual('\n'.join(port.expectations_dict().keys()), '/mock-checkout/LayoutTests/platform/exists/TestExpectations')
  228. def test_additional_expectations(self):
  229. port = self.make_port(port_name='foo')
  230. port.port_name = 'foo'
  231. port._filesystem.write_text_file('/mock-checkout/LayoutTests/platform/foo/TestExpectations', '')
  232. port._filesystem.write_text_file(
  233. '/tmp/additional-expectations-1.txt', 'content1\n')
  234. port._filesystem.write_text_file(
  235. '/tmp/additional-expectations-2.txt', 'content2\n')
  236. self.assertEqual('\n'.join(port.expectations_dict().values()), '')
  237. port._options.additional_expectations = [
  238. '/tmp/additional-expectations-1.txt']
  239. self.assertEqual('\n'.join(port.expectations_dict().values()), '\ncontent1\n')
  240. port._options.additional_expectations = [
  241. '/tmp/nonexistent-file', '/tmp/additional-expectations-1.txt']
  242. self.assertEqual('\n'.join(port.expectations_dict().values()), '\ncontent1\n')
  243. port._options.additional_expectations = [
  244. '/tmp/additional-expectations-1.txt', '/tmp/additional-expectations-2.txt']
  245. self.assertEqual('\n'.join(port.expectations_dict().values()), '\ncontent1\n\ncontent2\n')
  246. def test_additional_env_var(self):
  247. port = self.make_port(options=optparse.Values({'additional_env_var': ['FOO=BAR', 'BAR=FOO']}))
  248. self.assertEqual(port.get_option('additional_env_var'), ['FOO=BAR', 'BAR=FOO'])
  249. environment = port.setup_environ_for_server()
  250. self.assertTrue(('FOO' in environment) & ('BAR' in environment))
  251. self.assertEqual(environment['FOO'], 'BAR')
  252. self.assertEqual(environment['BAR'], 'FOO')
  253. def test_uses_test_expectations_file(self):
  254. port = self.make_port(port_name='foo')
  255. port.port_name = 'foo'
  256. port.path_to_test_expectations_file = lambda: '/mock-results/TestExpectations'
  257. self.assertFalse(port.uses_test_expectations_file())
  258. port._filesystem = MockFileSystem({'/mock-results/TestExpectations': ''})
  259. self.assertTrue(port.uses_test_expectations_file())
  260. def test_find_no_paths_specified(self):
  261. port = self.make_port(with_tests=True)
  262. layout_tests_dir = port.layout_tests_dir()
  263. tests = port.tests([])
  264. self.assertNotEqual(len(tests), 0)
  265. def test_find_one_test(self):
  266. port = self.make_port(with_tests=True)
  267. tests = port.tests(['failures/expected/image.html'])
  268. self.assertEqual(len(tests), 1)
  269. def test_find_glob(self):
  270. port = self.make_port(with_tests=True)
  271. tests = port.tests(['failures/expected/im*'])
  272. self.assertEqual(len(tests), 2)
  273. def test_find_with_skipped_directories(self):
  274. port = self.make_port(with_tests=True)
  275. tests = port.tests(['userscripts'])
  276. self.assertNotIn('userscripts/resources/iframe.html', tests)
  277. def test_find_with_skipped_directories_2(self):
  278. port = self.make_port(with_tests=True)
  279. tests = port.tests(['userscripts/resources'])
  280. self.assertEqual(tests, [])
  281. def test_is_test_file(self):
  282. filesystem = MockFileSystem()
  283. self.assertTrue(Port._is_test_file(filesystem, '', 'foo.html'))
  284. self.assertTrue(Port._is_test_file(filesystem, '', 'foo.shtml'))
  285. self.assertTrue(Port._is_test_file(filesystem, '', 'foo.svg'))
  286. self.assertTrue(Port._is_test_file(filesystem, '', 'test-ref-test.html'))
  287. self.assertFalse(Port._is_test_file(filesystem, '', 'foo.png'))
  288. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected.html'))
  289. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected.svg'))
  290. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected.xht'))
  291. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected-mismatch.html'))
  292. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected-mismatch.svg'))
  293. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected-mismatch.xhtml'))
  294. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.html'))
  295. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.html'))
  296. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.xht'))
  297. self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.xhtml'))
  298. self.assertFalse(Port._is_test_file(filesystem, '', 'ref-foo.html'))
  299. self.assertFalse(Port._is_test_file(filesystem, '', 'notref-foo.xhr'))
  300. def test_is_reference_html_file(self):
  301. filesystem = MockFileSystem()
  302. self.assertTrue(Port.is_reference_html_file(filesystem, '', 'foo-expected.html'))
  303. self.assertTrue(Port.is_reference_html_file(filesystem, '', 'foo-expected-mismatch.xml'))
  304. self.assertTrue(Port.is_reference_html_file(filesystem, '', 'foo-ref.xhtml'))
  305. self.assertTrue(Port.is_reference_html_file(filesystem, '', 'foo-notref.svg'))
  306. self.assertFalse(Port.is_reference_html_file(filesystem, '', 'foo.html'))
  307. self.assertFalse(Port.is_reference_html_file(filesystem, '', 'foo-expected.txt'))
  308. self.assertFalse(Port.is_reference_html_file(filesystem, '', 'foo-expected.shtml'))
  309. self.assertFalse(Port.is_reference_html_file(filesystem, '', 'foo-expected.php'))
  310. self.assertFalse(Port.is_reference_html_file(filesystem, '', 'foo-expected.mht'))
  311. def test_parse_reftest_list(self):
  312. port = self.make_port(with_tests=True)
  313. port.host.filesystem.files['bar/reftest.list'] = "\n".join(["== test.html test-ref.html",
  314. "",
  315. "# some comment",
  316. "!= test-2.html test-notref.html # more comments",
  317. "== test-3.html test-ref.html",
  318. "== test-3.html test-ref2.html",
  319. "!= test-3.html test-notref.html"])
  320. reftest_list = Port._parse_reftest_list(port.host.filesystem, 'bar')
  321. self.assertEqual(reftest_list, {'bar/test.html': [('==', 'bar/test-ref.html')],
  322. 'bar/test-2.html': [('!=', 'bar/test-notref.html')],
  323. 'bar/test-3.html': [('==', 'bar/test-ref.html'), ('==', 'bar/test-ref2.html'), ('!=', 'bar/test-notref.html')]})
  324. def test_reference_files(self):
  325. port = self.make_port(with_tests=True)
  326. self.assertEqual(port.reference_files('passes/svgreftest.svg'), [('==', port.layout_tests_dir() + '/passes/svgreftest-expected.svg')])
  327. self.assertEqual(port.reference_files('passes/xhtreftest.svg'), [('==', port.layout_tests_dir() + '/passes/xhtreftest-expected.html')])
  328. self.assertEqual(port.reference_files('passes/phpreftest.php'), [('!=', port.layout_tests_dir() + '/passes/phpreftest-expected-mismatch.svg')])
  329. def test_operating_system(self):
  330. self.assertEqual('mac', self.make_port().operating_system())
  331. def test_http_server_supports_ipv6(self):
  332. port = self.make_port()
  333. self.assertTrue(port.http_server_supports_ipv6())
  334. port.host.platform.os_name = 'cygwin'
  335. self.assertFalse(port.http_server_supports_ipv6())
  336. port.host.platform.os_name = 'win'
  337. self.assertTrue(port.http_server_supports_ipv6())
  338. def test_check_httpd_success(self):
  339. port = self.make_port(executive=MockExecutive2())
  340. port._path_to_apache = lambda: '/usr/sbin/httpd'
  341. capture = OutputCapture()
  342. capture.capture_output()
  343. self.assertTrue(port.check_httpd())
  344. _, _, logs = capture.restore_output()
  345. self.assertEqual('', logs)
  346. def test_httpd_returns_error_code(self):
  347. port = self.make_port(executive=MockExecutive2(exit_code=1))
  348. port._path_to_apache = lambda: '/usr/sbin/httpd'
  349. capture = OutputCapture()
  350. capture.capture_output()
  351. self.assertFalse(port.check_httpd())
  352. _, _, logs = capture.restore_output()
  353. self.assertEqual('httpd seems broken. Cannot run http tests.\n', logs)
  354. def test_test_exists(self):
  355. port = self.make_port(with_tests=True)
  356. self.assertTrue(port.test_exists('passes'))
  357. self.assertTrue(port.test_exists('passes/text.html'))
  358. self.assertFalse(port.test_exists('passes/does_not_exist.html'))
  359. self.assertTrue(port.test_exists('virtual'))
  360. self.assertFalse(port.test_exists('virtual/does_not_exist.html'))
  361. self.assertTrue(port.test_exists('virtual/passes/text.html'))
  362. def test_test_isfile(self):
  363. port = self.make_port(with_tests=True)
  364. self.assertFalse(port.test_isfile('passes'))
  365. self.assertTrue(port.test_isfile('passes/text.html'))
  366. self.assertFalse(port.test_isfile('passes/does_not_exist.html'))
  367. self.assertFalse(port.test_isfile('virtual'))
  368. self.assertTrue(port.test_isfile('virtual/passes/text.html'))
  369. self.assertFalse(port.test_isfile('virtual/does_not_exist.html'))
  370. def test_test_isdir(self):
  371. port = self.make_port(with_tests=True)
  372. self.assertTrue(port.test_isdir('passes'))
  373. self.assertFalse(port.test_isdir('passes/text.html'))
  374. self.assertFalse(port.test_isdir('passes/does_not_exist.html'))
  375. self.assertFalse(port.test_isdir('passes/does_not_exist/'))
  376. self.assertTrue(port.test_isdir('virtual'))
  377. self.assertFalse(port.test_isdir('virtual/does_not_exist.html'))
  378. self.assertFalse(port.test_isdir('virtual/does_not_exist/'))
  379. self.assertFalse(port.test_isdir('virtual/passes/text.html'))
  380. def test_tests(self):
  381. port = self.make_port(with_tests=True)
  382. tests = port.tests([])
  383. self.assertIn('passes/text.html', tests)
  384. self.assertIn('virtual/passes/text.html', tests)
  385. tests = port.tests(['passes'])
  386. self.assertIn('passes/text.html', tests)
  387. self.assertIn('passes/passes/test-virtual-passes.html', tests)
  388. self.assertNotIn('virtual/passes/text.html', tests)
  389. tests = port.tests(['virtual/passes'])
  390. self.assertNotIn('passes/text.html', tests)
  391. self.assertIn('virtual/passes/test-virtual-passes.html', tests)
  392. self.assertIn('virtual/passes/passes/test-virtual-passes.html', tests)
  393. self.assertNotIn('virtual/passes/test-virtual-virtual/passes.html', tests)
  394. self.assertNotIn('virtual/passes/virtual/passes/test-virtual-passes.html', tests)
  395. def test_build_path(self):
  396. port = self.make_port(options=optparse.Values({'build_directory': '/my-build-directory/'}))
  397. self.assertEqual(port._build_path(), '/my-build-directory/Release')
  398. class NaturalCompareTest(unittest.TestCase):
  399. def setUp(self):
  400. self._port = TestPort(MockSystemHost())
  401. def assert_cmp(self, x, y, result):
  402. self.assertEqual(cmp(self._port._natural_sort_key(x), self._port._natural_sort_key(y)), result)
  403. def test_natural_compare(self):
  404. self.assert_cmp('a', 'a', 0)
  405. self.assert_cmp('ab', 'a', 1)
  406. self.assert_cmp('a', 'ab', -1)
  407. self.assert_cmp('', '', 0)
  408. self.assert_cmp('', 'ab', -1)
  409. self.assert_cmp('1', '2', -1)
  410. self.assert_cmp('2', '1', 1)
  411. self.assert_cmp('1', '10', -1)
  412. self.assert_cmp('2', '10', -1)
  413. self.assert_cmp('foo_1.html', 'foo_2.html', -1)
  414. self.assert_cmp('foo_1.1.html', 'foo_2.html', -1)
  415. self.assert_cmp('foo_1.html', 'foo_10.html', -1)
  416. self.assert_cmp('foo_2.html', 'foo_10.html', -1)
  417. self.assert_cmp('foo_23.html', 'foo_10.html', 1)
  418. self.assert_cmp('foo_23.html', 'foo_100.html', -1)
  419. class KeyCompareTest(unittest.TestCase):
  420. def setUp(self):
  421. self._port = TestPort(MockSystemHost())
  422. def assert_cmp(self, x, y, result):
  423. self.assertEqual(cmp(self._port.test_key(x), self._port.test_key(y)), result)
  424. def test_test_key(self):
  425. self.assert_cmp('/a', '/a', 0)
  426. self.assert_cmp('/a', '/b', -1)
  427. self.assert_cmp('/a2', '/a10', -1)
  428. self.assert_cmp('/a2/foo', '/a10/foo', -1)
  429. self.assert_cmp('/a/foo11', '/a/foo2', 1)
  430. self.assert_cmp('/ab', '/a/a/b', -1)
  431. self.assert_cmp('/a/a/b', '/ab', 1)
  432. self.assert_cmp('/foo-bar/baz', '/foo/baz', -1)