Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xd009642 committed Jul 10, 2020
2 parents c0af8c8 + 0d3e20a commit eb9dc9f
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 73 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ file.

### Removed

## [0.14.2]
### Added
- Added `--all-targets` to config file

### Changed
- Actually pass `--all-targets` to cargo
- Merge more CLI options with active config (no-run, no-default-features,
ignore-panics, forward-signals, run-ignored, release, count, all-features,
all-targets, line-coverage, branch-coverage, offline, timeout, features,
out, arguments passed to test executable, -Z)
- Update stats for all traces when they match a single address
- Correct handling of doc tests in workspaces as doctest name is relative to
package root not workspace root
- Return an error if a doctest fails to compile
- Include files with no coverable lines in Html report
- `--ignore-panics` now ignores `assert_*` and `debug_assert*` macros

### Removed

## [0.14.1] - 2020-07-01
### Added
- run-types for lib, bins and all-targets
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-tarpaulin"
version = "0.14.1"
version = "0.14.2"
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 All @@ -26,12 +26,12 @@ clap = "2.33.1"
coveralls-api = "0.5.0"
env_logger = "0.7"
fallible-iterator = "0.2.0"
gimli = "0.21.0"
gimli = "0.22.0"
git2 = "0.13"
humantime-serde = "1"
indexmap = { version = "1.4.0", features = ["serde-1"] }
lazy_static = "1.0"
libc = "0.2.71"
libc = "0.2.72"
log = "0.4.8"
memmap = "0.7.0"
nix = "0.17.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ want to run it locally, e.g. during development. See below for how to do that.
Below is the help-text for a thorough explanation of the flags and features
available:

