Skip to content

Commit

Permalink
Release 0.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
xd009642 committed Apr 11, 2020
2 parents 32c852d + 65789da commit 4adf767
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 44 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ From 2019 onwards, all notable changes to tarpaulin will be documented in this
file.

## [Unreleased]
### Added

### Changed

### Removed

## [0.12.2] 2020-04-11
### Changed
- Fill in `CARGO_PKG_NAME`, `CARG_PKG_VERSION`, `CARGO_PKG_AUTHORS` and
`CARGO_MANIFEST_DIR` environment variables when launching tests
- Filter out executables where profile test is false and run type is `Tests`

## [0.12.1] 2020-04-09
### Added
Expand Down
50 changes: 25 additions & 25 deletions 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.12.1"
version = "0.12.2"
authors = ["Daniel McKenna <danielmckenna93@gmail.com>"]
description = "Cargo-Tarpaulin is a tool to determine code coverage achieved via tests"
repository = "https://github.com/xd009642/tarpaulin"
Expand Down
53 changes: 36 additions & 17 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::errors::RunError;
use cargo_metadata::{
diagnostic::DiagnosticLevel, parse_messages, CargoOpt, Message, MetadataCommand,
};
use log::{error, info};
use log::error;
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
Expand All @@ -14,11 +14,25 @@ static DOCTEST_FOLDER: &str = "target/doctests";
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TestBinary {
path: PathBuf,
cargo_dir: Option<PathBuf>,
ty: RunType,
cargo_dir: Option<PathBuf>,
pkg_name: Option<String>,
pkg_version: Option<String>,
pkg_authors: Option<Vec<String>>,
}

impl TestBinary {
pub fn new(path: PathBuf, ty: RunType) -> Self {
Self {
path,
ty,
pkg_name: None,
pkg_version: None,
pkg_authors: None,
cargo_dir: None,
}
}

pub fn path(&self) -> &Path {
&self.path
}
Expand All @@ -30,6 +44,18 @@ impl TestBinary {
pub fn manifest_dir(&self) -> &Option<PathBuf> {
&self.cargo_dir
}

pub fn pkg_name(&self) -> &Option<String> {
&self.pkg_name
}

pub fn pkg_version(&self) -> &Option<String> {
&self.pkg_version
}

pub fn pkg_authors(&self) -> &Option<Vec<String>> {
&self.pkg_authors
}
}

pub fn get_tests(config: &Config) -> Result<Vec<TestBinary>, RunError> {
Expand Down Expand Up @@ -58,11 +84,10 @@ pub fn get_tests(config: &Config) -> Result<Vec<TestBinary>, RunError> {
match msg {
Ok(Message::CompilerArtifact(art)) => {
if let Some(path) = art.executable {
result.push(TestBinary {
path,
ty: *ty,
cargo_dir: None,
});
if !art.profile.test && ty == &RunType::Tests {
continue;
}
result.push(TestBinary::new(path, *ty));
package_ids.push(art.package_id.clone());
}
}
Expand All @@ -82,11 +107,9 @@ pub fn get_tests(config: &Config) -> Result<Vec<TestBinary>, RunError> {
for (res, package) in result.iter_mut().zip(package_ids.iter()) {
let package = &metadata[package];
res.cargo_dir = package.manifest_path.parent().map(|x| x.to_path_buf());
info!(
"Cargo directory for {} is {:?}",
res.path.display(),
res.cargo_dir
);
res.pkg_name = Some(package.name.clone());
res.pkg_version = Some(package.version.to_string());
res.pkg_authors = Some(package.authors.clone());
}
} else {
// Need to get the packages...
Expand All @@ -106,11 +129,7 @@ pub fn get_tests(config: &Config) -> Result<Vec<TestBinary>, RunError> {
_ => false,
})
{
result.push(TestBinary {
path: dt.path().to_path_buf(),
ty: *ty,
cargo_dir: None,
});
result.push(TestBinary::new(dt.path().to_path_buf(), *ty));
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,19 @@ fn execute_test(test: &TestBinary, ignored: bool, config: &Config) -> Result<(),
argv.push(CString::new(s.as_bytes()).unwrap_or_default());
}

if let Some(s) = test.pkg_name() {
envars.push(CString::new(format!("CARGO_PKG_NAME={}", s)).unwrap_or_default());
}
if let Some(s) = test.pkg_version() {
envars.push(CString::new(format!("CARGO_PKG_VERSION={}", s)).unwrap_or_default());
}
if let Some(s) = test.pkg_authors() {
envars.push(CString::new(format!("CARGO_PKG_AUTHORS={}", s.join(":"))).unwrap_or_default());
}
if let Some(s) = test.manifest_dir() {
envars
.push(CString::new(format!("CARGO_MANIFEST_DIR={}", s.display())).unwrap_or_default());
}

execute(exec_path, &argv, envars.as_slice())
}
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.12.1/cargo-tarpaulin-0.12.1-travis.tar.gz | tar xvz -C $HOME/.cargo/bin
curl -sL https://github.com/xd009642/tarpaulin/releases/download/0.12.2/cargo-tarpaulin-0.12.2-travis.tar.gz | tar xvz -C $HOME/.cargo/bin

0 comments on commit 4adf767

Please sign in to comment.