diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..2f3633bb6b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: +- package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + target-branch: develop + ignore: + - dependency-name: libc + versions: + - 0.2.83 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6955f2cbbc..9edf397ee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,20 @@ From 2019 onwards, all notable changes to tarpaulin will be documented in this file. +## Unreleased +### Added + +### Changed +- Updated logging so for the build mode it says "launching binary" instead of +"launching test" +- Don't apply `--color` argument to test executables if "auto" to prevent issues +with tests that can't have color controlled +- Fix directory that `cargo clean` is run from +- Reduce number of cleans fixing issue where only last run-type was ran +- Clean without `cargo clean` removing directory to preserve coverage run delta reporting + +### Removed + ## [0.18.0-alpha2] 2021-04-16 ### Added - Check if user sets -Cdebuginfo and remove it #601 diff --git a/Cargo.lock b/Cargo.lock index 54fa097124..6234f4bb9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cargo-tarpaulin" -version = "0.18.0-alpha2" +version = "0.18.0-alpha3" dependencies = [ "cargo_metadata", "cfg-if 1.0.0", @@ -289,9 +289,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.13.17" +version = "0.13.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d250f5f82326884bd39c2853577e70a121775db76818ffa452ed1e80de12986" +checksum = "b483c6c2145421099df1b4efd50e0f6205479a072199460eff852fa15e5603c7" dependencies = [ "bitflags", "libc", @@ -393,15 +393,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.93" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "libgit2-sys" -version = "0.12.18+1.1.0" +version = "0.12.19+1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3da6a42da88fc37ee1ecda212ffa254c25713532980005d5f7c0b0fbe7e6e885" +checksum = "f322155d574c8b9ebe991a04f6908bb49e68a79463338d24a43d6274cb6443e6" dependencies = [ "cc", "libc", @@ -634,9 +634,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.5" +version = "1.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" +checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" dependencies = [ "aho-corasick", "memchr", @@ -789,9 +789,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.69" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "ad184cc9470f9117b2ac6817bfe297307418819ba40552f9b3846f05c33d5373" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index bcfe68b53c..1469867c9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-tarpaulin" -version = "0.18.0-alpha2" +version = "0.18.0-alpha3" authors = ["Daniel McKenna "] description = "Cargo-Tarpaulin is a tool to determine code coverage achieved via tests" repository = "https://github.com/xd009642/tarpaulin" @@ -47,7 +47,7 @@ walkdir = "2.3.2" cfg-if = "1.0.0" [target.'cfg(target_os = "linux")'.dependencies] -libc = "0.2.93" +libc = "0.2.94" nix = "0.20.0" procfs = "0.9" diff --git a/README.md b/README.md index 1174973bc5..53cc566145 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Below is the help-text for a thorough explanation of the flags and features available: ``` -cargo-tarpaulin version: 0.18.0-alpha2 +cargo-tarpaulin version: 0.18.0-alpha3 Tool to analyse test coverage of cargo projects USAGE: diff --git a/src/cargo.rs b/src/cargo.rs index 53213a7e1f..699fab70ca 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -12,7 +12,6 @@ use std::io; use std::io::{BufRead, BufReader}; use std::path::{Component, Path, PathBuf}; use std::process::{Command, Stdio}; - use toml::Value; use tracing::{error, info, trace, warn}; use walkdir::{DirEntry, WalkDir}; @@ -40,7 +39,7 @@ impl CargoVersionInfo { } } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)] pub struct TestBinary { path: PathBuf, ty: Option, @@ -164,6 +163,19 @@ lazy_static! { pub fn get_tests(config: &Config) -> Result, RunError> { let mut result = vec![]; + if config.force_clean { + let cleanup_dir = if config.release { + config.target_dir().join("debug") + } else { + config.target_dir().join("release") + }; + info!("Cleaning project"); + if cleanup_dir.exists() { + if let Err(e) = remove_dir_all(cleanup_dir) { + error!("Cargo clean failed: {}", e); + } + } + } let manifest = match config.manifest.as_path().to_str() { Some(s) => s, None => "Cargo.toml", @@ -197,15 +209,6 @@ fn run_cargo( ty: Option, result: &mut Vec, ) -> Result<(), RunError> { - if config.force_clean { - if let Ok(clean) = Command::new("cargo").arg("clean").output() { - info!("Cleaning project"); - if !clean.status.success() { - error!("Cargo clean failed:"); - println!("{}", std::str::from_utf8(&clean.stderr).unwrap_or_default()); - } - } - } let mut cmd = create_command(manifest, config, ty); if ty != Some(RunType::Doctests) { cmd.stdout(Stdio::piped()); diff --git a/src/process_handling/linux.rs b/src/process_handling/linux.rs index a2be597151..2263fe055b 100644 --- a/src/process_handling/linux.rs +++ b/src/process_handling/linux.rs @@ -1,4 +1,5 @@ use crate::collect_coverage; +use crate::config::types::Mode; use crate::errors::*; use crate::event_log::*; use crate::process_handling::execute_test; @@ -40,6 +41,7 @@ pub fn get_test_coverage( logger: &Option, ) -> Result, RunError> { if !test.path().exists() { + warn!("Test at {} doesn't exist", test.path().display()); return Ok(None); } if let Err(e) = limit_affinity() { @@ -57,7 +59,11 @@ pub fn get_test_coverage( } } Ok(ForkResult::Child) => { - info!("Launching test"); + let bin_type = match config.command { + Mode::Test => "test", + Mode::Build => "binary", + }; + info!("Launching {}", bin_type); execute_test(test, ignored, config)?; Ok(None) } diff --git a/src/process_handling/mod.rs b/src/process_handling/mod.rs index 482f304308..10311d7ff7 100644 --- a/src/process_handling/mod.rs +++ b/src/process_handling/mod.rs @@ -1,3 +1,4 @@ +use crate::config::Color; use crate::generate_tracemap; use crate::statemachine::{create_state_machine, TestState}; use crate::traces::*; @@ -96,8 +97,10 @@ fn execute_test(test: &TestBinary, ignored: bool, config: &Config) -> Result<(), for s in &config.varargs { argv.push(CString::new(s.as_bytes()).unwrap_or_default()); } - argv.push(CString::new("--color").unwrap_or_default()); - argv.push(CString::new(config.color.to_string().to_ascii_lowercase()).unwrap_or_default()); + if config.color != Color::Auto { + argv.push(CString::new("--color").unwrap_or_default()); + argv.push(CString::new(config.color.to_string().to_ascii_lowercase()).unwrap_or_default()); + } if let Some(s) = test.pkg_name() { envars.push(CString::new(format!("CARGO_PKG_NAME={}", s)).unwrap_or_default()); diff --git a/tests/test_types.rs b/tests/test_types.rs index d206d78563..66c126ab1e 100644 --- a/tests/test_types.rs +++ b/tests/test_types.rs @@ -4,6 +4,34 @@ use cargo_tarpaulin::launch_tarpaulin; use std::env; use std::time::Duration; +#[test] +fn mix_test_types() { + // Issue 747 the clean would delete old tests leaving to only one run type effectively being + // ran. This test covers against that mistake + let mut config = Config::default(); + config.force_clean = true; + config.test_timeout = Duration::from_secs(60); + config.run_types = vec![RunType::Tests, RunType::Examples]; + let restore_dir = env::current_dir().unwrap(); + let test_dir = get_test_path("all_test_types"); + env::set_current_dir(&test_dir).unwrap(); + config.manifest = test_dir; + config.manifest.push("Cargo.toml"); + + let (res, ret) = launch_tarpaulin(&config, &None).unwrap(); + assert_eq!(ret, 0); + env::set_current_dir(restore_dir).unwrap(); + + for f in res.files() { + let f_name = f.file_name().unwrap().to_str().unwrap(); + if f_name.contains("example") || (f_name.contains("test") && !f_name.contains("doc")) { + assert!(res.covered_in_path(f) > 0); + } else { + assert_eq!(res.covered_in_path(f), 0); + } + } +} + #[test] fn only_test_coverage() { let mut config = Config::default(); diff --git a/travis-install.sh b/travis-install.sh index 41ddb41e83..00a573ee77 100755 --- a/travis-install.sh +++ b/travis-install.sh @@ -1,2 +1,2 @@ #!/bin/bash -curl -sL https://github.com/xd009642/tarpaulin/releases/download/0.18.0-alpha2/cargo-tarpaulin-0.18.0-alpha2-travis.tar.gz | tar xvz -C $HOME/.cargo/bin +curl -sL https://github.com/xd009642/tarpaulin/releases/download/0.18.0-alpha3/cargo-tarpaulin-0.18.0-alpha3-travis.tar.gz | tar xvz -C $HOME/.cargo/bin