```bash
cargo-tarpaulin version: 0.14.1
```
cargo-tarpaulin version: 0.14.2
Tool to analyse test coverage of cargo projects
USAGE:
Expand Down
22 changes: 16 additions & 6 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::path_utils::get_source_walker;
use cargo_metadata::{diagnostic::DiagnosticLevel, CargoOpt, Message, Metadata, MetadataCommand};
use log::{error, trace, warn};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::env;
use std::fs::{read_dir, remove_dir_all, File};
use std::io;
Expand Down Expand Up @@ -184,6 +184,7 @@ fn run_cargo(
.map_err(|e| RunError::Cargo(e.to_string()))?;
if !out.status.success() {
error!("Building doctests failed");
return Err(RunError::Cargo("Building doctest failed".to_string()));
}
let walker = WalkDir::new(&config.doctest_dir()).into_iter();
let dir_entries = walker
Expand Down Expand Up @@ -217,7 +218,7 @@ fn convert_to_prefix(p: &Path) -> Option<String> {

fn is_prefix_match(prefix: &str, entry: &Path) -> bool {
convert_to_prefix(entry)
.map(|s| prefix.starts_with(&s))
.map(|s| s.ends_with(prefix))
.unwrap_or(false)
}

Expand All @@ -232,6 +233,7 @@ fn is_prefix_match(prefix: &str, entry: &Path) -> bool {
/// that any matching file is good because we can't do any better
fn get_panic_candidates(tests: &[DirEntry], config: &Config) -> HashMap<String, Vec<usize>> {
let mut result = HashMap::new();
let mut checked_files = HashSet::new();
let root = config.root();
for test in tests {
if let Some(test_binary) = DocTestBinaryMeta::new(test.path()) {
Expand All @@ -240,13 +242,18 @@ fn get_panic_candidates(tests: &[DirEntry], config: &Config) -> HashMap<String,
if path.is_file() {
if let Some(p) = path_relative_from(path, &root) {
if is_prefix_match(&test_binary.prefix, &p) {
let prefix = convert_to_prefix(&p).unwrap_or_default();
if !result.contains_key(&prefix) {
if !checked_files.contains(path) {
checked_files.insert(path.to_path_buf());
trace!("Assessing {} for `should_panic` doctests", path.display());
let lines = find_panics_in_file(path).unwrap_or_default();
result.insert(prefix, lines);
if !result.contains_key(&test_binary.prefix) {
result.insert(test_binary.prefix.clone(), lines);
} else if let Some(current_lines) =
result.get_mut(&test_binary.prefix)
{
current_lines.extend_from_slice(&lines);
}
}
break;
}
}
}
Expand Down Expand Up @@ -349,6 +356,9 @@ fn init_args(test_cmd: &mut Command, config: &Config) {
test_cmd.arg("--features");
test_cmd.arg(features);
}
if config.all_targets {
test_cmd.arg("--all-targets");
}
if config.all_features {
test_cmd.arg("--all-features");
}
Expand Down
60 changes: 59 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub struct Config {
/// Flag to add a clean step when preparing the target project
#[serde(rename = "force-clean")]
pub force_clean: bool,
#[serde(rename = "all-targets")]
pub all_targets: bool,
/// Verbose flag for printing information to the user
pub verbose: bool,
/// Debug flag for printing internal debugging information to the user
Expand Down Expand Up @@ -152,6 +154,10 @@ pub struct Config {
pub metadata: RefCell<Option<Metadata>>,
}

fn default_test_timeout() -> Duration {
Duration::from_secs(60)
}

impl Default for Config {
fn default() -> Config {
Config {
Expand All @@ -161,6 +167,7 @@ impl Default for Config {
config: None,
root: Default::default(),
run_ignored: false,
all_targets: false,
ignore_tests: false,
ignore_panics: false,
force_clean: false,
Expand All @@ -185,7 +192,7 @@ impl Default for Config {
excluded_files: RefCell::new(vec![]),
excluded_files_raw: vec![],
varargs: vec![],
test_timeout: Duration::from_secs(60),
test_timeout: default_test_timeout(),
release: false,
all_features: false,
no_run: false,
Expand Down Expand Up @@ -231,6 +238,7 @@ impl<'a> From<&'a ArgMatches<'a>> for ConfigWrapper {
ignore_panics: args.is_present("ignore-panics"),
force_clean: args.is_present("force-clean"),
no_fail_fast: args.is_present("no-fail-fast"),
all_targets: args.is_present("all-targets"),
verbose,
debug,
dump_traces,
Expand Down Expand Up @@ -431,7 +439,19 @@ impl Config {
} else if other.verbose {
self.verbose = other.verbose;
}
self.no_run |= other.no_run;
self.no_default_features |= other.no_default_features;
self.ignore_panics |= other.ignore_panics;
self.forward_signals |= other.forward_signals;
self.run_ignored |= other.run_ignored;
self.release |= other.release;
self.count |= other.count;
self.all_features |= other.all_features;
self.all_targets |= other.all_targets;
self.line_coverage |= other.line_coverage;
self.branch_coverage |= other.branch_coverage;
self.dump_traces |= other.dump_traces;
self.offline |= other.offline;
self.manifest = other.manifest.clone();
self.root = Config::pick_optional_config(&self.root, &other.root);
self.coveralls = Config::pick_optional_config(&self.coveralls, &other.coveralls);
Expand All @@ -448,9 +468,21 @@ impl Config {
self.ignore_tests |= other.ignore_tests;
self.no_fail_fast |= other.no_fail_fast;

if other.test_timeout != default_test_timeout() {
self.test_timeout = other.test_timeout.clone();
}

if self.profile.is_none() && other.profile.is_some() {
self.profile = other.profile.clone();
}
if other.features.is_some() {
if self.features.is_none() {
self.features = other.features.clone();
} else if let Some(features) = self.features.as_mut() {
features.push(' ');
features.push_str(other.features.as_ref().unwrap());
}
}

let additional_packages = other
.packages
Expand All @@ -460,6 +492,14 @@ impl Config {
.collect::<Vec<String>>();
self.packages.extend(additional_packages);

let additional_outs = other
.generate
.iter()
.filter(|out| !self.generate.contains(out))
.copied()
.collect::<Vec<_>>();
self.generate.extend(additional_outs);

let additional_excludes = other
.exclude
.iter()
Expand All @@ -468,6 +508,22 @@ impl Config {
.collect::<Vec<String>>();
self.exclude.extend(additional_excludes);

let additional_varargs = other
.varargs
.iter()
.filter(|package| !self.varargs.contains(package))
.cloned()
.collect::<Vec<String>>();
self.varargs.extend(additional_varargs);

let additional_z_opts = other
.unstable_features
.iter()
.filter(|package| !self.unstable_features.contains(package))
.cloned()
.collect::<Vec<String>>();
self.unstable_features.extend(additional_z_opts);

let exclude = &self.exclude;
self.packages.retain(|package| {
let keep = !exclude.contains(package);
Expand Down Expand Up @@ -964,13 +1020,15 @@ mod tests {
no-fail-fast = true
profile = "Release"
dump-traces = true
all-targets = true
"#;
let mut configs = Config::parse_config_toml(toml.as_bytes()).unwrap();
assert_eq!(configs.len(), 1);
let config = configs.remove(0);
assert!(config.debug);
assert!(config.verbose);
assert!(config.dump_traces);
assert!(config.all_targets);
assert!(config.ignore_panics);
assert!(config.count);
assert!(config.run_ignored);
Expand Down
2 changes: 1 addition & 1 deletion src/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ arg_enum! {
}

arg_enum! {
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
pub enum OutputFile {
Json,
Toml,
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::cargo::TestBinary;
use crate::config::*;
use crate::errors::*;
use crate::event_log::*;
use crate::path_utils::*;
use crate::process_handling::*;
use crate::report::report_coverage;
use crate::source_analysis::LineAnalysis;
Expand Down Expand Up @@ -81,7 +82,13 @@ pub fn trace(configs: &[Config]) -> Result<TraceMap, RunError> {
}

pub fn run(configs: &[Config]) -> Result<(), RunError> {
let tracemap = trace(configs)?;
let mut tracemap = trace(configs)?;
if !configs.is_empty() {
// Assumption: all configs are for the same project
for dir in get_source_walker(&configs[0]) {
tracemap.add_file(dir.path());
}
}
if configs.len() == 1 {
report_coverage(&configs[0], &tracemap)?;
} else if !configs.is_empty() {
Expand Down
Loading

0 comments on commit eb9dc9f

Please sign in to comment.