| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 if (rule_match.group(2)): | 91 if (rule_match.group(2)): |
| 92 expects = expects + [rule_match.group(2)] | 92 expects = expects + [rule_match.group(2)] |
| 93 if (rule_match.group(3)): | 93 if (rule_match.group(3)): |
| 94 expects = expects + [rule_match.group(3), rule_match.group(4)] | 94 expects = expects + [rule_match.group(3), rule_match.group(4)] |
| 95 map[rule_match.group(1)] = expects | 95 map[rule_match.group(1)] = expects |
| 96 return map; | 96 return map; |
| 97 | 97 |
| 98 def ParsePythonTestTemplates(self, result, filename, | 98 def ParsePythonTestTemplates(self, result, filename, |
| 99 executable, current_path, mode): | 99 executable, current_path, mode): |
| 100 pathname = join(self.root, filename + ".pyt") | 100 pathname = join(self.root, filename + ".pyt") |
| 101 source = open(pathname).read(); | |
| 102 def Test(name, source, expectation): | 101 def Test(name, source, expectation): |
| 103 throws = None | 102 throws = None |
| 104 if (expectation is not None): | 103 if (expectation is not None): |
| 105 throws = [expectation] | 104 throws = [expectation] |
| 106 test = PreparserTestCase(self.root, | 105 test = PreparserTestCase(self.root, |
| 107 current_path + [filename, name], | 106 current_path + [filename, name], |
| 108 executable, | 107 executable, |
| 109 mode, throws, self.context, | 108 mode, throws, self.context, |
| 110 source.replace("\n", " ")) | 109 source.replace("\n", " ")) |
| 111 result.append(test) | 110 result.append(test) |
| 112 def Template(name, source): | 111 def Template(name, source): |
| 113 def MkTest(replacement, expectation): | 112 def MkTest(replacement, expectation): |
| 114 testname = name | 113 testname = name |
| 115 testsource = source | 114 testsource = source |
| 116 for key in replacement.keys(): | 115 for key in replacement.keys(): |
| 117 testname = testname.replace("$"+key, replacement[key]); | 116 testname = testname.replace("$"+key, replacement[key]); |
| 118 testsource = testsource.replace("$"+key, replacement[key]); | 117 testsource = testsource.replace("$"+key, replacement[key]); |
| 119 Test(testname, testsource, expectation) | 118 Test(testname, testsource, expectation) |
| 120 return MkTest | 119 return MkTest |
| 121 eval(compile(source, pathname, "exec"), | 120 execfile(pathname, {"Test": Test, "Template": Template}) |
| 122 {"Test": Test, "Template": Template}, {}) | |
| 123 | 121 |
| 124 def ListTests(self, current_path, path, mode, variant_flags): | 122 def ListTests(self, current_path, path, mode, variant_flags): |
| 125 executable = join('obj', 'preparser', mode, 'preparser') | 123 executable = join('obj', 'preparser', mode, 'preparser') |
| 126 if utils.IsWindows(): | 124 if utils.IsWindows(): |
| 127 executable += '.exe' | 125 executable += '.exe' |
| 128 executable = join(self.context.buildspace, executable) | 126 executable = join(self.context.buildspace, executable) |
| 129 expectations = self.GetExpectations() | 127 expectations = self.GetExpectations() |
| 130 result = [] | 128 result = [] |
| 131 # Find all .js files in tests/preparser directory. | 129 # Find all .js files in tests/preparser directory. |
| 132 filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")] | 130 filenames = [f[:-3] for f in os.listdir(self.root) if f.endswith(".js")] |
| 133 filenames.sort() | 131 filenames.sort() |
| 134 for file in filenames: | 132 for file in filenames: |
| 135 throws = None; | 133 throws = None; |
| 136 if (file in expectations): | 134 if (file in expectations): |
| 137 throws = expectations[file] | 135 throws = expectations[file] |
| 138 result.append(PreparserTestCase(self.root, | 136 result.append(PreparserTestCase(self.root, |
| 139 current_path + [file], executable, | 137 current_path + [file], executable, |
| 140 mode, throws, self.context, None)) | 138 mode, throws, self.context, None)) |
| 141 # Find all .pyt files in test/preparser directory. | 139 # Find all .pyt files in test/preparser directory. |
| 142 filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")] | 140 filenames = [f[:-4] for f in os.listdir(self.root) if f.endswith(".pyt")] |
| 143 filenames.sort() | 141 filenames.sort() |
| 144 for file in filenames: | 142 for file in filenames: |
| 145 # Each file as a python source file to be executed in a specially | 143 # Each file as a python source file to be executed in a specially |
| 146 # perparsed environment (defining the Template and Test functions) | 144 # created environment (defining the Template and Test functions) |
| 147 self.ParsePythonTestTemplates(result, file, | 145 self.ParsePythonTestTemplates(result, file, |
| 148 executable, current_path, mode) | 146 executable, current_path, mode) |
| 149 return result | 147 return result |
| 150 | 148 |
| 151 def GetTestStatus(self, sections, defs): | 149 def GetTestStatus(self, sections, defs): |
| 152 status_file = join(self.root, 'preparser.status') | 150 status_file = join(self.root, 'preparser.status') |
| 153 if exists(status_file): | 151 if exists(status_file): |
| 154 test.ReadConfigurationInto(status_file, sections, defs) | 152 test.ReadConfigurationInto(status_file, sections, defs) |
| 155 | 153 |
| 156 def VariantFlags(self): | 154 def VariantFlags(self): |
| 157 return [[]]; | 155 return [[]]; |
| 158 | 156 |
| 159 | 157 |
| 160 def GetConfiguration(context, root): | 158 def GetConfiguration(context, root): |
| 161 return PreparserTestConfiguration(context, root) | 159 return PreparserTestConfiguration(context, root) |
| OLD | NEW |