Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: tools/testing/test_case.py

Issue 9360017: Remove unused support files for old version of tools/test.py. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove testcfg.py files. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/testing/architecture.py ('k') | tools/testing/test_configuration.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # BSD-style license that can be found in the LICENSE file.
4
5 """Common TestCase subclasses used to define a single test."""
6
7 import os
8 import tempfile
9
10 import test
11 from testing import architecture
12
13
14 class Error(Exception):
15 pass
16
17
18 class StandardTestCase(test.TestCase):
19 """A test case defined by a *Test.dart file."""
20
21 def __init__(self, context, path, filename, mode, arch, component,
22 vm_options=None):
23 super(StandardTestCase, self).__init__(context, path)
24 self.filename = filename
25 self.mode = mode
26 self.arch = arch
27 self.component = component
28 self.run_arch = architecture.GetArchitecture(self.arch, self.mode,
29 self.component,
30 self.filename)
31 for flag in context.flags:
32 self.run_arch.vm_options.append(flag)
33
34 if vm_options:
35 for flag in vm_options:
36 self.run_arch.vm_options.append(flag)
37
38 def IsNegative(self):
39 return self.GetName().endswith('NegativeTest')
40
41 def GetLabel(self):
42 return '%s%s %s %s' % (self.mode, self.arch, self.component,
43 '/'.join(self.path))
44
45 def GetCommand(self):
46 return self.run_arch.GetRunCommand()
47
48 def GetName(self):
49 return self.path[-1]
50
51 def GetPath(self):
52 return os.path.dirname(self.filename)
53
54 def GetSource(self):
55 return file(self.filename).read()
56
57 def Cleanup(self):
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.
60 if not self.context.keep_temporary_files:
61 self.run_arch.Cleanup()
62
63
64 class MultiTestCase(StandardTestCase):
65 """Multiple test cases defined within a single *Test.dart file."""
66
67 def __init__(self, context, path, filename, kind, mode, arch, component,
68 vm_options = None):
69 super(MultiTestCase, self).__init__(context, path, filename, mode, arch,
70 component, vm_options)
71 self.kind = kind
72
73 def GetCommand(self):
74 """Returns a commandline to execute to perform the test."""
75 return self.run_arch.GetRunCommand(
76 fatal_static_type_errors=(self.kind == 'static type error'))
77
78 def IsNegative(self):
79 """Determine if this is a negative test. by looking at @ directives.
80
81 A negative test is considered to pas if its outcome is FAIL.
82
83 Returns:
84 True if this is a negative test.
85 """
86 if self.kind == 'compile-time error':
87 return True
88 if self.kind == 'runtime error':
89 return True
90 if self.kind == 'static type error':
91 return self.run_arch.HasFatalTypeErrors()
92 return False
93
94
95 class BrowserTestCase(StandardTestCase):
96 """A test case that executes inside DumpRenderTree or a browser."""
97
98 def __init__(self, context, path, filename,
99 fatal_static_type_errors, mode, arch, component, vm_options=None) :
100 super(BrowserTestCase, self).__init__(
101 context, path, filename, mode, arch, component, vm_options)
102 self.fatal_static_type_errors = fatal_static_type_errors
103
104 def Run(self):
105 """Optionally compiles and then runs the specified test."""
106 command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors)
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()
122 # Don't clean up just in case test turned out flaky and we want to retry.
123 test_output = self.RunCommand(command, cleanup=False)
124 # The return value of DumpRenderedTree does not indicate test failing, but
125 # the output does.
126 if self.run_arch.HasFailed(test_output.output.stdout):
127 test_output.output.exit_code = 1
128 # DumpRenderTree is sometimes flaky in xvfb-run, try again in that case.
129 if (self.run_arch.WasFlakyDrt(test_output.output.stderr)):
130 print "\nFlaky Gtw-WARNING error found, trying again..."
131 test_output = self.RunCommand(command, cleanup=False)
132 if self.run_arch.HasFailed(test_output.output.stdout):
133 test_output.output.exit_code = 1
134 self.Cleanup();
135
136 return test_output
137
138
139 class CompilationTestCase(test.TestCase):
140 """Run the dartc compiler on a given top level .dart file."""
141
142 def __init__(self, path, context, filename, mode, arch, component):
143 super(CompilationTestCase, self).__init__(context, path)
144 self.filename = filename
145 self.mode = mode
146 self.arch = arch
147 self.component = component
148 self.run_arch = architecture.GetArchitecture(self.arch,
149 self.mode,
150 self.component,
151 self.filename)
152 self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-')
153
154 def IsNegative(self):
155 return False
156
157 def GetLabel(self):
158 return '%s/%s %s %s' % (self.mode, self.arch, self.component,
159 '/'.join(self.path))
160
161 def GetCommand(self):
162 """Returns a command line to run the test."""
163 cmd = self.context.GetDartC(self.mode, self.arch)
164 cmd += self.context.flags
165 cmd += ['-check-only',
166 '-fatal-type-errors',
167 '-Werror',
168 '-out', self.temp_dir,
169 self.filename]
170
171 return cmd
172
173 def GetName(self):
174 return self.path[-1]
175
176 def Cleanup(self):
177 if not self.context.keep_temporary_files:
178 self.run_arch.Cleanup()
OLDNEW
« no previous file with comments | « tools/testing/architecture.py ('k') | tools/testing/test_configuration.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698