diff --git a/client/tests/client/testcfg.py b/client/tests/client/testcfg.py index b5042f32f5c..7d2c2ab5d69 100644 --- a/client/tests/client/testcfg.py +++ b/client/tests/client/testcfg.py @@ -2,13 +2,8 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. -import os -import test - -from os.path import join, exists - -import testing +from testing import test_configuration def GetConfiguration(context, root): - return testing.BrowserTestConfiguration( + return test_configuration.BrowserTestConfiguration( context, root, fatal_static_type_errors=True) diff --git a/client/tests/dartc/testcfg.py b/client/tests/dartc/testcfg.py index 97a941b31a2..efeb28356b3 100644 --- a/client/tests/dartc/testcfg.py +++ b/client/tests/dartc/testcfg.py @@ -2,14 +2,14 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. -import testing +from testing import test_configuration def GetConfiguration(context, root): return ClientCompilationTestConfiguration(context, root) class ClientCompilationTestConfiguration( - testing.CompilationTestConfiguration): + test_configuration.CompilationTestConfiguration): def __init__(self, context, root): super(ClientCompilationTestConfiguration, self).__init__(context, root) diff --git a/co19/tests/co19/testcfg.py b/co19/tests/co19/testcfg.py index b84739611c0..484c20cc25f 100644 --- a/co19/tests/co19/testcfg.py +++ b/co19/tests/co19/testcfg.py @@ -2,13 +2,14 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. + import os +from os.path import join, exists import re + import test import utils -from os.path import join, exists - class Error(Exception): pass diff --git a/compiler/tests/dart/testcfg.py b/compiler/tests/dart/testcfg.py index 2df39433e47..b7d3e13f3c4 100644 --- a/compiler/tests/dart/testcfg.py +++ b/compiler/tests/dart/testcfg.py @@ -2,7 +2,7 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. -import testing +from testing import test_configuration def GetConfiguration(context, root): - return testing.StandardTestConfiguration(context, root) + return test_configuration.StandardTestConfiguration(context, root) diff --git a/compiler/tests/dartc/testcfg.py b/compiler/tests/dartc/testcfg.py index 3597ccffa8c..f28a4269103 100644 --- a/compiler/tests/dartc/testcfg.py +++ b/compiler/tests/dartc/testcfg.py @@ -4,11 +4,13 @@ # BSD-style license that can be found in the LICENSE file. import os +from os.path import join, exists import re + import test import utils -from os.path import join, exists + class JUnitTestCase(test.TestCase): def __init__(self, path, context, classnames, mode, arch): diff --git a/runtime/tests/dart/testcfg.py b/runtime/tests/dart/testcfg.py index 2df39433e47..b7d3e13f3c4 100644 --- a/runtime/tests/dart/testcfg.py +++ b/runtime/tests/dart/testcfg.py @@ -2,7 +2,7 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. -import testing +from testing import test_configuration def GetConfiguration(context, root): - return testing.StandardTestConfiguration(context, root) + return test_configuration.StandardTestConfiguration(context, root) diff --git a/runtime/tests/vm/testcfg.py b/runtime/tests/vm/testcfg.py index ea4c1b2495b..fa0ff011740 100644 --- a/runtime/tests/vm/testcfg.py +++ b/runtime/tests/vm/testcfg.py @@ -3,10 +3,10 @@ # BSD-style license that can be found in the LICENSE file. import os -import test - from os.path import join, exists +import test + class VmTestCase(test.TestCase): def __init__(self, path, context, mode, arch, flags): super(VmTestCase, self).__init__(context, path) diff --git a/tests/corelib/testcfg.py b/tests/corelib/testcfg.py index 2df39433e47..b7d3e13f3c4 100644 --- a/tests/corelib/testcfg.py +++ b/tests/corelib/testcfg.py @@ -2,7 +2,7 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. -import testing +from testing import test_configuration def GetConfiguration(context, root): - return testing.StandardTestConfiguration(context, root) + return test_configuration.StandardTestConfiguration(context, root) diff --git a/tests/isolate/testcfg.py b/tests/isolate/testcfg.py index 2df39433e47..b7d3e13f3c4 100644 --- a/tests/isolate/testcfg.py +++ b/tests/isolate/testcfg.py @@ -2,7 +2,7 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. -import testing +from testing import test_configuration def GetConfiguration(context, root): - return testing.StandardTestConfiguration(context, root) + return test_configuration.StandardTestConfiguration(context, root) diff --git a/tests/language/testcfg.py b/tests/language/testcfg.py index 2df39433e47..b7d3e13f3c4 100644 --- a/tests/language/testcfg.py +++ b/tests/language/testcfg.py @@ -2,7 +2,7 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. -import testing +from testing import test_configuration def GetConfiguration(context, root): - return testing.StandardTestConfiguration(context, root) + return test_configuration.StandardTestConfiguration(context, root) diff --git a/tests/stub-generator/testcfg.py b/tests/stub-generator/testcfg.py index 6017d18526d..0d436fac060 100644 --- a/tests/stub-generator/testcfg.py +++ b/tests/stub-generator/testcfg.py @@ -6,13 +6,14 @@ import os import re import shutil import tempfile + import test -import testing +from testing import test_case,test_configuration import utils from os.path import join, exists, isdir -class DartStubTestCase(testing.StandardTestCase): +class DartStubTestCase(test_case.StandardTestCase): def __init__(self, context, path, filename, mode, arch): super(DartStubTestCase, self).__init__(context, path, filename, mode, arch) self.filename = filename @@ -71,7 +72,7 @@ class DartStubTestCase(testing.StandardTestCase): return command -class DartStubTestConfiguration(testing.StandardTestConfiguration): +class DartStubTestConfiguration(test_configuration.StandardTestConfiguration): def __init__(self, context, root): super(DartStubTestConfiguration, self).__init__(context, root) diff --git a/tools/testing/__init__.py b/tools/testing/__init__.py new file mode 100644 index 00000000000..c0541ffc1d5 --- /dev/null +++ b/tools/testing/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. diff --git a/tools/testing/test_case.py b/tools/testing/test_case.py new file mode 100644 index 00000000000..62e99093574 --- /dev/null +++ b/tools/testing/test_case.py @@ -0,0 +1,143 @@ +# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +import atexit +import fileinput +import os +import test +import platform +import re +import run +import sys +import tempfile + +import test +import utils + +from os.path import join, exists, basename + +import utils + +class Error(Exception): + pass + + +class StandardTestCase(test.TestCase): + def __init__(self, context, path, filename, mode, arch): + super(StandardTestCase, self).__init__(context, path) + self.filename = filename + self.mode = mode + self.arch = arch + self.run_arch = run.GetArchitecture(self.arch, self.mode, self.filename) + for flag in context.flags: + self.run_arch.vm_options.append(flag) + + def IsNegative(self): + return self.GetName().endswith("NegativeTest") + + def GetLabel(self): + return "%s%s %s" % (self.mode, self.arch, '/'.join(self.path)) + + def GetCommand(self): + return self.run_arch.GetRunCommand(); + + def GetName(self): + return self.path[-1] + + def GetPath(self): + return os.path.dirname(self.filename) + + def GetSource(self): + return file(self.filename).read() + + +class MultiTestCase(StandardTestCase): + + def __init__(self, context, path, filename, kind, mode, arch): + super(MultiTestCase, self).__init__(context, path, filename, mode, arch) + self.kind = kind + + def GetCommand(self): + return self.run_arch.GetRunCommand( + fatal_static_type_errors=(self.kind == 'static type error')); + + def IsNegative(self): + if self.kind == 'compile-time error': + return True + if self.kind == 'runtime error': + return False + if self.kind == 'static type error': + return self.run_arch.HasFatalTypeErrors() + return False + +class BrowserTestCase(StandardTestCase): + def __init__(self, context, path, filename, + fatal_static_type_errors, mode, arch): + super(BrowserTestCase, self).__init__(context, path, filename, mode, arch) + self.fatal_static_type_errors = fatal_static_type_errors + + + def Run(self): + command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) + if command != None: + # We change the directory where dartc will be launched because + # it is not predictable on the location of the compiled file. In + # case the test is a web test, we make sure the app file is not + # in a subdirectory. + cwd = None + if self.run_arch.is_web_test: cwd = self.run_arch.temp_dir + command = command[:1] + self.context.flags + command[1:] + test_output = self.RunCommand(command, cwd=cwd) + + # If errors were found, fail fast and show compile errors: + if test_output.output.exit_code != 0: + if not self.context.keep_temporary_files: + self.run_arch.Cleanup() + return test_output + + command = self.run_arch.GetRunCommand(); + test_output = self.RunCommand(command) + # The return value of DumpRenderedTree does not indicate test failing, but + # the output does. + if self.run_arch.HasFailed(test_output.output.stdout): + test_output.output.exit_code = 1 + + # TODO(ngeoffray): We run out of space on the build bots for these tests if + # the temp directories are not removed right after running the test. + if not self.context.keep_temporary_files: + self.run_arch.Cleanup() + + return test_output + + +class CompilationTestCase(test.TestCase): + """ Run the dartc compiler on a given top level dart file """ + def __init__(self, path, context, filename, mode, arch): + super(CompilationTestCase, self).__init__(context, path) + self.filename = filename + self.mode = mode + self.arch = arch + self.run_arch = run.GetArchitecture(self.arch, self.mode, + self.filename) + self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-') + + def IsNegative(self): + return False + + def GetLabel(self): + return "%s/%s %s" % (self.mode, self.arch, '/'.join(self.path)) + + def GetCommand(self): + cmd = self.context.GetDartC(self.mode, self.arch); + cmd += self.context.flags + cmd += ['-check-only', + '-fatal-type-errors', + '-Werror', + '-out', self.temp_dir, + self.filename] + + return cmd + + def GetName(self): + return self.path[-1] diff --git a/tools/testing.py b/tools/testing/test_configuration.py similarity index 72% rename from tools/testing.py rename to tools/testing/test_configuration.py index a2601a41f2b..461bffbdd02 100644 --- a/tools/testing.py +++ b/tools/testing/test_configuration.py @@ -12,12 +12,13 @@ import run import sys import tempfile +from testing import test_case import test import utils from os.path import join, exists, basename -import utils # This is tools.utils +import utils class Error(Exception): pass @@ -25,55 +26,6 @@ class Error(Exception): class TestConfigurationError(Error): pass -class StandardTestCase(test.TestCase): - def __init__(self, context, path, filename, mode, arch): - super(StandardTestCase, self).__init__(context, path) - self.filename = filename - self.mode = mode - self.arch = arch - self.run_arch = run.GetArchitecture(self.arch, self.mode, self.filename) - for flag in context.flags: - self.run_arch.vm_options.append(flag) - - def IsNegative(self): - return self.GetName().endswith("NegativeTest") - - def GetLabel(self): - return "%s%s %s" % (self.mode, self.arch, '/'.join(self.path)) - - def GetCommand(self): - return self.run_arch.GetRunCommand(); - - def GetName(self): - return self.path[-1] - - def GetPath(self): - return os.path.dirname(self.filename) - - def GetSource(self): - return file(self.filename).read() - - -class MultiTestCase(StandardTestCase): - - def __init__(self, context, path, filename, kind, mode, arch): - super(MultiTestCase, self).__init__(context, path, filename, mode, arch) - self.kind = kind - - def GetCommand(self): - return self.run_arch.GetRunCommand( - fatal_static_type_errors=(self.kind == 'static type error')); - - def IsNegative(self): - if self.kind == 'compile-time error': - return True - if self.kind == 'runtime error': - return False - if self.kind == 'static type error': - return self.run_arch.HasFatalTypeErrors() - return False - - class StandardTestConfiguration(test.TestConfiguration): LEGAL_KINDS = set(['compile-time error', 'runtime error', @@ -106,7 +58,7 @@ class StandardTestConfiguration(test.TestConfiguration): if tags: return [] else: - return [BrowserTestCase( + return [test_case.BrowserTestCase( self.context, test_path, filename, False, mode, arch)] else: tests = [] @@ -115,18 +67,11 @@ class StandardTestConfiguration(test.TestConfiguration): kind, test_source = tags[tag] if not self.Contains(path, test_path + [tag]): continue - tests.append(MultiTestCase(self.context, - test_path + [tag], - test_source, - kind, - mode, - arch)) + tests.append(test_case.MultiTestCase(self.context, + test_path + [tag], test_source, kind, mode, arch)) else: - tests.append(StandardTestCase(self.context, - test_path, - filename, - mode, - arch)) + tests.append(test_case.StandardTestCase(self.context, + test_path, filename, mode, arch)) return tests def ListTests(self, current_path, path, mode, arch): @@ -201,12 +146,15 @@ class StandardTestConfiguration(test.TestConfiguration): tests['none'] = ('', test_filename) return tests -class BrowserTestCase(StandardTestCase): +class BrowserTestCase(test_case.StandardTestCase): def __init__(self, context, path, filename, fatal_static_type_errors, mode, arch): - super(BrowserTestCase, self).__init__(context, path, filename, mode, arch) + super(test_case.BrowserTestCase, self).__init__(context, path, filename, mode, arch) self.fatal_static_type_errors = fatal_static_type_errors + def IsBatchable(self): + return True + def Run(self): command = self.run_arch.GetCompileCommand(self.fatal_static_type_errors) if command != None: @@ -253,12 +201,9 @@ class BrowserTestConfiguration(StandardTestConfiguration): test_path = current_path + relative + [os.path.splitext(f)[0]] if not self.Contains(path, test_path): continue - tests.append(BrowserTestCase(self.context, - test_path, - join(root, f), - self.fatal_static_type_errors, - mode, - arch)) + tests.append(test_case.BrowserTestCase(self.context, + test_path, join(root, f), self.fatal_static_type_errors, mode, + arch)) atexit.register(lambda: self._cleanup(tests)) return tests @@ -266,38 +211,6 @@ class BrowserTestConfiguration(StandardTestConfiguration): return name.endswith('_tests.dart') -class CompilationTestCase(test.TestCase): - """ Run the dartc compiler on a given top level dart file """ - def __init__(self, path, context, filename, mode, arch): - super(CompilationTestCase, self).__init__(context, path) - self.filename = filename - self.mode = mode - self.arch = arch - self.run_arch = run.GetArchitecture(self.arch, self.mode, - self.filename) - self.temp_dir = tempfile.mkdtemp(prefix='dartc-output-') - - def IsNegative(self): - return False - - def GetLabel(self): - return "%s/%s %s" % (self.mode, self.arch, '/'.join(self.path)) - - def GetCommand(self): - cmd = self.context.GetDartC(self.mode, self.arch); - cmd += self.context.flags - cmd += ['-check-only', - '-fatal-type-errors', - '-Werror', - '-out', self.temp_dir, - self.filename] - - return cmd - - def GetName(self): - return self.path[-1] - - class CompilationTestConfiguration(test.TestConfiguration): """ Configuration that searches specific directories for apps to compile @@ -324,7 +237,7 @@ class CompilationTestConfiguration(test.TestConfiguration): if ((not self.Contains(path, test_path)) or (not self.IsTest(test_dart_file))): continue - tests.append(CompilationTestCase(test_path, + tests.append(test_case.CompilationTestCase(test_path, self.context, test_dart_file, mode, @@ -359,7 +272,3 @@ class CompilationTestConfiguration(test.TestConfiguration): if not utils.Daemonize(): return os.execlp('rm', *(['rm', '-rf'] + [t.temp_dir for t in tests])) raise - - -def GetConfiguration(context, root): - return CompilationTestConfiguration(context, root)