OLD | NEW |
---|---|
1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 """Common TestCase subclasses used to define a single test.""" | 5 """Common TestCase subclasses used to define a single test.""" |
6 | 6 |
7 import os | 7 import os |
8 import tempfile | 8 import tempfile |
9 | 9 |
10 import test | 10 import test |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 53 |
54 def GetSource(self): | 54 def GetSource(self): |
55 return file(self.filename).read() | 55 return file(self.filename).read() |
56 | 56 |
57 def Cleanup(self): | 57 def Cleanup(self): |
58 # TODO(ngeoffray): We run out of space on the build bots for these tests if | 58 # TODO(ngeoffray): We run out of space on the build bots for these tests if |
59 # the temp directories are not removed right after running the test. | 59 # the temp directories are not removed right after running the test. |
60 if not self.context.keep_temporary_files: | 60 if not self.context.keep_temporary_files: |
61 self.run_arch.Cleanup() | 61 self.run_arch.Cleanup() |
62 | 62 |
63 def BeforeRunHelper(self, command): | |
Siggi Cherem (dart-lang)
2011/11/11 00:06:02
I'm not sure why this refactoring needed?
Emily Fortuna
2011/11/11 00:58:41
Because I wanted to be able to compile tests, but
| |
64 """Helper method to merge shared code between StandardTestCase and | |
65 BrowserTestCase""" | |
66 if command: | |
67 # We change the directory where dartc/frog will be launched because | |
68 # it is not predictable on the location of the compiled file. In | |
69 # case the test is a web test, we make sure the app file is not | |
70 # in a subdirectory. | |
71 cwd = None | |
72 if self.run_arch.is_web_test: cwd = self.run_arch.temp_dir | |
73 command = command[:1] + self.context.flags + command[1:] | |
74 test_output = self.RunCommand(command, cwd=cwd, cleanup=False) | |
75 | |
76 # If errors were found, fail fast and show compile errors: | |
77 if test_output.output.exit_code != 0: | |
78 return test_output | |
79 | |
80 def BeforeRun(self): | |
81 """Optionally compile tests.""" | |
82 command = self.run_arch.GetCompileCommand() | |
83 return self.BeforeRunHelper(command) | |
84 | |
63 | 85 |
64 class MultiTestCase(StandardTestCase): | 86 class MultiTestCase(StandardTestCase): |
65 """Multiple test cases defined within a single *Test.dart file.""" | 87 """Multiple test cases defined within a single *Test.dart file.""" |
66 | 88 |
67 def __init__(self, context, path, filename, kind, mode, arch, component, | 89 def __init__(self, context, path, filename, kind, mode, arch, component, |
68 vm_options = None): | 90 vm_options = None): |
69 super(MultiTestCase, self).__init__(context, path, filename, mode, arch, | 91 super(MultiTestCase, self).__init__(context, path, filename, mode, arch, |
70 component, vm_options) | 92 component, vm_options) |
71 self.kind = kind | 93 self.kind = kind |
72 | 94 |
(...skipping 13 matching lines...) Expand all Loading... | |
86 if self.kind == 'compile-time error': | 108 if self.kind == 'compile-time error': |
87 return True | 109 return True |
88 if self.kind == 'runtime error': | 110 if self.kind == 'runtime error': |
89 return True | 111 return True |
90 if self.kind == 'static type error': | 112 if self.kind == 'static type error': |
91 return self.run_arch.HasFatalTypeErrors() | 113 return self.run_arch.HasFatalTypeErrors() |
92 return False | 114 return False |
93 | 115 |
94 | 116 |
95 class BrowserTestCase(StandardTestCase): | 117 class BrowserTestCase(StandardTestCase): |
96 """A test case that executes inside a browser (or DumpRenderTree).""" | 118 """A test case that executes inside DumpRenderTree.""" |
97 | 119 |
98 def __init__(self, context, path, filename, | 120 def __init__(self, context, path, filename, |
99 fatal_static_type_errors, mode, arch, component, vm_options=None) : | 121 fatal_static_type_errors, mode, arch, component, vm_options=None) : |
100 super(BrowserTestCase, self).__init__( | 122 super(BrowserTestCase, self).__init__( |
101 context, path, filename, mode, arch, component, vm_options) | 123 context, path, filename, mode, arch, component, vm_options) |
102 self.fatal_static_type_errors = fatal_static_type_errors | 124 self.fatal_static_type_errors = fatal_static_type_errors |
103 | 125 |
126 def BeforeRun(self): | |
127 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) | |
128 return self.BeforeRunHelper(command) | |
129 | |
104 def Run(self): | 130 def Run(self): |
105 """Optionally compiles and then runs the specified test.""" | 131 """Runs the specified test, with an update to the exit code to compensate |
106 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) | 132 for DumpRenderTree.""" |
Jennifer Messerly
2011/11/10 23:57:08
as long as this looks good to Siggi it works for m
| |
107 if command: | |
108 # We change the directory where dartc will be launched because | |
109 # it is not predictable on the location of the compiled file. In | |
110 # case the test is a web test, we make sure the app file is not | |
111 # in a subdirectory. | |
112 cwd = None | |
113 if self.run_arch.is_web_test: cwd = self.run_arch.temp_dir | |
114 command = command[:1] + self.context.flags + command[1:] | |
115 test_output = self.RunCommand(command, cwd=cwd, cleanup=False) | |
116 | |
117 # If errors were found, fail fast and show compile errors: | |
118 if test_output.output.exit_code != 0: | |
119 return test_output | |
120 | |
121 command = self.run_arch.GetRunCommand() | 133 command = self.run_arch.GetRunCommand() |
122 test_output = self.RunCommand(command) | 134 test_output = self.RunCommand(command) |
123 # The return value of DumpRenderedTree does not indicate test failing, but | 135 # The return value of DumpRenderedTree does not indicate test failing, but |
124 # the output does. | 136 # the output does. |
125 if self.run_arch.HasFailed(test_output.output.stdout): | 137 if self.run_arch.HasFailed(test_output.output.stdout): |
126 test_output.output.exit_code = 1 | 138 test_output.output.exit_code = 1 |
127 | 139 |
128 return test_output | 140 return test_output |
129 | 141 |
130 | 142 |
(...skipping 30 matching lines...) Expand all Loading... | |
161 self.filename] | 173 self.filename] |
162 | 174 |
163 return cmd | 175 return cmd |
164 | 176 |
165 def GetName(self): | 177 def GetName(self): |
166 return self.path[-1] | 178 return self.path[-1] |
167 | 179 |
168 def Cleanup(self): | 180 def Cleanup(self): |
169 if not self.context.keep_temporary_files: | 181 if not self.context.keep_temporary_files: |
170 self.run_arch.Cleanup() | 182 self.run_arch.Cleanup() |
OLD | NEW |