Skip to content

Commit

Permalink
Merge branch 'arg_forwarding'
Browse files Browse the repository at this point in the history
fixes #37 by allowing arguments following " -- " to be forwarded onto the test executable
  • Loading branch information
xd009642 committed Sep 12, 2017
2 parents 0d7089d + 4160181 commit 8e3fe3a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
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.4.1"
version = "0.4.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
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Config {
pub forward_signals: bool,
pub features: Vec<String>,
pub packages: Vec<String>,
pub varargs: Vec<String>
}


Expand Down Expand Up @@ -97,6 +98,10 @@ impl Config {
Some(v) => v,
None => vec![],
};
let varargs: Vec<String> = match args.values_of_lossy("args") {
Some(v) => v,
None => vec![],
};
Config{
manifest: root,
run_ignored: ignored,
Expand All @@ -110,6 +115,7 @@ impl Config {
forward_signals: forward,
features: features,
packages: packages,
varargs: varargs
}
}

Expand Down
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ pub fn launch_tarpaulin(config: Config) -> Result<(), i32> {
println!("Processing {}", c.1);
}
let res = get_test_coverage(workspace.root(), c.2.as_path(),
config.forward_signals, false)
&config, false)
.unwrap_or_default();
merge_test_results(&mut result, &res);
if config.run_ignored {
let res = get_test_coverage(workspace.root(), c.2.as_path(),
config.forward_signals, true)
&config, true)
.unwrap_or_default();
merge_test_results(&mut result, &res);
}
Expand Down Expand Up @@ -238,13 +238,13 @@ pub fn report_coverage(config: &Config, result: &[TracerData]) {
}

/// Returns the coverage statistics for a test executable in the given workspace
pub fn get_test_coverage(root: &Path, test: &Path, forward:bool, ignored: bool) -> Option<Vec<TracerData>> {
pub fn get_test_coverage(root: &Path, test: &Path, config: &Config, ignored: bool) -> Option<Vec<TracerData>> {
if !test.exists() {
return None;
}
match fork() {
Ok(ForkResult::Parent{ child }) => {
match collect_coverage(root, test, child, forward) {
match collect_coverage(root, test, child, config.forward_signals) {
Ok(t) => {
Some(t)
},
Expand All @@ -256,7 +256,7 @@ pub fn get_test_coverage(root: &Path, test: &Path, forward:bool, ignored: bool)
}
Ok(ForkResult::Child) => {
println!("Launching test");
execute_test(test, ignored, true);
execute_test(test, ignored, config);
None
}
Err(err) => {
Expand Down Expand Up @@ -412,7 +412,7 @@ fn run_function(pid: pid_t,


/// Launches the test executable
fn execute_test(test: &Path, ignored: bool, backtrace_on: bool) {
fn execute_test(test: &Path, ignored: bool, config: &Config) {
let exec_path = CString::new(test.to_str().unwrap()).unwrap();
match personality::disable_aslr() {
Ok(_) => {},
Expand All @@ -428,14 +428,17 @@ fn execute_test(test: &Path, ignored: bool, backtrace_on: bool) {
temp.push_str(value.as_str());
envars.push(CString::new(temp).unwrap());
}
if backtrace_on {
if config.verbose {
envars.push(CString::new("RUST_BACKTRACE=1").unwrap());
}
let argv = if ignored {
let mut argv = if ignored {
vec![exec_path.clone(), CString::new("--ignored").unwrap()]
} else {
vec![exec_path.clone()]
};
for s in &config.varargs {
argv.push(CString::new(s.as_bytes()).unwrap_or_default());
}
execve(&exec_path, &argv, envars.as_slice())
.unwrap();
}
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate rustc_demangle;
extern crate clap;

use std::path::Path;
use clap::{App, Arg, SubCommand};
use clap::{App, Arg, SubCommand, ArgSettings};
use cargo_tarpaulin::launch_tarpaulin;
use cargo_tarpaulin::config::*;

Expand Down Expand Up @@ -39,7 +39,7 @@ fn main() {
.about("Tool to analyse test coverage of cargo projects")
.version(concat!("version: ", crate_version!()))
.args_from_usage(
"--help -h 'Prints help information'
"--help 'Prints help information'
--verbose -v 'Show extra output'
--ignored -i 'Run ignored tests as well'
--line -l 'Line coverage'
Expand All @@ -57,6 +57,9 @@ fn main() {
.validator(is_dir),
Arg::from_usage("--ciserver [SERVICE] 'CI server being used'")
.help(CI_SERVER_HELP),
Arg::with_name("args")
.set(ArgSettings::Last)
.multiple(true)
]))
.get_matches();

Expand Down

0 comments on commit 8e3fe3a

Please sign in to comment.