Skip to content

Commit eba0585

Browse files
authored
Merge pull request #461 from rustcoreutils/codecov
Unify integration testing target dir selection
2 parents 41035a3 + e67d7e2 commit eba0585

File tree

8 files changed

+94
-34
lines changed

8 files changed

+94
-34
lines changed

datetime/tests/time/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ use std::{
1515
use plib::testing::TestPlan;
1616

1717
fn run_test_base(cmd: &str, args: &Vec<String>, stdin_data: &[u8]) -> Output {
18-
let relpath = if cfg!(debug_assertions) {
19-
format!("target/debug/{}", cmd)
18+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
19+
let target_dir = std::env::var("CARGO_TARGET_DIR")
20+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
21+
.unwrap_or_else(|_| String::from("target"));
22+
23+
let profile = if cfg!(debug_assertions) {
24+
"debug"
2025
} else {
21-
format!("target/release/{}", cmd)
26+
"release"
2227
};
28+
29+
let relpath = format!("{}/{}/{}", target_dir, profile, cmd);
2330
let test_bin_path = std::env::current_dir()
2431
.unwrap()
2532
.parent()

file/tests/find/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ fn run_test_find_sorted(
3030
expected_exit_code: i32,
3131
) {
3232
let project_root = env!("CARGO_MANIFEST_DIR");
33-
let find_path = format!("{}/../target/release/find", project_root);
33+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
34+
let target_dir = std::env::var("CARGO_TARGET_DIR")
35+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
36+
.unwrap_or_else(|_| String::from("target"));
37+
let profile = if cfg!(debug_assertions) {
38+
"debug"
39+
} else {
40+
"release"
41+
};
42+
let find_path = format!("{}/../{}/{}/find", project_root, target_dir, profile);
3443

3544
let output = Command::new(&find_path)
3645
.args(args)
@@ -261,7 +270,16 @@ fn find_newer_test() {
261270
/// Run find and compare null-delimited output (for -print0 testing)
262271
fn run_test_find_print0_sorted(args: &[&str], expected_paths: &[&str], expected_exit_code: i32) {
263272
let project_root = env!("CARGO_MANIFEST_DIR");
264-
let find_path = format!("{}/../target/release/find", project_root);
273+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
274+
let target_dir = std::env::var("CARGO_TARGET_DIR")
275+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
276+
.unwrap_or_else(|_| String::from("target"));
277+
let profile = if cfg!(debug_assertions) {
278+
"debug"
279+
} else {
280+
"release"
281+
};
282+
let find_path = format!("{}/../{}/{}/find", project_root, target_dir, profile);
265283

266284
let output = Command::new(&find_path)
267285
.args(args)

m4/build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,17 @@ fn run_command(input: &Path) -> std::process::Output {
271271
.output()
272272
.unwrap();
273273
274+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
275+
let target_dir = std::env::var("CARGO_TARGET_DIR")
276+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
277+
.unwrap_or_else(|_| String::from("target"));
278+
let m4_path = format!("../{}/debug/m4", target_dir);
279+
274280
log::info!("RUST_LOG is ignored for this test because it interferes with output");
275281
let output = std::process::Command::new("sh")
276282
.env("RUST_LOG", "") // Disable rust log output because it interferes with the test.
277283
.arg("-c")
278-
.arg(format!("../target/debug/m4 {args}"))
284+
.arg(format!("{m4_path} {args}"))
279285
.output()
280286
.unwrap();
281287

m4/tests/integration_test.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ use std::os::unix::ffi::OsStrExt;
1010
use std::os::unix::process::ExitStatusExt;
1111
use std::path::Path;
1212
use std::process::ExitStatus;
13-
use std::sync::Once;
14-
15-
static BUILD_ONCE: Once = Once::new();
1613

1714
fn init() {
1815
let _ = env_logger::builder()
@@ -74,20 +71,22 @@ fn run_command(input: &Path) -> std::process::Output {
7471
}
7572
b"args" => {
7673
let args = input_string;
77-
// Use Once to ensure cargo build runs only once, avoiding race conditions
78-
// when multiple .args tests run in parallel
79-
BUILD_ONCE.call_once(|| {
80-
let _cargo_build_output = std::process::Command::new("cargo")
81-
.arg("build")
82-
.output()
83-
.unwrap();
84-
});
74+
let _cargo_build_output = std::process::Command::new("cargo")
75+
.arg("build")
76+
.output()
77+
.unwrap();
78+
79+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
80+
let target_dir = std::env::var("CARGO_TARGET_DIR")
81+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
82+
.unwrap_or_else(|_| String::from("target"));
83+
let m4_path = format!("../{}/debug/m4", target_dir);
8584

8685
log::info!("RUST_LOG is ignored for this test because it interferes with output");
8786
let output = std::process::Command::new("sh")
8887
.env("RUST_LOG", "") // Disable rust log output because it interferes with the test.
8988
.arg("-c")
90-
.arg(format!("../target/debug/m4 {args}"))
89+
.arg(format!("{m4_path} {args}"))
9190
.output()
9291
.unwrap();
9392

make/tests/integration.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ fn run_test_helper_with_setup_and_destruct(
9696
}
9797

9898
fn manual_test_helper(args: &[&str]) -> Child {
99-
// Determine the binary path based on the build profile
100-
let relpath = if cfg!(debug_assertions) {
101-
format!("target/debug/{}", "make")
99+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
100+
let target_dir = env::var("CARGO_TARGET_DIR")
101+
.or_else(|_| env::var("CARGO_LLVM_COV_TARGET_DIR"))
102+
.unwrap_or_else(|_| String::from("target"));
103+
104+
let profile = if cfg!(debug_assertions) {
105+
"debug"
102106
} else {
103-
format!("target/release/{}", "make")
107+
"release"
104108
};
105109

110+
let relpath = format!("{}/{}/{}", target_dir, profile, "make");
111+
106112
// Build the full path to the binary
107113
let test_bin_path = env::current_dir()
108114
.expect("failed to get current directory")

plib/src/testing.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ pub fn run_test_base_with_env(
4040
stdin_data: &[u8],
4141
env_vars: &[(&str, &str)],
4242
) -> Output {
43-
let relpath = if cfg!(debug_assertions) {
44-
format!("target/debug/{}", cmd)
43+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
44+
let target_dir = std::env::var("CARGO_TARGET_DIR")
45+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
46+
.unwrap_or_else(|_| String::from("target"));
47+
48+
let profile = if cfg!(debug_assertions) {
49+
"debug"
4550
} else {
46-
format!("target/release/{}", cmd)
51+
"release"
4752
};
53+
54+
let relpath = format!("{}/{}/{}", target_dir, profile, cmd);
4855
let test_bin_path = std::env::current_dir()
4956
.unwrap()
5057
.parent()

process/tests/timeout/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ pub struct TestPlan {
2727
}
2828

2929
fn run_test_base(cmd: &str, args: &Vec<String>, stdin_data: &[u8]) -> (Output, i32) {
30-
let relpath = if cfg!(debug_assertions) {
31-
format!("target/debug/{}", cmd)
30+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
31+
let target_dir = std::env::var("CARGO_TARGET_DIR")
32+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
33+
.unwrap_or_else(|_| String::from("target"));
34+
35+
let profile = if cfg!(debug_assertions) {
36+
"debug"
3237
} else {
33-
format!("target/release/{}", cmd)
38+
"release"
3439
};
40+
41+
let relpath = format!("{}/{}/{}", target_dir, profile, cmd);
3542
let test_bin_path = std::env::current_dir()
3643
.unwrap()
3744
.parent()

uucp/tests/uustat/mod.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,16 @@ impl SpoolEnv {
134134
}
135135

136136
fn run_uucp(&self, args: &[&str]) -> std::process::Output {
137-
let relpath = if cfg!(debug_assertions) {
138-
"target/debug/uucp"
137+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
138+
let target_dir = std::env::var("CARGO_TARGET_DIR")
139+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
140+
.unwrap_or_else(|_| String::from("target"));
141+
let profile = if cfg!(debug_assertions) {
142+
"debug"
139143
} else {
140-
"target/release/uucp"
144+
"release"
141145
};
146+
let relpath = format!("{}/{}/uucp", target_dir, profile);
142147
let test_bin_path = std::env::current_dir()
143148
.unwrap()
144149
.parent()
@@ -154,11 +159,16 @@ impl SpoolEnv {
154159
}
155160

156161
fn run_uustat(&self, args: &[&str]) -> std::process::Output {
157-
let relpath = if cfg!(debug_assertions) {
158-
"target/debug/uustat"
162+
// Determine the target directory - cargo-llvm-cov uses a custom target dir
163+
let target_dir = std::env::var("CARGO_TARGET_DIR")
164+
.or_else(|_| std::env::var("CARGO_LLVM_COV_TARGET_DIR"))
165+
.unwrap_or_else(|_| String::from("target"));
166+
let profile = if cfg!(debug_assertions) {
167+
"debug"
159168
} else {
160-
"target/release/uustat"
169+
"release"
161170
};
171+
let relpath = format!("{}/{}/uustat", target_dir, profile);
162172
let test_bin_path = std::env::current_dir()
163173
.unwrap()
164174
.parent()

0 commit comments

Comments
 (0)