Skip to content

Commit

Permalink
Added test for doc coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
xd009642 committed Mar 10, 2019
1 parent c4cde1a commit f32c4aa
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod parse;
mod types;

/// Specifies the current configuration tarpaulin is using.
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct Config {
/// Path to the projects cargo manifest
pub manifest: PathBuf,
Expand Down Expand Up @@ -72,6 +72,40 @@ pub struct Config {
pub release: bool,
}

impl Default for Config {

fn default() -> Config {
Config {
run_types: vec![RunType::Tests],
manifest: Default::default(),
run_ignored: false,
ignore_tests: false,
ignore_panics: false,
force_clean: false,
verbose: false,
debug: false,
count: false,
line_coverage: true,
branch_coverage: false,
generate: vec![],
coveralls: None,
ci_tool: None,
report_uri: None,
forward_signals: false,
no_default_features: false,
features: vec![],
all: false,
packages: vec![],
exclude: vec![],
excluded_files: vec![],
varargs: vec![],
test_timeout: Duration::from_secs(60),
release: false,
all_features: false,
}
}
}

impl<'a> From<&'a ArgMatches<'a>> for Config {
fn from(args: &'a ArgMatches<'a>) -> Self {
Config {
Expand Down
6 changes: 6 additions & 0 deletions tests/data/doc_coverage/Cargo.lock

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

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

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



///This is a doc comment
/// ```
/// use doc_coverage::uncovered_by_tests;
/// assert_eq!(4, uncovered_by_tests(4));
/// ```
pub fn uncovered_by_tests(x: i32) -> i32 {
let y = x.pow(2);
y / x
}
34 changes: 34 additions & 0 deletions tests/doc_coverage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use cargo_tarpaulin::config::{Config, RunType};
use cargo_tarpaulin::launch_tarpaulin;
use std::env;
use std::time::Duration;

#[test]
fn doc_test_coverage() {
let mut config = Config::default();
config.verbose = true;
config.test_timeout = Duration::from_secs(60);
let mut test_dir = env::current_dir().unwrap();
test_dir.push("tests");
test_dir.push("data");
test_dir.push("doc_coverage");
env::set_current_dir(test_dir.clone()).unwrap();
config.manifest = test_dir.clone();
config.manifest.push("Cargo.toml");

config.run_types = vec![RunType::Doctests];

let (res, ret) = launch_tarpaulin(&config).unwrap();

assert_eq!(ret, 0);
assert!(res.total_covered() > 0);
assert_eq!(res.total_covered(), res.total_coverable());

config.run_types = vec![RunType::Tests];

let (res, ret) = launch_tarpaulin(&config).unwrap();

assert_eq!(ret, 0);
assert_eq!(res.total_covered(), 0);

}

0 comments on commit f32c4aa

Please sign in to comment.