OLD | NEW |
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 27 matching lines...) Expand all Loading... |
38 INVALID_FLAGS = ["--enable-slow-asserts"] | 38 INVALID_FLAGS = ["--enable-slow-asserts"] |
39 | 39 |
40 | 40 |
41 class PreparserTestSuite(testsuite.TestSuite): | 41 class PreparserTestSuite(testsuite.TestSuite): |
42 def __init__(self, name, root): | 42 def __init__(self, name, root): |
43 super(PreparserTestSuite, self).__init__(name, root) | 43 super(PreparserTestSuite, self).__init__(name, root) |
44 | 44 |
45 def shell(self): | 45 def shell(self): |
46 return "d8" | 46 return "d8" |
47 | 47 |
48 def _GetExpectations(self): | |
49 expects_file = os.path.join(self.root, "preparser.expectation") | |
50 expectations_map = {} | |
51 if not os.path.exists(expects_file): return expectations_map | |
52 rule_regex = re.compile("^([\w\-]+)(?::([\w\-]+))?(?::(\d+),(\d+))?$") | |
53 for line in utils.ReadLinesFrom(expects_file): | |
54 rule_match = rule_regex.match(line) | |
55 if not rule_match: continue | |
56 expects = [] | |
57 if (rule_match.group(2)): | |
58 expects += [rule_match.group(2)] | |
59 if (rule_match.group(3)): | |
60 expects += [rule_match.group(3), rule_match.group(4)] | |
61 expectations_map[rule_match.group(1)] = " ".join(expects) | |
62 return expectations_map | |
63 | |
64 def _ParsePythonTestTemplates(self, result, filename): | 48 def _ParsePythonTestTemplates(self, result, filename): |
65 pathname = os.path.join(self.root, filename + ".pyt") | 49 pathname = os.path.join(self.root, filename + ".pyt") |
66 def Test(name, source, expectation, extra_flags=[]): | 50 def Test(name, source, expectation, extra_flags=[]): |
67 source = source.replace("\n", " ") | 51 source = source.replace("\n", " ") |
68 testname = os.path.join(filename, name) | 52 testname = os.path.join(filename, name) |
69 flags = ["-e", source] | 53 flags = ["-e", source] |
70 if expectation: | 54 if expectation: |
71 flags += ["--throws"] | 55 flags += ["--throws"] |
72 flags += extra_flags | 56 flags += extra_flags |
73 test = testcase.TestCase(self, testname, flags=flags) | 57 test = testcase.TestCase(self, testname, flags=flags) |
74 result.append(test) | 58 result.append(test) |
75 def Template(name, source): | 59 def Template(name, source): |
76 def MkTest(replacement, expectation): | 60 def MkTest(replacement, expectation): |
77 testname = name | 61 testname = name |
78 testsource = source | 62 testsource = source |
79 for key in replacement.keys(): | 63 for key in replacement.keys(): |
80 testname = testname.replace("$" + key, replacement[key]); | 64 testname = testname.replace("$" + key, replacement[key]); |
81 testsource = testsource.replace("$" + key, replacement[key]); | 65 testsource = testsource.replace("$" + key, replacement[key]); |
82 Test(testname, testsource, expectation) | 66 Test(testname, testsource, expectation) |
83 return MkTest | 67 return MkTest |
84 execfile(pathname, {"Test": Test, "Template": Template}) | 68 execfile(pathname, {"Test": Test, "Template": Template}) |
85 | 69 |
86 def ListTests(self, context): | 70 def ListTests(self, context): |
87 expectations = self._GetExpectations() | |
88 result = [] | 71 result = [] |
89 | 72 |
90 # Find all .js files in this directory. | 73 # Find all .js files in this directory. |
91 filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")] | 74 filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")] |
92 filenames.sort() | 75 filenames.sort() |
93 for f in filenames: | 76 for f in filenames: |
94 throws = expectations.get(f, None) | |
95 flags = [f + ".js"] | 77 flags = [f + ".js"] |
96 if throws: | |
97 flags += ["--throws"] | |
98 test = testcase.TestCase(self, f, flags=flags) | 78 test = testcase.TestCase(self, f, flags=flags) |
99 result.append(test) | 79 result.append(test) |
100 | 80 |
101 # Find all .pyt files in this directory. | 81 # Find all .pyt files in this directory. |
102 filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")] | 82 filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")] |
103 filenames.sort() | 83 filenames.sort() |
104 for f in filenames: | 84 for f in filenames: |
105 self._ParsePythonTestTemplates(result, f) | 85 self._ParsePythonTestTemplates(result, f) |
106 return result | 86 return result |
107 | 87 |
(...skipping 17 matching lines...) Expand all Loading... |
125 return testcase.flags[1] | 105 return testcase.flags[1] |
126 with open(testcase.flags[0]) as f: | 106 with open(testcase.flags[0]) as f: |
127 return f.read() | 107 return f.read() |
128 | 108 |
129 def _VariantGeneratorFactory(self): | 109 def _VariantGeneratorFactory(self): |
130 return testsuite.StandardVariantGenerator | 110 return testsuite.StandardVariantGenerator |
131 | 111 |
132 | 112 |
133 def GetSuite(name, root): | 113 def GetSuite(name, root): |
134 return PreparserTestSuite(name, root) | 114 return PreparserTestSuite(name, root) |
OLD | NEW |