Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ result
.claude/*.local.json
.claude/*.local
.claude-reliability/
lcov.info
17 changes: 13 additions & 4 deletions tests/common/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ use std::sync::LazyLock;
use std::sync::atomic::{AtomicU64, Ordering};
use tempfile::TempDir;

// cache build output from TempRustProject across tests. Compilation time is substantial
// (10+ seconds) and this lets us only incur that cost on the first test.
// Cache build output from TempRustProject across tests within the same process.
//
// We clear the dir at the start to ensure a fresh environment on each test run.
// Under coverage (CARGO_LLVM_COV=1), we reuse the main project's llvm-cov target
// dir so that subprocess builds share the same instrumented artifacts. This lets
// cargo-llvm-cov's report phase map subprocess profraw data back to source files.
// Cargo's internal file locks prevent corruption from concurrent access.
//
// Outside coverage, each test binary gets its own target dir (via PID) to avoid
// heavy lock contention when multiple test binaries build in parallel.
static SHARED_TARGET_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
let path = std::env::temp_dir().join("hegel-test-cargo-target");
if std::env::var("CARGO_LLVM_COV").is_ok() {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target/llvm-cov-target");
return path;
}
let path = std::env::temp_dir().join(format!("hegel-test-cargo-target-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&path);
Comment on lines 10 to 26
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have we changed from a shared target dir to mixing in pid outside of coverage? This lessens the benefit of a shared target dir for compilation times by a factor of n where n is the number of cores

std::fs::create_dir_all(&path).unwrap();
path
Expand Down
16 changes: 5 additions & 11 deletions tests/test_output.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod common;

use common::project::TempRustProject;
use common::utils::{assert_matches_regex, is_nightly};
use common::utils::assert_matches_regex;

const FAILING_TEST_CODE: &str = r#"
use hegel::generators;
Expand Down Expand Up @@ -44,11 +44,8 @@ fn test_failing_test_output_with_backtrace() {
.expect_failure("intentional failure")
.cargo_run(&[]);

let closure_name = if is_nightly() {
r"\{closure#0\}"
} else {
r"\{\{closure\}\}"
};
// Rust >= 1.92 uses {closure#0}, older stable uses {{closure}}
let closure_name = r"(\{closure#0\}|\{\{closure\}\})";
// For example:
// Draw 1: 0
// thread 'main' (1) panicked at src/main.rs:7:9:
Expand Down Expand Up @@ -97,11 +94,8 @@ fn test_failing_test_output_with_full_backtrace() {
.expect_failure("intentional failure")
.cargo_run(&[]);

let closure_name = if is_nightly() {
r"\{closure#0\}"
} else {
r"\{\{closure\}\}"
};
// Rust >= 1.92 uses {closure#0}, older stable uses {{closure}}
let closure_name = r"(\{closure#0\}|\{\{closure\}\})";
assert_matches_regex(
&output.stderr,
&format!(
Expand Down