1 # Copyright (C) 2012 Google, Inc. 2 # 3 # Redistribution and use in source and binary forms, with or without 4 # modification, are permitted provided that the following conditions 5 # are met: 6 # 1. Redistributions of source code must retain the above copyright 7 # notice, this list of conditions and the following disclaimer. 8 # 2. Redistributions in binary form must reproduce the above copyright 9 # notice, this list of conditions and the following disclaimer in the 10 # documentation and/or other materials provided with the distribution. 11 # 12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 13 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR 16 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 18 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 19 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 20 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 23 import logging 24 import sys 25 import webkitpy.thirdparty.unittest2 as unittest 26 import StringIO 27 28 from webkitpy.common.system.filesystem import FileSystem 29 from webkitpy.common.system.executive import Executive 30 from webkitpy.common.system.outputcapture import OutputCapture 31 from webkitpy.test.main import Tester, _Loader 32 33 34 STUBS_CLASS = __name__ + ".TestStubs" 35 36 37 class TestStubs(unittest.TestCase): 38 def test_empty(self): 39 pass 40 41 def integration_test_empty(self): 42 pass 43 44 def serial_test_empty(self): 45 pass 46 47 def serial_integration_test_empty(self): 48 pass 49 50 51 class TesterTest(unittest.TestCase): 52 53 def test_no_tests_found(self): 54 tester = Tester() 55 errors = StringIO.StringIO() 56 57 # Here we need to remove any existing log handlers so that they 58 # don't log the messages webkitpy.test while we're testing it. 59 root_logger = logging.getLogger() 60 root_handlers = root_logger.handlers 61 root_logger.handlers = [] 62 63 tester.printer.stream = errors 64 tester.finder.find_names = lambda args, run_all: [] 65 oc = OutputCapture() 66 try: 67 oc.capture_output() 68 self.assertFalse(tester.run()) 69 finally: 70 _, _, logs = oc.restore_output() 71 root_logger.handlers = root_handlers 72 73 self.assertIn('No tests to run', errors.getvalue()) 74 self.assertIn('No tests to run', logs) 75 76 def _find_test_names(self, args): 77 tester = Tester() 78 tester._options, args = tester._parse_args(args) 79 return tester._test_names(_Loader(), args) 80 81 def test_individual_names_are_not_run_twice(self): 82 args = [STUBS_CLASS + '.test_empty'] 83 parallel_tests, serial_tests = self._find_test_names(args) 84 self.assertEqual(parallel_tests, args) 85 self.assertEqual(serial_tests, []) 86 87 def test_integration_tests_are_not_found_by_default(self): 88 parallel_tests, serial_tests = self._find_test_names([STUBS_CLASS]) 89 self.assertEqual(parallel_tests, [ 90 STUBS_CLASS + '.test_empty', 91 ]) 92 self.assertEqual(serial_tests, [ 93 STUBS_CLASS + '.serial_test_empty', 94 ]) 95 96 def test_integration_tests_are_found(self): 97 parallel_tests, serial_tests = self._find_test_names(['--integration-tests', STUBS_CLASS]) 98 self.assertEqual(parallel_tests, [ 99 STUBS_CLASS + '.integration_test_empty', 100 STUBS_CLASS + '.test_empty', 101 ]) 102 self.assertEqual(serial_tests, [ 103 STUBS_CLASS + '.serial_integration_test_empty', 104 STUBS_CLASS + '.serial_test_empty', 105 ]) 106 107 def integration_test_coverage_works(self): 108 filesystem = FileSystem() 109 executive = Executive() 110 module_path = filesystem.path_to_module(self.__module__) 111 script_dir = module_path[0:module_path.find('webkitpy') - 1] 112 proc = executive.popen([sys.executable, filesystem.join(script_dir, 'test-webkitpy'), '-c', STUBS_CLASS + '.test_empty'], 113 stdout=executive.PIPE, stderr=executive.PIPE) 114 out, _ = proc.communicate() 115 retcode = proc.returncode 116 self.assertEqual(retcode, 0) 117 self.assertIn('Cover', out) 118