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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/preparser/strict-yield-var.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2011 the V8 project authors. All rights reserved. 1 # Copyright 2011 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
(...skipping 16 matching lines...) Expand all
27 27
28 import test 28 import test
29 import os 29 import os
30 from os.path import join, dirname, exists 30 from os.path import join, dirname, exists
31 import platform 31 import platform
32 import utils 32 import utils
33 import re 33 import re
34 34
35 class PreparserTestCase(test.TestCase): 35 class PreparserTestCase(test.TestCase):
36 36
37 def __init__(self, root, path, executable, mode, throws, context): 37 def __init__(self, root, path, executable, mode, throws, context, source):
38 super(PreparserTestCase, self).__init__(context, path, mode) 38 super(PreparserTestCase, self).__init__(context, path, mode)
39 self.executable = executable 39 self.executable = executable
40 self.root = root 40 self.root = root
41 self.throws = throws 41 self.throws = throws
42 self.source = source
42 43
43 def GetLabel(self): 44 def GetLabel(self):
44 return "%s %s %s" % (self.mode, self.path[-2], self.path[-1]) 45 return "%s %s %s" % (self.mode, self.path[-2], self.path[-1])
45 46
46 def GetName(self): 47 def GetName(self):
47 return self.path[-1] 48 return self.path[-1]
48 49
50 def HasSource(self):
51 return self.source is not None
52
53 def GetSource():
54 return self.source
55
49 def BuildCommand(self, path): 56 def BuildCommand(self, path):
50 testfile = join(self.root, self.GetName()) + ".js" 57 if (self.source is not None):
51 result = [self.executable, testfile] 58 result = [self.executable, "-e", self.source]
59 else:
60 testfile = join(self.root, self.GetName()) + ".js"
61 result = [self.executable, testfile]
52 if (self.throws): 62 if (self.throws):
53 result += ['throws'] + self.throws 63 result += ['throws'] + self.throws
54 return result 64 return result
55 65
56 def GetCommand(self): 66 def GetCommand(self):
57 return self.BuildCommand(self.path) 67 return self.BuildCommand(self.path)
58 68
59 def Run(self): 69 def Run(self):
60 return test.TestCase.Run(self) 70 return test.TestCase.Run(self)
61 71
(...skipping 16 matching lines...) Expand all
78 rule_match = rule_regex.match(line) 88 rule_match = rule_regex.match(line)
79 if rule_match: 89 if rule_match:
80 expects = [] 90 expects = []
81 if (rule_match.group(2)): 91 if (rule_match.group(2)):
82 expects = expects + [rule_match.group(2)] 92 expects = expects + [rule_match.group(2)]
83 if (rule_match.group(3)): 93 if (rule_match.group(3)):
84 expects = expects + [rule_match.group(3), rule_match.group(4)] 94 expects = expects + [rule_match.group(3), rule_match.group(4)]
85 map[rule_match.group(1)] = expects 95 map[rule_match.group(1)] = expects
86 return map; 96 return map;
87 97
98 def ParsePythonTestTemplates(self, result, filename,
99 executable, current_path, mode):
100 pathname = join(self.root, filename + ".pyt")
101 source = open(pathname).read();
102 def Test(name, source, expectation):
103 throws = None
104 if (expectation is not None):
105 throws = [expectation]
106 test = PreparserTestCase(self.root,
107 current_path + [filename, name],
108 executable,
109 mode, throws, self.context, source)
110 result.append(test)
111 def Template(name, source):
112 def MkTest(replacement, expectation):
113 testname = name
114 testsource = source
115 for key in replacement.keys():
116 testname = testname.replace("$"+key, replacement[key]);
117 testsource = testsource.replace("$"+key, replacement[key]);
118 Test(testname, testsource, expectation)
119 return MkTest
120 eval(compile(source, pathname, "exec"),
121 {"Test": Test, "Template": Template}, {})
88 122
89 def ListTests(self, current_path, path, mode, variant_flags): 123 def ListTests(self, current_path, path, mode, variant_flags):
90 executable = join('obj', 'preparser', mode, 'preparser') 124 executable = join('obj', 'preparser', mode, 'preparser')
91 if utils.IsWindows(): 125 if utils.IsWindows():
92 executable += '.exe' 126 executable += '.exe'
93 executable = join(self.context.buildspace, executable) 127 executable = join(self.context.buildspace, executable)
94 expectations = self.GetExpectations() 128 expectations = self.GetExpectations()
129 result = []
95 # Find all .js files in tests/preparser directory. 130 # Find all .js files in tests/preparser directory.
96 filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")] 131 filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")]
97 filenames.sort() 132 filenames.sort()
98 result = []
99 for file in filenames: 133 for file in filenames:
100 throws = None; 134 throws = None;
101 if (file in expectations): 135 if (file in expectations):
102 throws = expectations[file] 136 throws = expectations[file]
103 result.append(PreparserTestCase(self.root, 137 result.append(PreparserTestCase(self.root,
104 current_path + [file], executable, 138 current_path + [file], executable,
105 mode, throws, self.context)) 139 mode, throws, self.context, None))
140 # Find all .pyt files in test/preparser directory.
141 filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")]
142 filenames.sort()
143 for file in filenames:
144 # Each file as a python source file to be executed in a specially
145 # perparsed environment (defining the Template and Test functions)
146 self.ParsePythonTestTemplates(result, file,
147 executable, current_path, mode)
106 return result 148 return result
107 149
108 def GetTestStatus(self, sections, defs): 150 def GetTestStatus(self, sections, defs):
109 status_file = join(self.root, 'preparser.status') 151 status_file = join(self.root, 'preparser.status')
110 if exists(status_file): 152 if exists(status_file):
111 test.ReadConfigurationInto(status_file, sections, defs) 153 test.ReadConfigurationInto(status_file, sections, defs)
112 154
113 def VariantFlags(self): 155 def VariantFlags(self):
114 return [[]]; 156 return [[]];
115 157
116 158
117 def GetConfiguration(context, root): 159 def GetConfiguration(context, root):
118 return PreparserTestConfiguration(context, root) 160 return PreparserTestConfiguration(context, root)
OLDNEW
« 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