summaryrefslogtreecommitdiffstats
path: root/tools/code_coverage/coverage_posix_unittest.py
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 04:46:23 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 04:46:23 +0000
commit862194135cffb729a7938cde3ec042e29bc50ffc (patch)
treecd3579682e2fd6a5e17c31643565f43df5c3dcbe /tools/code_coverage/coverage_posix_unittest.py
parentd0b8e5f9bff9553c75bf78bdebeff855db03ebc9 (diff)
downloadchromium_src-862194135cffb729a7938cde3ec042e29bc50ffc.zip
chromium_src-862194135cffb729a7938cde3ec042e29bc50ffc.tar.gz
chromium_src-862194135cffb729a7938cde3ec042e29bc50ffc.tar.bz2
Split coverage into build and run phases in preparation for splitting
it into 2 distinct buildbot phases. Add changes to reduce size or increase speed of coverage builds. Add 'bundle files' mechanism to process_coverage.py to make the above split easier. Add unit test for said mechanism. TEST=build coverage on 10.6 and watch it work. Review URL: http://codereview.chromium.org/2121003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/code_coverage/coverage_posix_unittest.py')
-rwxr-xr-xtools/code_coverage/coverage_posix_unittest.py58
1 files changed, 57 insertions, 1 deletions
diff --git a/tools/code_coverage/coverage_posix_unittest.py b/tools/code_coverage/coverage_posix_unittest.py
index e7ae155..9eee129 100755
--- a/tools/code_coverage/coverage_posix_unittest.py
+++ b/tools/code_coverage/coverage_posix_unittest.py
@@ -3,16 +3,52 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Unit tests for coverage_posix.py."""
+"""Unit tests for coverage_posix.py.
+
+Run a single test with a command such as:
+ ./coverage_posix_unittest.py CoveragePosixTest.testFindTestsAsArgs
+
+Waring that running a single test like that may interfere with the arg
+parsing tests, since coverage_posix.py uses optparse.OptionParser()
+which references globals.
+"""
import coverage_posix as coverage
+import os
import sys
+import tempfile
import unittest
class CoveragePosixTest(unittest.TestCase):
+
def setUp(self):
self.parseArgs()
+ self.sample_test_names = ['zippy_tests', '../base/base.gyp:base_unittests']
+
+ def confirmSampleTestsArePresent(self, tests):
+ """Confirm the tests in self.sample_test_names are in some form in 'tests'.
+
+ The Coverage object can munge them (e.g. add .exe to the end as needed.
+ Helper function for arg parsing, bundle file tests.
+
+ Args:
+ tests: the parsed tests from a Coverage object.
+ """
+ for simple_test_name in ('zippy_tests', 'base_unittests'):
+ found = False
+ for item in tests:
+ if simple_test_name in item:
+ found = True
+ break
+ self.assertTrue(found)
+ for not_test_name in ('kablammo', 'not_a_unittest'):
+ found = False
+ for item in tests:
+ if not_test_name in item:
+ found = True
+ break
+ self.assertFalse(found)
def parseArgs(self):
"""Setup and process arg parsing."""
@@ -67,6 +103,26 @@ class CoveragePosixTest(unittest.TestCase):
c.Run,
[sys.executable, '-u', '-c', slowscript])
+ def testFindTestsAsArgs(self):
+ """Test finding of tests passed as args."""
+ self.args += '--'
+ self.args += self.sample_test_names
+ c = coverage.Coverage('.', self.options, self.args)
+ c.FindTests()
+ self.confirmSampleTestsArePresent(c.tests)
+
+ def testFindTestsFromBundleFile(self):
+ """Test finding of tests from a bundlefile."""
+ (fd, filename) = tempfile.mkstemp()
+ f = os.fdopen(fd, 'w')
+ f.write(str(self.sample_test_names))
+ f.close()
+ self.options.bundles = filename
+ c = coverage.Coverage('.', self.options, self.args)
+ c.FindTests()
+ self.confirmSampleTestsArePresent(c.tests)
+ os.unlink(filename)
+
if __name__ == '__main__':
unittest.main()