self.ref_doc = None
self.load_file(filename)
- def load_file(self, filename):
+ def load_file(self, filename, is_ref=False):
if self.filesystem.isfile(filename):
try:
- self.test_doc = Parser(self.filesystem.read_binary_file(filename))
+ doc = Parser(self.filesystem.read_binary_file(filename))
except:
# FIXME: Figure out what to do if we can't parse the file.
_log.error("Failed to parse %s", filename)
- self.test_doc is None
+ doc = None
else:
if self.filesystem.isdir(filename):
# FIXME: Figure out what is triggering this and what to do about it.
_log.error("Trying to load %s, which is a directory", filename)
- self.test_doc = None
- self.ref_doc = None
+ doc = None
+
+ if is_ref:
+ self.ref_doc = doc
+ else:
+ self.test_doc = doc
def analyze_test(self, test_contents=None, ref_contents=None):
""" Analyzes a file to determine if it's a test, what type of test, and what reference or support files it requires. Returns all of the test info """
self.ref_doc = Parser(ref_contents)
# First check if it's a reftest
-
matches = self.reference_links_of_type('match') + self.reference_links_of_type('mismatch')
if matches:
if len(matches) > 1:
return None
if self.ref_doc is None:
- self.ref_doc = self.load_file(ref_file)
+ self.load_file(ref_file, True)
test_info = {'test': self.filename, 'reference': ref_file}
- # If the ref file path is relative, we need to check it for
- # relative paths also because when it lands in WebKit, it will be
- # moved down into the test dir.
- #
- # Note: The test files themselves are not checked for support files
- # outside their directories as the convention in the CSSWG is to
- # put all support files in the same dir or subdir as the test.
- #
- # All non-test files in the test's directory tree are normally
- # copied as part of the import as they are assumed to be required
- # support files.
- #
- # *But*, there is exactly one case in the entire css2.1 suite where
- # a test depends on a file that lives in a different directory,
- # which depends on another file that lives outside of its
- # directory. This code covers that case :)
- if matches[0]['href'].startswith('..'):
- support_files = self.support_files(self.ref_doc)
- test_info['refsupport'] = support_files
+ # If the ref file does not live in the same directory as the test file, check it for support files
+ test_info['reference_support_info'] = {}
+ if self.filesystem.dirname(ref_file) != self.filesystem.dirname(self.filename):
+ reference_support_files = self.support_files(self.ref_doc)
+ if len(reference_support_files) > 0:
+ reference_relpath = self.filesystem.relpath(self.filesystem.dirname(self.filename), self.filesystem.dirname(ref_file)) + self.filesystem.sep
+ test_info['reference_support_info'] = {'reference_relpath': reference_relpath, 'files': reference_support_files}
elif self.is_jstest():
test_info = {'test': self.filename, 'jstest': True}
return bool(self.test_doc.find(src=re.compile('[\'\"/]?/resources/testharness')))
def support_files(self, doc):
- """ Searches the file for all paths specified in url()'s, href or src attributes."""
+ """ Searches the file for all paths specified in url()'s or src attributes."""
support_files = []
if doc is None:
paths = src_paths + href_paths + urls
for path in paths:
if not(path.startswith('http:')) and not(path.startswith('mailto:')):
- support_files.append(path)
+ uri_scheme_pattern = re.compile(r"[A-Za-z][A-Za-z+.-]*:")
+ if not uri_scheme_pattern.match(path):
+ support_files.append(path)
return support_files