Commit 3d1d61d6 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[tools] Handle string literal export names in testcase.py

JS now allows string literals as export names, which the current regexp
used to discover module files to push to Android for running tests does
not account for.

Bug: v8:10964
Bug: v8:11049
Change-Id: I6f26f44a98f1d2c91ad69b171faa3f201f8f1e7a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2492055
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70739}
parent 9b1f9e5d
......@@ -49,13 +49,21 @@ RESOURCES_PATTERN = re.compile(r"//\s+Resources:(.*)")
LOAD_PATTERN = re.compile(
r"(?:load|readbuffer|read)\((?:'|\")([^'\"]+)(?:'|\")\)")
# Pattern to auto-detect files to push on Android for statements like:
# import "path/to/file.js"
# import foobar from "path/to/file.js"
# import {foo, bar} from "path/to/file.js"
# export {"foo" as "bar"} from "path/to/file.js"
MODULE_FROM_RESOURCES_PATTERN = re.compile(
r"(?:import|export).*?from\s*\(?['\"]([^'\"]+)['\"]",
re.MULTILINE | re.DOTALL)
# Pattern to detect files to push on Android for statements like:
# import "path/to/file.js"
# import("module.mjs").catch()...
MODULE_RESOURCES_PATTERN = re.compile(
r"(?:import|export)(?:[^'\"]*?from)?\s*\(?['\"]([^'\"]+)['\"]",
MODULE_IMPORT_RESOURCES_PATTERN = re.compile(
r"import\s*\(?['\"]([^'\"]+)['\"]",
re.MULTILINE | re.DOTALL)
# Pattern to detect and strip test262 frontmatter from tests to prevent false
# positives for MODULE_RESOURCES_PATTERN above.
TEST262_FRONTMATTER_PATTERN = re.compile(r"/\*---.*?---\*/", re.DOTALL)
TIMEOUT_LONG = "long"
......@@ -402,17 +410,26 @@ class D8TestCase(TestCase):
result = []
def add_path(path):
result.append(os.path.abspath(path.replace('/', os.path.sep)))
def add_import_path(import_path):
add_path(os.path.normpath(
os.path.join(os.path.dirname(file), import_path)))
def strip_test262_frontmatter(input):
return TEST262_FRONTMATTER_PATTERN.sub('', input)
for match in RESOURCES_PATTERN.finditer(source):
# There are several resources per line. Relative to base dir.
for path in match.group(1).strip().split():
add_path(path)
# Strip test262 frontmatter before looking for load() and import/export
# statements.
source = strip_test262_frontmatter(source)
for match in LOAD_PATTERN.finditer(source):
# Files in load statements are relative to base dir.
add_path(match.group(1))
for match in MODULE_RESOURCES_PATTERN.finditer(source):
# Imported files are relative to the file importing them.
add_path(os.path.normpath(
os.path.join(os.path.dirname(file), match.group(1))))
# Imported files are relative to the file importing them.
for match in MODULE_FROM_RESOURCES_PATTERN.finditer(source):
add_import_path(match.group(1))
for match in MODULE_IMPORT_RESOURCES_PATTERN.finditer(source):
add_import_path(match.group(1))
return result
def _get_resources(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment