Skip to content

Commit

Permalink
Release 0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xd009642 committed Jun 25, 2020
2 parents 5ad0b99 + 4cca612 commit 742eb7d
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
components: rustfmt
- name: clean
run: cargo clean
- name: check formatting
run: cargo fmt -- --check
- name: build
run: cargo build --verbose
env:
Expand All @@ -40,6 +38,8 @@ jobs:
env:
RUST_BACKTRACE: 1
if: matrix.version == 'nightly'
- name: check formatting
run: cargo fmt -- --check
- name: notify docker hub
run: |
curl --request POST \
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
From 2019 onwards, all notable changes to tarpaulin will be documented in this
file.

## [Unreleased]
## [0.14.0] - 2020-06-25
### Added
- Filtering for `cfg(not(tarpaulin_include))` also adding `--cfg=tarpaulin` to default config
- Support for tool attribute `#[tarpaulin::skip]`

### Changed

### Removed

# [0.13.4] - 2020-06-23
# [0.13.4] - 2020-06-23 [YANKED]
### Added
- Add `--cfg=tarpaulin` to `RUSTFLAGS` this allows users to use
`#[cfg(tarpaulin)]` and `#[cfg(not(tarpaulin))]`
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-tarpaulin"
version = "0.13.4"
version = "0.14.0"
authors = ["Daniel McKenna <[email protected]>"]
description = "Cargo-Tarpaulin is a tool to determine code coverage achieved via tests"
repository = "https://github.com/xd009642/tarpaulin"
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Below is the help-text for a thorough explanation of the flags and features
available:

