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 29 import sys 30 import unittest 31 32 from webkitpy.layout_tests.port import test 33 import test_files 34 35 class TestFilesTest(unittest.TestCase): 36 def test_find_no_paths_specified(self): 37 port = test.TestPort() 38 layout_tests_dir = port.layout_tests_dir() 39 tests = test_files.find(port, []) 40 self.assertNotEqual(len(tests), 0) 41 42 def test_find_one_test(self): 43 port = test.TestPort() 44 tests = test_files.find(port, ['failures/expected/image.html']) 45 self.assertEqual(len(tests), 1) 46 47 def test_find_glob(self): 48 port = test.TestPort() 49 tests = test_files.find(port, ['failures/expected/im*']) 50 self.assertEqual(len(tests), 2) 51 52 def test_find_with_skipped_directories(self): 53 port = test.TestPort() 54 tests = port.tests('userscripts') 55 self.assertTrue('userscripts/resources/iframe.html' not in tests) 56 57 def test_find_with_skipped_directories_2(self): 58 port = test.TestPort() 59 tests = test_files.find(port, ['userscripts/resources']) 60 self.assertEqual(tests, set([])) 61 62 def test_is_test_file(self): 63 port = test.TestPort() 64 fs = port._filesystem 65 self.assertTrue(test_files._is_test_file(fs, '', 'foo.html')) 66 self.assertTrue(test_files._is_test_file(fs, '', 'foo.shtml')) 67 self.assertFalse(test_files._is_test_file(fs, '', 'foo.png')) 68 self.assertFalse(test_files._is_test_file(fs, '', 'foo-expected.html')) 69 self.assertFalse(test_files._is_test_file(fs, '', 'foo-expected-mismatch.html')) 70 71 72 class MockWinFileSystem(object): 73 def join(self, *paths): 74 return '\\'.join(paths) 75 76 def normpath(self, path): 77 return path.replace('/', '\\') 78 79 80 class TestWinNormalize(unittest.TestCase): 81 def assert_filesystem_normalizes(self, filesystem): 82 self.assertEquals(test_files.normalize(filesystem, "c:\\foo", 83 ['fast/html', 'fast/canvas/*', 'compositing/foo.html']), 84 ['c:\\foo\\fast\html', 'c:\\foo\\fast\canvas\*', 'c:\\foo\compositing\\foo.html']) 85 86 def test_mocked_win(self): 87 # This tests test_files.normalize, using portable behavior emulating 88 # what we think Windows is supposed to do. This test will run on all 89 # platforms. 90 self.assert_filesystem_normalizes(MockWinFileSystem()) 91 92 def test_win(self): 93 # This tests the actual windows platform, to ensure we get the same 94 # results that we get in test_mocked_win(). 95 if sys.platform != 'win': 96 return 97 self.assert_filesystem_normalizes(FileSystem()) 98 99 100 if __name__ == '__main__': 101 unittest.main() 102