diff options
author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2017-05-07 03:17:42 -0400 |
---|---|---|
committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2017-05-21 16:11:31 -0400 |
commit | 17328e7019b8b7406a82a508beedf3138ad1681b (patch) | |
tree | 60a963c62c89f38a8d1f4cdc847df002e0826187 | |
parent | b595cda4ed0ca699da3052a6bd30ba7d1dae1124 (diff) | |
download | meson-17328e7019b8b7406a82a508beedf3138ad1681b.zip meson-17328e7019b8b7406a82a508beedf3138ad1681b.tar.gz meson-17328e7019b8b7406a82a508beedf3138ad1681b.tar.bz2 |
Add coverage export for tests.
-rw-r--r-- | .coveragerc | 17 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | docs/markdown/Release-notes-for-0.41.0.md | 7 | ||||
-rwxr-xr-x | run_tests.py | 29 |
4 files changed, 47 insertions, 7 deletions
diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..a345f46 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,17 @@ +[run] +branch = True +concurrency = + multiprocessing +data_file = .coverage/coverage +parallel = True +source = + meson.py + mesonbuild/ + mesonconf.py + mesonintrospect.py + mesonrewriter.py + mesontest.py + run_cross_test.py + run_project_tests.py + run_tests.py + run_unittests.py @@ -5,6 +5,7 @@ /.idea __pycache__ +.coverage /install dir /work area diff --git a/docs/markdown/Release-notes-for-0.41.0.md b/docs/markdown/Release-notes-for-0.41.0.md index a96ded0..7da9ed7 100644 --- a/docs/markdown/Release-notes-for-0.41.0.md +++ b/docs/markdown/Release-notes-for-0.41.0.md @@ -52,7 +52,12 @@ installed. This is roughly equivalent to the `distcheck` target in other build systems. Currently this only works for projects using Git and only with the Ninja backend. - ## Support for passing arguments to Rust compiler Targets for building rust now take a `rust_args` keyword. + +## Code coverage export for tests + +Code coverage can be generated for tests by passing the `--cov` argument to +the `run_tests.py` test runner. Note, since multiple processes are used, +coverage must be combined before producing a report (`coverage3 combine`.) diff --git a/run_tests.py b/run_tests.py index 7ef9cf4..00c2595 100755 --- a/run_tests.py +++ b/run_tests.py @@ -19,6 +19,7 @@ import sys import time import shutil import subprocess +import tempfile import platform from mesonbuild import mesonlib from mesonbuild.environment import detect_ninja @@ -125,6 +126,13 @@ class FakeEnvironment(object): return False if __name__ == '__main__': + # Enable coverage early... + enable_coverage = '--cov' in sys.argv + if enable_coverage: + os.makedirs('.coverage', exist_ok=True) + sys.argv.remove('--cov') + import coverage + coverage.process_startup() returncode = 0 # Iterate over list in reverse order to find the last --backend arg backend = Backend.ninja @@ -164,10 +172,19 @@ if __name__ == '__main__': # Can't pass arguments to unit tests, so set the backend to use in the environment env = os.environ.copy() env['MESON_UNIT_TEST_BACKEND'] = backend.name - returncode += subprocess.call([sys.executable, 'run_unittests.py', '-v'] + units, env=env) - # Ubuntu packages do not have a binary without -6 suffix. - if should_run_linux_cross_tests(): - print('Running cross compilation tests.\n') - returncode += subprocess.call([sys.executable, 'run_cross_test.py', 'cross/ubuntu-armhf.txt']) - returncode += subprocess.call([sys.executable, 'run_project_tests.py'] + sys.argv[1:]) + with tempfile.TemporaryDirectory() as td: + # Enable coverage on all subsequent processes. + if enable_coverage: + with open(os.path.join(td, 'usercustomize.py'), 'w') as f: + f.write('import coverage\n' + 'coverage.process_startup()\n') + env['COVERAGE_PROCESS_START'] = '.coveragerc' + env['PYTHONPATH'] = os.pathsep.join([td] + env.get('PYTHONPATH', [])) + + returncode += subprocess.call([sys.executable, 'run_unittests.py', '-v'] + units, env=env) + # Ubuntu packages do not have a binary without -6 suffix. + if should_run_linux_cross_tests(): + print('Running cross compilation tests.\n') + returncode += subprocess.call([sys.executable, 'run_cross_test.py', 'cross/ubuntu-armhf.txt'], env=env) + returncode += subprocess.call([sys.executable, 'run_project_tests.py'] + sys.argv[1:], env=env) sys.exit(returncode) |