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