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 |
11 from testing import architecture | 11 from testing import architecture |
12 | 12 |
13 | 13 |
14 class Error(Exception): | 14 class Error(Exception): |
15 pass | 15 pass |
16 | 16 |
17 | 17 |
18 class StandardTestCase(test.TestCase): | 18 class StandardTestCase(test.TestCase): |
19 """A test case defined by a *Test.dart file.""" | 19 """A test case defined by a *Test.dart file.""" |
20 | 20 |
21 def __init__(self, context, path, filename, mode, arch, vm_options=None): | 21 def __init__(self, context, path, filename, mode, arch, component, |
| 22 vm_options=None): |
22 super(StandardTestCase, self).__init__(context, path) | 23 super(StandardTestCase, self).__init__(context, path) |
23 self.filename = filename | 24 self.filename = filename |
24 self.mode = mode | 25 self.mode = mode |
25 self.arch = arch | 26 self.arch = arch |
| 27 self.component = component |
26 self.run_arch = architecture.GetArchitecture(self.arch, self.mode, | 28 self.run_arch = architecture.GetArchitecture(self.arch, self.mode, |
| 29 self.component, |
27 self.filename) | 30 self.filename) |
28 for flag in context.flags: | 31 for flag in context.flags: |
29 self.run_arch.vm_options.append(flag) | 32 self.run_arch.vm_options.append(flag) |
30 | 33 |
31 if vm_options: | 34 if vm_options: |
32 for flag in vm_options: | 35 for flag in vm_options: |
33 self.run_arch.vm_options.append(flag) | 36 self.run_arch.vm_options.append(flag) |
34 | 37 |
35 def IsNegative(self): | 38 def IsNegative(self): |
36 return self.GetName().endswith('NegativeTest') | 39 return self.GetName().endswith('NegativeTest') |
37 | 40 |
38 def GetLabel(self): | 41 def GetLabel(self): |
39 return '%s%s %s' % (self.mode, self.arch, '/'.join(self.path)) | 42 return '%s%s %s %s' % (self.mode, self.arch, self.component, |
| 43 '/'.join(self.path)) |
40 | 44 |
41 def GetCommand(self): | 45 def GetCommand(self): |
42 return self.run_arch.GetRunCommand() | 46 return self.run_arch.GetRunCommand() |
43 | 47 |
44 def GetName(self): | 48 def GetName(self): |
45 return self.path[-1] | 49 return self.path[-1] |
46 | 50 |
47 def GetPath(self): | 51 def GetPath(self): |
48 return os.path.dirname(self.filename) | 52 return os.path.dirname(self.filename) |
49 | 53 |
50 def GetSource(self): | 54 def GetSource(self): |
51 return file(self.filename).read() | 55 return file(self.filename).read() |
52 | 56 |
53 def Cleanup(self): | 57 def Cleanup(self): |
54 # 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 |
55 # the temp directories are not removed right after running the test. | 59 # the temp directories are not removed right after running the test. |
56 if not self.context.keep_temporary_files: | 60 if not self.context.keep_temporary_files: |
57 self.run_arch.Cleanup() | 61 self.run_arch.Cleanup() |
58 | 62 |
59 | 63 |
60 class MultiTestCase(StandardTestCase): | 64 class MultiTestCase(StandardTestCase): |
61 """Multiple test cases defined within a single *Test.dart file.""" | 65 """Multiple test cases defined within a single *Test.dart file.""" |
62 | 66 |
63 def __init__(self, context, path, filename, kind, mode, arch): | 67 def __init__(self, context, path, filename, kind, mode, arch, component): |
64 super(MultiTestCase, self).__init__(context, path, filename, mode, arch) | 68 super(MultiTestCase, self).__init__(context, path, filename, mode, arch, |
| 69 component) |
65 self.kind = kind | 70 self.kind = kind |
66 | 71 |
67 def GetCommand(self): | 72 def GetCommand(self): |
68 """Returns a commandline to execute to perform the test.""" | 73 """Returns a commandline to execute to perform the test.""" |
69 return self.run_arch.GetRunCommand( | 74 return self.run_arch.GetRunCommand( |
70 fatal_static_type_errors=(self.kind == 'static type error')) | 75 fatal_static_type_errors=(self.kind == 'static type error')) |
71 | 76 |
72 def IsNegative(self): | 77 def IsNegative(self): |
73 """Determine if this is a negative test. by looking at @ directives. | 78 """Determine if this is a negative test. by looking at @ directives. |
74 | 79 |
75 A negative test is considered to pas if its outcome is FAIL. | 80 A negative test is considered to pas if its outcome is FAIL. |
76 | 81 |
77 Returns: | 82 Returns: |
78 True if this is a negative test. | 83 True if this is a negative test. |
79 """ | 84 """ |
80 if self.kind == 'compile-time error': | 85 if self.kind == 'compile-time error': |
81 return True | 86 return True |
82 if self.kind == 'runtime error': | 87 if self.kind == 'runtime error': |
83 return False | 88 return False |
84 if self.kind == 'static type error': | 89 if self.kind == 'static type error': |
85 return self.run_arch.HasFatalTypeErrors() | 90 return self.run_arch.HasFatalTypeErrors() |
86 return False | 91 return False |
87 | 92 |
88 | 93 |
89 class BrowserTestCase(StandardTestCase): | 94 class BrowserTestCase(StandardTestCase): |
90 """A test case that executes inside a browser (or DumpRenderTree).""" | 95 """A test case that executes inside a browser (or DumpRenderTree).""" |
91 | 96 |
92 def __init__(self, context, path, filename, | 97 def __init__(self, context, path, filename, |
93 fatal_static_type_errors, mode, arch, vm_options=None): | 98 fatal_static_type_errors, mode, arch, component, vm_options=None)
: |
94 super(BrowserTestCase, self).__init__( | 99 super(BrowserTestCase, self).__init__( |
95 context, path, filename, mode, arch, vm_options) | 100 context, path, filename, mode, arch, component, vm_options) |
96 self.fatal_static_type_errors = fatal_static_type_errors | 101 self.fatal_static_type_errors = fatal_static_type_errors |
97 | 102 |
98 def Run(self): | 103 def Run(self): |
99 """Optionally compiles and then runs the specified test.""" | 104 """Optionally compiles and then runs the specified test.""" |
100 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) | 105 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) |
101 if command: | 106 if command: |
102 # We change the directory where dartc will be launched because | 107 # We change the directory where dartc will be launched because |
103 # it is not predictable on the location of the compiled file. In | 108 # it is not predictable on the location of the compiled file. In |
104 # case the test is a web test, we make sure the app file is not | 109 # case the test is a web test, we make sure the app file is not |
105 # in a subdirectory. | 110 # in a subdirectory. |
(...skipping 12 matching lines...) Expand all Loading... |
118 # the output does. | 123 # the output does. |
119 if self.run_arch.HasFailed(test_output.output.stdout): | 124 if self.run_arch.HasFailed(test_output.output.stdout): |
120 test_output.output.exit_code = 1 | 125 test_output.output.exit_code = 1 |
121 | 126 |
122 return test_output | 127 return test_output |
123 | 128 |
124 | 129 |
125 class CompilationTestCase(test.TestCase): | 130 class CompilationTestCase(test.TestCase): |
126 """Run the dartc compiler on a given top level .dart file.""" | 131 """Run the dartc compiler on a given top level .dart file.""" |
127 | 132 |
128 def __init__(self, path, context, filename, mode, arch): | 133 def __init__(self, path, context, filename, mode, arch, component): |
129 super(CompilationTestCase, self).__init__(context, path) | 134 super(CompilationTestCase, self).__init__(context, path) |
130 self.filename = filename | 135 self.filename = filename |
131 self.mode = mode | 136 self.mode = mode |
132 self.arch = arch | 137 self.arch = arch |
133 self.run_arch = architecture.GetArchitecture(self.arch, self.mode, | 138 self.component = component |
| 139 self.run_arch = architecture.GetArchitecture(self.arch, |
| 140 self.mode, |
| 141 self.component, |
134 self.filename) | 142 self.filename) |
135 self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-') | 143 self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-') |
136 | 144 |
137 def IsNegative(self): | 145 def IsNegative(self): |
138 return False | 146 return False |
139 | 147 |
140 def GetLabel(self): | 148 def GetLabel(self): |
141 return '%s/%s %s' % (self.mode, self.arch, '/'.join(self.path)) | 149 return '%s/%s %s %s' % (self.mode, self.arch, self.component, |
| 150 '/'.join(self.path)) |
142 | 151 |
143 def GetCommand(self): | 152 def GetCommand(self): |
144 """Returns a command line to run the test.""" | 153 """Returns a command line to run the test.""" |
145 cmd = self.context.GetDartC(self.mode, self.arch) | 154 cmd = self.context.GetDartC(self.mode, self.arch) |
146 cmd += self.context.flags | 155 cmd += self.context.flags |
147 cmd += ['-check-only', | 156 cmd += ['-check-only', |
148 '-fatal-type-errors', | 157 '-fatal-type-errors', |
149 '-Werror', | 158 '-Werror', |
150 '-out', self.temp_dir, | 159 '-out', self.temp_dir, |
151 self.filename] | 160 self.filename] |
152 | 161 |
153 return cmd | 162 return cmd |
154 | 163 |
155 def GetName(self): | 164 def GetName(self): |
156 return self.path[-1] | 165 return self.path[-1] |
157 | 166 |
158 def Cleanup(self): | 167 def Cleanup(self): |
159 if not self.context.keep_temporary_files: | 168 if not self.context.keep_temporary_files: |
160 self.run_arch.Cleanup() | 169 self.run_arch.Cleanup() |
OLD | NEW |