Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: test/preparser/testcfg.py

Issue 7061008: Create template system for strict-mode tests. (Closed)
Patch Set: Remove debug print. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/preparser/strict-yield-var.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/preparser/testcfg.py
diff --git a/test/preparser/testcfg.py b/test/preparser/testcfg.py
index afe3d7d1353f4c709ebee10bab149a11c64666b2..e389e11db50ed4ff42fef294cc2aeee8bef2d255 100644
--- a/test/preparser/testcfg.py
+++ b/test/preparser/testcfg.py
@@ -34,11 +34,12 @@ import re
class PreparserTestCase(test.TestCase):
- def __init__(self, root, path, executable, mode, throws, context):
+ def __init__(self, root, path, executable, mode, throws, context, source):
super(PreparserTestCase, self).__init__(context, path, mode)
self.executable = executable
self.root = root
self.throws = throws
+ self.source = source
def GetLabel(self):
return "%s %s %s" % (self.mode, self.path[-2], self.path[-1])
@@ -46,9 +47,18 @@ class PreparserTestCase(test.TestCase):
def GetName(self):
return self.path[-1]
+ def HasSource(self):
+ return self.source is not None
+
+ def GetSource():
+ return self.source
+
def BuildCommand(self, path):
- testfile = join(self.root, self.GetName()) + ".js"
- result = [self.executable, testfile]
+ if (self.source is not None):
+ result = [self.executable, "-e", self.source]
+ else:
+ testfile = join(self.root, self.GetName()) + ".js"
+ result = [self.executable, testfile]
if (self.throws):
result += ['throws'] + self.throws
return result
@@ -85,6 +95,30 @@ class PreparserTestConfiguration(test.TestConfiguration):
map[rule_match.group(1)] = expects
return map;
+ def ParsePythonTestTemplates(self, result, filename,
+ executable, current_path, mode):
+ pathname = join(self.root, filename + ".pyt")
+ source = open(pathname).read();
+ def Test(name, source, expectation):
+ throws = None
+ if (expectation is not None):
+ throws = [expectation]
+ test = PreparserTestCase(self.root,
+ current_path + [filename, name],
+ executable,
+ mode, throws, self.context, source)
+ result.append(test)
+ def Template(name, source):
+ def MkTest(replacement, expectation):
+ testname = name
+ testsource = source
+ for key in replacement.keys():
+ testname = testname.replace("$"+key, replacement[key]);
+ testsource = testsource.replace("$"+key, replacement[key]);
+ Test(testname, testsource, expectation)
+ return MkTest
+ eval(compile(source, pathname, "exec"),
+ {"Test": Test, "Template": Template}, {})
def ListTests(self, current_path, path, mode, variant_flags):
executable = join('obj', 'preparser', mode, 'preparser')
@@ -92,17 +126,25 @@ class PreparserTestConfiguration(test.TestConfiguration):
executable += '.exe'
executable = join(self.context.buildspace, executable)
expectations = self.GetExpectations()
+ result = []
# Find all .js files in tests/preparser directory.
filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")]
filenames.sort()
- result = []
for file in filenames:
throws = None;
if (file in expectations):
throws = expectations[file]
result.append(PreparserTestCase(self.root,
current_path + [file], executable,
- mode, throws, self.context))
+ mode, throws, self.context, None))
+ # Find all .pyt files in test/preparser directory.
+ filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")]
+ filenames.sort()
+ for file in filenames:
+ # Each file as a python source file to be executed in a specially
+ # perparsed environment (defining the Template and Test functions)
+ self.ParsePythonTestTemplates(result, file,
+ executable, current_path, mode)
return result
def GetTestStatus(self, sections, defs):
« no previous file with comments | « test/preparser/strict-yield-var.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698