|
1 |
| -# Codecov Rust Example [](https://travis-ci.org/codecov/example-rust) [](http://codecov.io/github/codecov/example-rust?branch=master) |
2 |
| - |
3 |
| -| [https://codecov.io][1] | [@codecov][2] | [[email protected]][3] | |
4 |
| -| ----------------------- | ------------- | --------------------- | |
5 |
| - |
6 |
| -This repository serves as an **example** of how to use [the Codecov global |
7 |
| -uploader][4] with Rust. |
8 |
| - |
9 |
| -Note that the coverage is deliberately incomplete. That |
10 |
| -way you can [follow the badge link][5] and see how [Codecov][1] |
11 |
| -works. You can view the code there, see hits and misses for coverage, etc. |
| 1 | +# [Codecov][1] Rust Example |
12 | 2 |
|
13 | 3 | **As of July 2, 2016, there is [no option to make rustdoc generate a runnable test executable][7]. That means that documentation tests will not show in your coverage data. If you discover a way to run the doctest executable with kcov, please open an [Issue][8] and we will add that to these instructions.**
|
14 | 4 |
|
15 |
| -## Basic Usage |
16 |
| - |
17 |
| -Run your tests with [kcov][6] in order to create the necessary coverage |
18 |
| -reports. For example: |
19 |
| - |
20 |
| -``` |
21 |
| -kcov --exclude-pattern=/.cargo,/usr/lib --verify target/cov target/debug/<PROJECT-NAME>-<hash> |
22 |
| -``` |
23 |
| - |
24 |
| -`<PROJECT-NAME>` and `<hash>` are the appropriate project name and hash for |
25 |
| -your executable. |
26 |
| - |
27 |
| -The hash at the end may change if cargo generates different test |
28 |
| -executables with the same name. If you are building your code |
29 |
| -differently or without cargo, change the last two arguments |
30 |
| -to kcov to respectively represent where you want the coverage to |
31 |
| -be stored and which executable to run. |
32 |
| - |
33 |
| -Attempting to run `kcov` with an executable argument ending in a wildcard |
34 |
| -like `<PROJECT-NAME>-*` may result in incorrect coverage results as only a |
35 |
| -single test executable will run. **For best results, run the kcov command |
36 |
| -for each test executable and store the results in separate directories.** |
37 |
| -Codecov will automatically find and upload the cobertura.xml files and |
38 |
| -merge the coverage for you. |
39 |
| - |
40 |
| -Note that setting the environment variable `RUSTFLAGS="-C link-dead-code"` |
41 |
| -during tests build may improve coverage accuracy by preventing dead-code elimination. |
42 |
| -Do not set this variable when creating release builds since it will increase |
43 |
| -binary size. |
44 |
| - |
45 |
| -After you've run the tests and created a cobertura.xml report, you can |
46 |
| -use [the Codecov global uploader][4] to push that report to Codecov. |
47 |
| -See below for further details. |
48 |
| - |
49 |
| -Installing `kcov` is largely dependent on your operating system. It is |
50 |
| -demonstrated to work on Linux systems but may not be fully compatible with |
51 |
| -Windows or OS X. Please lookup the appropriate installation instructions. |
52 |
| -The Travis CI example below demonstrates installing `kcov` on a Linux |
53 |
| -computer. |
54 |
| - |
55 |
| -The version of `kcov` that is distributed with your package manager may not |
56 |
| -work with Rust binaries. You usually need to manually build the latest |
57 |
| -master branch and run kcov from there. All of this is taken care of for you |
58 |
| -in the `.travis.yml` file below. |
59 |
| - |
60 |
| -## [](https://travis-ci.org) Travis CI |
61 |
| - |
62 |
| -### Public Repos |
63 |
| - |
64 |
| -Adjust the following example `.travis.yml` file to test with the versions |
65 |
| -of Rust you desire. |
| 5 | +## Guide |
| 6 | +### Travis Setup |
66 | 7 |
|
| 8 | +Add to your `.travis.yml` file. |
67 | 9 | ```yml
|
68 | 10 | language: rust
|
69 | 11 |
|
@@ -108,44 +50,82 @@ after_success: |
|
108 | 50 | bash <(curl -s https://codecov.io/bash) &&
|
109 | 51 | echo "Uploaded code coverage"
|
110 | 52 | ```
|
| 53 | +This will automatically run each executable and store the results in a |
| 54 | +different directory. Codecov will automatically find the `cobertura.xml` |
| 55 | +files that `kcov` generates and combine the results. |
111 | 56 |
|
112 |
| -[Codecov][1] is integrated by the following line in `after_success:`. |
| 57 | +#### Other CI services |
| 58 | +- Adjust the materials in the above example as necessary for your CI. |
| 59 | +- Add CODECOV_TOKEN=<your repo token> to your CI's environment variables. (Don't store the raw token in your repo.) |
| 60 | +- Run bash <(curl -s https://codecov.io/bash) after tests complete. |
| 61 | + |
| 62 | +### Produce Coverage Reports |
| 63 | + |
| 64 | +Run your tests with [kcov][6] in order to create the necessary coverage |
| 65 | +reports. For example: |
113 | 66 |
|
114 |
| -```yml |
115 |
| -bash <(curl -s https://codecov.io/bash) |
| 67 | +``` |
| 68 | +kcov --exclude-pattern=/.cargo,/usr/lib --verify target/cov target/debug/<PROJECT-NAME>-<hash> |
116 | 69 | ```
|
117 | 70 |
|
118 |
| -This will automatically run each executable and store the results in a |
119 |
| -different directory. Codecov will automatically find the `cobertura.xml` |
120 |
| -files that `kcov` generates and combine the results. |
| 71 | +`<PROJECT-NAME>` and `<hash>` are the appropriate project name and hash for |
| 72 | +your executable. |
121 | 73 |
|
122 |
| -### Private Repos |
| 74 | +The hash at the end may change if cargo generates different test |
| 75 | +executables with the same name. If you are building your code |
| 76 | +differently or without cargo, change the last two arguments |
| 77 | +to kcov to respectively represent where you want the coverage to |
| 78 | +be stored and which executable to run. |
123 | 79 |
|
124 |
| -Add to your `.travis.yml` file. |
| 80 | +Attempting to run `kcov` with an executable argument ending in a wildcard |
| 81 | +like `<PROJECT-NAME>-*` may result in incorrect coverage results as only a |
| 82 | +single test executable will run. **For best results, run the kcov command |
| 83 | +for each test executable and store the results in separate directories.** |
| 84 | +Codecov will automatically find and upload the cobertura.xml files and |
| 85 | +merge the coverage for you. |
| 86 | + |
| 87 | +Note that setting the environment variable `RUSTFLAGS="-C link-dead-code"` |
| 88 | +during tests build may improve coverage accuracy by preventing dead-code elimination. |
| 89 | +Do not set this variable when creating release builds since it will increase |
| 90 | +binary size. |
125 | 91 |
|
| 92 | +After you've run the tests and created a cobertura.xml report, you can |
| 93 | +use [the Codecov global uploader][4] to push that report to Codecov. |
| 94 | +See below for further details. |
| 95 | + |
| 96 | +Installing `kcov` is largely dependent on your operating system. It is |
| 97 | +demonstrated to work on Linux systems but may not be fully compatible with |
| 98 | +Windows or OS X. Please lookup the appropriate installation instructions. |
| 99 | +The Travis CI example below demonstrates installing `kcov` on a Linux |
| 100 | +computer. |
| 101 | + |
| 102 | +## Caveats |
| 103 | +### Private Repos |
| 104 | +Add to your `.travis.yml` file. |
126 | 105 | ```yml
|
127 |
| -env: |
128 |
| - global: |
129 |
| - - CODECOV_TOKEN=:uuid-repo-token |
| 106 | +after_success: |
| 107 | + - bash <(curl -s https://codecov.io/bash) -t uuid-repo-token |
130 | 108 | ```
|
| 109 | +### `kcov` Version |
| 110 | + |
| 111 | +The version of `kcov` that is distributed with your package manager may not |
| 112 | +work with Rust binaries. You usually need to manually build the latest |
| 113 | +master branch and run kcov from there. All of this is taken care of for you |
| 114 | +in the `.travis.yml` file. |
| 115 | +## Support |
131 | 116 |
|
132 |
| -## Other CI services |
| 117 | +### Contact |
| 118 | +- Intercom (in-app messanger) |
| 119 | + |
| 120 | +- Slack: [slack.codecov.io](https://slack.codecov.io) |
| 121 | +- [gh/codecov/support](https://github.com/codecov/support) |
133 | 122 |
|
134 |
| -+ Adjust the materials in the above example as necessary for |
135 |
| - your CI. |
136 |
| -+ Add `CODECOV_TOKEN=<your repo token>` to your CI's environment variables. |
137 |
| - (Don't store the raw token in your repo.) |
138 |
| -+ Run `bash <(curl -s https://codecov.io/bash)` after tests complete. |
| 123 | +1. More documentation at https://docs.codecov.io |
| 124 | +2. Configure codecov through the `codecov.yml` https://docs.codecov.io/docs/codecov-yaml |
139 | 125 |
|
140 |
| -## More details |
141 | 126 |
|
142 |
| -Visit [the global uploader's repo][4] to view its source and |
143 |
| -learn more about the script. |
144 | 127 |
|
145 |
| -[1]: https://codecov.io |
146 |
| -[2]: https://twitter.com/codecov |
147 |
| - |
148 |
| -[4]: https://github.com/codecov/codecov-bash |
| 128 | +[1]: https://codecov.io/ |
149 | 129 | [5]: http://codecov.io/github/codecov/example-rust?branch=master
|
150 | 130 | [6]: https://simonkagstrom.github.io/kcov/
|
151 | 131 | [7]: http://stackoverflow.com/questions/35547710/does-rustdoc-generate-runnable-binaries
|
|
0 commit comments