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