| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """This module is used to find all of the layout test files used by Chromium | |
| 7 (across all platforms). It exposes one public function - GatherTestFiles() - | |
| 8 which takes an optional list of paths. If a list is passed in, the returned | |
| 9 list of test files is constrained to those found under the paths passed in, | |
| 10 i.e. calling GatherTestFiles(["LayoutTests/fast"]) will only return files | |
| 11 under that directory.""" | |
| 12 | |
| 13 import glob | |
| 14 import os | |
| 15 import path_utils | |
| 16 | |
| 17 # When collecting test cases, we include any file with these extensions. | |
| 18 _supported_file_extensions = set(['.html', '.shtml', '.xml', '.xhtml', '.pl', | |
| 19 '.php', '.svg']) | |
| 20 # When collecting test cases, skip these directories | |
| 21 _skipped_directories = set(['.svn', '_svn', 'resources', 'script-tests']) | |
| 22 | |
| 23 | |
| 24 def GatherTestFiles(paths): | |
| 25 """Generate a set of test files and return them. | |
| 26 | |
| 27 Args: | |
| 28 paths: a list of command line paths relative to the webkit/tests | |
| 29 directory. glob patterns are ok. | |
| 30 """ | |
| 31 paths_to_walk = set() | |
| 32 # if paths is empty, provide a pre-defined list. | |
| 33 if paths: | |
| 34 for path in paths: | |
| 35 # If there's an * in the name, assume it's a glob pattern. | |
| 36 path = os.path.join(path_utils.LayoutTestsDir(), path) | |
| 37 if path.find('*') > -1: | |
| 38 filenames = glob.glob(path) | |
| 39 paths_to_walk.update(filenames) | |
| 40 else: | |
| 41 paths_to_walk.add(path) | |
| 42 else: | |
| 43 paths_to_walk.add(path_utils.LayoutTestsDir()) | |
| 44 | |
| 45 # Now walk all the paths passed in on the command line and get filenames | |
| 46 test_files = set() | |
| 47 for path in paths_to_walk: | |
| 48 if os.path.isfile(path) and _HasSupportedExtension(path): | |
| 49 test_files.add(os.path.normpath(path)) | |
| 50 continue | |
| 51 | |
| 52 for root, dirs, files in os.walk(path): | |
| 53 # don't walk skipped directories and sub directories | |
| 54 if os.path.basename(root) in _skipped_directories: | |
| 55 del dirs[:] | |
| 56 continue | |
| 57 | |
| 58 for filename in files: | |
| 59 if _HasSupportedExtension(filename): | |
| 60 filename = os.path.join(root, filename) | |
| 61 filename = os.path.normpath(filename) | |
| 62 test_files.add(filename) | |
| 63 | |
| 64 return test_files | |
| 65 | |
| 66 | |
| 67 def _HasSupportedExtension(filename): | |
| 68 """Return true if filename is one of the file extensions we want to run a | |
| 69 test on.""" | |
| 70 extension = os.path.splitext(filename)[1] | |
| 71 return extension in _supported_file_extensions | |
| OLD | NEW |