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