[android] Raise an exception when an instr test filter doesn't match a test.
BUG=662018
Review-Url: https://codereview.chromium.org/2473783004
Cr-Commit-Position: refs/heads/master@{#430763}
diff --git a/build/android/pylib/base/test_exception.py b/build/android/pylib/base/test_exception.py
new file mode 100644
index 0000000..f00f0d0e
--- /dev/null
+++ b/build/android/pylib/base/test_exception.py
@@ -0,0 +1,9 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+class TestException(Exception):
+ """Base class for exceptions thrown by the test runner."""
+ pass
+
diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance.py b/build/android/pylib/instrumentation/instrumentation_test_instance.py
index c98686a05..d393a58 100644
--- a/build/android/pylib/instrumentation/instrumentation_test_instance.py
+++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py
@@ -13,6 +13,7 @@
from devil.android import md5sum
from pylib import constants
from pylib.base import base_test_result
+from pylib.base import test_exception
from pylib.base import test_instance
from pylib.constants import host_paths
from pylib.instrumentation import test_result
@@ -52,14 +53,14 @@
_PICKLE_FORMAT_VERSION = 10
-class MissingSizeAnnotationError(Exception):
+class MissingSizeAnnotationError(test_exception.TestException):
def __init__(self, class_name):
super(MissingSizeAnnotationError, self).__init__(class_name +
': Test method is missing required size annotation. Add one of: ' +
', '.join('@' + a for a in _VALID_ANNOTATIONS))
-class ProguardPickleException(Exception):
+class ProguardPickleException(test_exception.TestException):
pass
@@ -352,6 +353,14 @@
pickle.dump(pickle_data, pickle_file)
+class UnmatchedFilterException(test_exception.TestException):
+ """Raised when a user specifies a filter that doesn't match any tests."""
+
+ def __init__(self, test_filter):
+ super(UnmatchedFilterException, self).__init__(
+ 'Test filter "%s" matched no tests.' % test_filter)
+
+
class InstrumentationTestInstance(test_instance.TestInstance):
def __init__(self, args, isolate_delegate, error_func):
@@ -654,6 +663,8 @@
tests = GetAllTests(self.test_jar)
filtered_tests = FilterTests(
tests, self._test_filter, self._annotations, self._excluded_annotations)
+ if self._test_filter and not filtered_tests:
+ raise UnmatchedFilterException(self._test_filter)
return self._ParametrizeTestsWithFlags(self._InflateTests(filtered_tests))
# pylint: disable=no-self-use
diff --git a/build/android/test_runner.pydeps b/build/android/test_runner.pydeps
index 430da87..554181d 100644
--- a/build/android/test_runner.pydeps
+++ b/build/android/test_runner.pydeps
@@ -77,6 +77,7 @@
pylib/base/environment_factory.py
pylib/base/test_collection.py
pylib/base/test_dispatcher.py
+pylib/base/test_exception.py
pylib/base/test_instance.py
pylib/base/test_instance_factory.py
pylib/base/test_run.py