```bash
cargo-tarpaulin version: 0.13.4
cargo-tarpaulin version: 0.14.0
Tool to analyse test coverage of cargo projects

USAGE:
Expand Down Expand Up @@ -205,11 +205,15 @@ my crate [keygraph-rs](https://github.com/xd009642/keygraph-rs).
### Ignoring code in files
Tarpaulin now allows you to ignore modules or functions using config attributes.
Before tarpaulin 0.13.4 you could ignore code in blocks with
`#[cfg_attr(tarpaulin, skip)]` this has changed with 0.13.4 and onwards
and the new instructions are described below.
Tarpaulin allows you to ignore modules or functions using attributes.
Below is an example of ignoring the main function in a project:
```Rust
#[cfg_attr(tarpaulin, skip)]
#[cfg(not(tarpaulin_include))]
fn main() {
println!("I won't be included in results");
}
Expand Down Expand Up @@ -241,6 +245,19 @@ fn ignored_by_tarpaulin() {
}
```
There is also nightly support for using tool attributes with tarpaulin for
skip. For example:
```Rust
#![feature(register_tool)]
#![register_tool(tarpaulin)]
#[tarpaulin::skip]
fn main() {
println!("I won't be in coverage stats");
}
```
### Continuous Integration Services
Tarpaulin aims to be easy to add to your CI workflow. With well tested support
Expand Down
56 changes: 26 additions & 30 deletions src/source_analysis/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,41 @@ pub(crate) fn check_attr_list(
pub(crate) fn check_cfg_attr(attr: &Meta) -> bool {
let mut ignore_span = false;
let id = attr.path();
if id.is_ident("cfg_attr") {
if let Meta::List(ml) = attr {
let mut skip_match = false;
let mut found_tarpaulin = false;
for p in ml.nested.iter() {
match p {
NestedMeta::Meta(Meta::Path(ref i)) => {
if !found_tarpaulin {
skip_match = i.is_ident("tarpaulin");
found_tarpaulin |= skip_match;
} else {
skip_match = i.is_ident("skip");
}
}
_ => skip_match = false,
}
if !skip_match {
break;
}
}
ignore_span = skip_match;
}
} else if id.is_ident("cfg") {
if id.is_ident("cfg") {
if let Meta::List(ml) = attr {
'outer: for p in ml.nested.iter() {
if let NestedMeta::Meta(Meta::List(ref i)) = p {
if i.path.is_ident("not") {
for n in i.nested.iter() {
if let NestedMeta::Meta(Meta::Path(ref pth)) = n {
if pth.is_ident("tarpaulin") {
ignore_span = true;
break 'outer;
match p {
NestedMeta::Meta(Meta::List(ref i)) => {
if i.path.is_ident("not") {
for n in i.nested.iter() {
if let NestedMeta::Meta(Meta::Path(ref pth)) = n {
if pth.is_ident("tarpaulin_include")
|| pth.is_ident("tarpaulin")
{
ignore_span = true;
break 'outer;
}
}
}
}
}
_ => {}
}
}
}
} else {
let skip_attrs = vec!["tarpaulin", "skip"];
let mut n = 0;
ignore_span = true;
for (segment, attr) in id.segments.iter().zip(skip_attrs.iter()) {
n += 1;
if segment.ident != attr {
ignore_span = false;
}
}
if n < skip_attrs.len() {
ignore_span = false;
}
}
ignore_span
}
19 changes: 13 additions & 6 deletions src/source_analysis/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ fn tarpaulin_skip_attr() {
let mut lines = LineAnalysis::new();
let ctx = Context {
config: &config,
file_contents: "#[cfg_attr(tarpaulin, skip)]
file_contents: "#[cfg(not(tarpaulin_include))]
fn skipped() {
println!(\"Hello world\");
}
Expand All @@ -734,6 +734,11 @@ fn tarpaulin_skip_attr() {
fn uncovered() {
println!(\"goodbye world\");
}
#[tarpaulin::skip]
fn uncovered2() {
println!(\"oof\");
}
",
file: Path::new(""),
ignore_mods: RefCell::new(HashSet::new()),
Expand All @@ -746,11 +751,13 @@ fn tarpaulin_skip_attr() {
assert!(!lines.ignore.contains(&Lines::Line(8)));
assert!(lines.ignore.contains(&Lines::Line(12)));
assert!(lines.ignore.contains(&Lines::Line(13)));
assert!(lines.ignore.contains(&Lines::Line(17)));
assert!(lines.ignore.contains(&Lines::Line(18)));

let mut lines = LineAnalysis::new();
let ctx = Context {
config: &config,
file_contents: "#[cfg_attr(tarpaulin, skip)]
file_contents: "#[cfg(not(tarpaulin_include))]
mod ignore_all {
fn skipped() {
println!(\"Hello world\");
Expand Down Expand Up @@ -779,7 +786,7 @@ fn tarpaulin_skip_trait_attrs() {
let mut lines = LineAnalysis::new();
let ctx = Context {
config: &config,
file_contents: "#[cfg_attr(tarpaulin, skip)]
file_contents: "#[cfg(not(tarpaulin_include))]
trait Foo {
fn bar() {
println!(\"Hello world\");
Expand Down Expand Up @@ -809,7 +816,7 @@ fn tarpaulin_skip_trait_attrs() {
println!(\"Hello world\");
}
#[cfg_attr(tarpaulin, skip)]
#[tarpaulin::skip]
fn not_covered() {
println!(\"hell world\");
}
Expand All @@ -833,7 +840,7 @@ fn tarpaulin_skip_impl_attrs() {
let ctx = Context {
config: &config,
file_contents: "struct Foo;
#[cfg_attr(tarpaulin, skip)]
#[tarpaulin::skip]
impl Foo {
fn bar() {
println!(\"Hello world\");
Expand Down Expand Up @@ -865,7 +872,7 @@ fn tarpaulin_skip_impl_attrs() {
}
#[cfg_attr(tarpaulin, skip)]
#[cfg(not(tarpaulin_include))]
fn not_covered() {
println!(\"hell world\");
}
Expand Down
5 changes: 5 additions & 0 deletions tests/data/tarpaulin_attrs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/data/tarpaulin_attrs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "tarpaulin_attrs"
version = "0.1.0"
authors = ["xd009642 <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
20 changes: 20 additions & 0 deletions tests/data/tarpaulin_attrs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@



#[test]
#[cfg_attr(tarpaulin, ignore)]
fn it_works() {
assert_eq!(2 + 2, 4);
}

#[test]
#[cfg(not(tarpaulin))]
fn it_works2() {
assert_eq!(2 + 2, 4);
}

#[test]
#[cfg(not(tarpaulin_include))]
fn it_works2() {
assert_eq!(2 + 2, 4);
}
5 changes: 5 additions & 0 deletions tests/data/tool_attr/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/data/tool_attr/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "tool_attr"
version = "0.1.0"
authors = ["xd009642 <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
7 changes: 7 additions & 0 deletions tests/data/tool_attr/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(register_tool)]
#![register_tool(tarpaulin)]

#[tarpaulin::skip]
fn main() {
println!("Hello, world!");
}
25 changes: 19 additions & 6 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ pub fn check_percentage_with_config(
let (res, _) = launch_tarpaulin(&config).unwrap();

env::set_current_dir(restore_dir).unwrap();
assert!(
res.coverage_percentage() >= minimum_coverage,
"Assertion failed {} >= {}",
res.coverage_percentage(),
minimum_coverage
);
if has_lines {
assert!(res.total_coverable() > 0);
assert!(
res.coverage_percentage() >= minimum_coverage,
"Assertion failed {} >= {}",
res.coverage_percentage(),
minimum_coverage
);
} else {
assert_eq!(res.total_coverable(), 0);
}
}

Expand Down Expand Up @@ -204,3 +206,14 @@ fn access_env_var() {
let test = "env_var";
check_percentage(test, 1.0f64, true);
}

#[test]
fn tarpaulin_attrs() {
check_percentage("tarpaulin_attrs", 0.0f64, true);
}

#[test]
#[cfg(nightly)]
fn tarpaulin_tool_attr() {
check_percentage("tool_attr", 0.0f64, false);
}
2 changes: 1 addition & 1 deletion travis-install.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
curl -sL https://github.com/xd009642/tarpaulin/releases/download/0.13.4/cargo-tarpaulin-0.13.4-travis.tar.gz | tar xvz -C $HOME/.cargo/bin
curl -sL https://github.com/xd009642/tarpaulin/releases/download/0.14.0/cargo-tarpaulin-0.14.0-travis.tar.gz | tar xvz -C $HOME/.cargo/bin

0 comments on commit 742eb7d

Please sign in to comment.