Skip to content

Commit 9d218bf

Browse files
Merge pull request RustPython#485 from calixteman/ccov
Code coverage for RustPython
2 parents a92f4bb + 6d646cc commit 9d218bf

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ matrix:
3232
env:
3333
- TRAVIS_RUST_VERSION=stable
3434
- REGULAR_TEST=false
35+
- CODE_COVERAGE=false
3536
script: tests/.travis-runner.sh
3637
- language: python
3738
python: 3.6
@@ -45,6 +46,7 @@ matrix:
4546
env:
4647
- TRAVIS_RUST_VERSION=beta
4748
- REGULAR_TEST=false
49+
- CODE_COVERAGE=false
4850
script: tests/.travis-runner.sh
4951
- name: rustfmt
5052
language: rust
@@ -97,6 +99,22 @@ matrix:
9799
- cargo clippy
98100
env:
99101
- REGULAR_TEST=true
102+
- name: Code Coverage
103+
language: python
104+
python: 3.6
105+
cache:
106+
pip: true
107+
# Because we're using the Python Travis environment, we can't use
108+
# the built-in cargo cacher
109+
directories:
110+
- /home/travis/.cargo
111+
- target
112+
script:
113+
- tests/.travis-runner.sh
114+
env:
115+
- TRAVIS_RUST_VERSION=nightly
116+
- REGULAR_TEST=false
117+
- CODE_COVERAGE=true
100118
allow_failures:
101119
- rust: nightly
102120
env: REGULAR_TEST=true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A Python-3 (CPython >= 3.5.0) Interpreter written in Rust :snake: :scream: :metal:.
44

55
[![Build Status](https://travis-ci.org/RustPython/RustPython.svg?branch=master)](https://travis-ci.org/RustPython/RustPython)
6+
[![codecov](https://codecov.io/gh/RustPython/RustPython/branch/master/graph/badge.svg)](https://codecov.io/gh/mozilla/RustPython/RustPython)
67
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
78
[![Contributors](https://img.shields.io/github/contributors/RustPython/RustPython.svg)](https://github.com/RustPython/RustPython/graphs/contributors)
89
[![Gitter](https://badges.gitter.im/RustPython/Lobby.svg)](https://gitter.im/rustpython/Lobby)

tests/.travis-runner.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,30 @@ pip install pipenv
1010
(cd tests; pipenv install)
1111

1212
# Build outside of the test runner
13-
cargo build --verbose --release
13+
if [ $CODE_COVERAGE = "true" ]
14+
then
15+
export CARGO_INCREMENTAL=0
16+
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zno-landing-pads"
17+
18+
cargo build --verbose
19+
else
20+
cargo build --verbose --release
21+
fi
1422

1523
# Run the tests
1624
(cd tests; pipenv run pytest)
25+
26+
if [ $CODE_COVERAGE = "true" ]
27+
then
28+
cargo test --verbose --all
29+
zip -0 ccov.zip `find . \( -name "rustpython*.gc*" \) -print`
30+
31+
# Install grcov
32+
curl -L https://github.com/mozilla/grcov/releases/download/v0.4.1/grcov-linux-x86_64.tar.bz2 | tar jxf -
33+
34+
./grcov ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore-dir "/*" -p "x" > lcov.info
35+
36+
# Install codecov.io reporter
37+
curl -s https://codecov.io/bash -o codecov.sh
38+
bash codecov.sh -f lcov.info
39+
fi

tests/test_snippets.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ def run_via_rustpython(filename, test_type):
7777
log_level = 'info' if test_type == _TestType.benchmark else 'trace'
7878
env['RUST_LOG'] = '{},cargo=error,jobserver=error'.format(log_level)
7979
env['RUST_BACKTRACE'] = '1'
80-
subprocess.check_call(
81-
['cargo', 'run', '--release', filename], env=env)
80+
if env.get('CODE_COVERAGE', 'false') == 'true':
81+
subprocess.check_call(
82+
['cargo', 'run', filename], env=env)
83+
else:
84+
subprocess.check_call(
85+
['cargo', 'run', '--release', filename], env=env)
8286

8387

8488
def create_test_function(cls, filename, method, test_type):

0 commit comments

Comments
 (0)