Skip to content

Commit

Permalink
Release 0.31.5
Browse files Browse the repository at this point in the history
  • Loading branch information
xd009642 committed Jan 16, 2025
2 parents 5aba88d + fdc9c09 commit bfe1b05
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 53 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
From 2019 onwards, all notable changes to tarpaulin will be documented in this
file.

## [0.31.5] 2025-01-16
### Changed
- ASLR detection was slightly broken - although it wouldn't break anything unless setting was broken as well.
- Detect the libdir path by rustc and link to it to enable proc-macro test binaries to run without error #1642

## [0.31.4] 2024-12-31
### Added
- Added `--include-files` argument to only display coverage for the mentioned files (#1667)
Expand Down
19 changes: 9 additions & 10 deletions Cargo.lock

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

5 changes: 2 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.31.4"
version = "0.31.5"
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 @@ -25,9 +25,8 @@ cfg-if = "1.0.0"
chrono = "0.4"
clap = { version = "4.4.0", features = ["derive"] }
coveralls-api = { version = "0.6.0", optional = true }
fallible-iterator = "0.3.0"
gimli = "0.31.1"
git2 = { version = "0.19", optional = true }
git2 = { version = "0.20", optional = true }
humantime-serde = "1"
indexmap = { version = "~1.8", features = ["serde-1"] }
lazy_static = "1.5"
Expand Down
39 changes: 36 additions & 3 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ fn run_cargo(
trace!("Running command {:?}", cmd);
let mut child = cmd.spawn().map_err(|e| RunError::Cargo(e.to_string()))?;
let update_from = result.test_binaries.len();
let mut paths = vec![];
let mut paths = match get_libdir(ty) {
Some(path) => vec![path],
None => vec![],
};

if ty != Some(RunType::Doctests) {
let mut package_ids = vec![None; result.test_binaries.len()];
Expand Down Expand Up @@ -514,7 +517,7 @@ fn find_str_in_file(file: &Path, value: &str) -> io::Result<Vec<usize>> {
Ok(lines)
}

fn create_command(manifest_path: &str, config: &Config, ty: Option<RunType>) -> Command {
fn start_cargo_command(ty: Option<RunType>) -> Command {
let mut test_cmd = Command::new("cargo");
let bootstrap = matches!(env::var("RUSTC_BOOTSTRAP").as_deref(), Ok("1"));
let override_toolchain = if cfg!(windows) {
Expand All @@ -541,13 +544,37 @@ fn create_command(manifest_path: &str, config: &Config, ty: Option<RunType>) ->
test_cmd.args(["+nightly"]);
}
}
test_cmd.args(["test"]);
} else {
if override_toolchain {
if let Ok(toolchain) = env::var("RUSTUP_TOOLCHAIN") {
test_cmd.arg(format!("+{toolchain}"));
}
}
}
test_cmd
}

fn get_libdir(ty: Option<RunType>) -> Option<PathBuf> {
let mut test_cmd = start_cargo_command(ty);
test_cmd.env("RUSTC_BOOTSTRAP", "1");
test_cmd.args(["rustc", "-Z", "unstable-options", "--print=target-libdir"]);

let output = match test_cmd.output() {
Ok(output) => String::from_utf8_lossy(&output.stdout).trim().to_string(),
Err(e) => {
debug!("Unable to run cargo rustc command: {}", e);
warn!("Unable to get target libdir proc macro crates in the workspace may not work. Consider adding `--exclude` to remove them from compilation");
return None;
}
};
Some(PathBuf::from(output))
}

fn create_command(manifest_path: &str, config: &Config, ty: Option<RunType>) -> Command {
let mut test_cmd = start_cargo_command(ty);
if ty == Some(RunType::Doctests) {
test_cmd.args(["test"]);
} else {
if config.command == Mode::Test {
test_cmd.args(["test", "--no-run"]);
} else {
Expand Down Expand Up @@ -913,6 +940,12 @@ mod tests {
use super::*;
use toml::toml;

#[test]
fn can_get_libdir() {
let path = get_libdir(Some(RunType::Tests)).unwrap();
assert!(path.exists(), "{} doesn't exist", path.display());
}

#[test]
#[cfg(not(windows))]
fn check_dead_code_flags() {
Expand Down
27 changes: 15 additions & 12 deletions src/process_handling/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use nix::sys::personality;
use nix::unistd::*;
use std::ffi::{CStr, CString};
use std::path::Path;
use std::process::Command;
use tracing::{info, warn};

lazy_static! {
Expand Down Expand Up @@ -63,17 +62,9 @@ fn disable_aslr() -> nix::Result<()> {
}

fn is_aslr_enabled() -> bool {
// Create a Command instance with the 'cat' command and the path to the file as arguments
let output = Command::new("cat")
.arg("/proc/sys/kernel/random/boot_random")
.output()
.unwrap();

// Convert the output to a String and store it in a variable
let output_str = String::from_utf8(output.stdout).unwrap();

// Check if the output string is not '0' (case-insensitive) and return the result
output_str.trim().to_lowercase() != "0"
!personality::get()
.map(|x| x.contains(personality::Persona::ADDR_NO_RANDOMIZE))
.unwrap_or(true)
}

pub fn limit_affinity() -> nix::Result<()> {
Expand Down Expand Up @@ -120,3 +111,15 @@ pub fn execute(

unreachable!();
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn can_disable_aslr() {
assert!(is_aslr_enabled());
disable_aslr().unwrap();
assert!(!is_aslr_enabled());
}
}
13 changes: 3 additions & 10 deletions src/process_handling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,14 @@ fn execute_test(
argv.push("--color".to_string());
argv.push(config.color.to_string().to_ascii_lowercase());
}
let no_test_env = if let Ok(threads) = env::var("RUST_TEST_THREADS") {
if let Ok(threads) = env::var("RUST_TEST_THREADS") {
envars.push(("RUST_TEST_THREADS".to_string(), threads));
false
} else {
true
};

if no_test_env
&& test.is_test_type()
} else if test.is_test_type()
&& !config.implicit_test_threads
&& !config.varargs.iter().any(|x| x.contains("--test-threads"))
{
if let Some(threads) = num_threads {
argv.push("--test-threads".to_string());
argv.push(threads.to_string());
envars.push(("RUST_TEST_THREADS".to_string(), threads.to_string()));
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/report/cobertura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ fn render_class(config: &Config, traces: &TraceMap, file: &Path) -> Option<Class
}
}

/// So I don't currently export out methods for cobertura. This may change in future easily enough
/// though so leaving the type here as a potential stub.
#[derive(Debug)]
struct Method {
name: String,
Expand All @@ -371,14 +373,6 @@ struct Method {
lines: Vec<Line>,
}

fn render_methods() -> Vec<Method> {
unimplemented!()
}

fn render_method() -> Method {
unimplemented!()
}

#[derive(Debug)]
enum Line {
Plain {
Expand Down
14 changes: 7 additions & 7 deletions tarpaulin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ target-dir = "./target"
# Run the tests without accessing the network (offline mode).
offline = false

# Cargo subcommand to run; options are "test" or "build".
command = "test"
# Cargo subcommand to run; options are "Test" or "Build".
command = "Test"

# Types of tests to collect coverage for. For example: ["unit", "integration"]
run-types = ["unit"]
# Types of tests to collect coverage for. For example: ["Lib", "AllTargets", "Benchmarks", "Bins", "Examples", "Doctests", "Tests"]
run-types = ["AllTargets"]

# List of packages to include when building the target project.
packages = ["my_package"]
packages = []

# List of packages to exclude from testing.
exclude = []
Expand Down Expand Up @@ -156,7 +156,7 @@ no-fail-fast = false
avoid-cfg-tarpaulin = false

# Colouring of logs in the terminal output (e.g., "auto", "always", "never").
color = "auto"
color = "Auto"

# Follow traced executables down through function calls.
follow-exec = true
Expand Down Expand Up @@ -189,4 +189,4 @@ profraw-folder = "./target/profraw"
fail-immediately = false

# Log to stderr instead of the default output.
stderr = false
stderr = false

0 comments on commit bfe1b05

Please sign in to comment.