Skip to content

Commit 8bba4f4

Browse files
committed
test: include a case for setting OUT_DIR
Signed-off-by: hi-rustin <rustin.liu@gmail.com> test: remove the env set by Cargo Signed-off-by: hi-rustin <rustin.liu@gmail.com> Fix Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 4e792c2 commit 8bba4f4

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

crates/cargo-test-support/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,8 @@ pub trait TestEnv: Sized {
12861286
.env_remove("RUSTFLAGS")
12871287
.env_remove("SSH_AUTH_SOCK") // ensure an outer agent is never contacted
12881288
.env_remove("USER") // not set on some rust-lang docker images
1289-
.env_remove("XDG_CONFIG_HOME"); // see #2345
1289+
.env_remove("XDG_CONFIG_HOME") // see #2345
1290+
.env_remove("OUT_DIR"); // see #13204
12901291
if cfg!(target_os = "macos") {
12911292
// Work-around a bug in macOS 10.15, see `link_or_copy` for details.
12921293
self = self.env("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS", "1");

tests/testsuite/test.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,3 +4897,51 @@ fn cargo_test_print_env_verbose() {
48974897
)
48984898
.run();
48994899
}
4900+
4901+
#[cargo_test]
4902+
fn cargo_test_set_out_dir_env_var() {
4903+
let p = project()
4904+
.file(
4905+
"Cargo.toml",
4906+
r#"
4907+
[package]
4908+
name = "foo"
4909+
version = "0.0.1"
4910+
edition = "2021"
4911+
"#,
4912+
)
4913+
.file(
4914+
"src/lib.rs",
4915+
r#"
4916+
pub fn add(left: usize, right: usize) -> usize {
4917+
left + right
4918+
}
4919+
"#,
4920+
)
4921+
.file(
4922+
"build.rs",
4923+
r#"
4924+
fn main() {}
4925+
"#,
4926+
)
4927+
.file(
4928+
"tests/case.rs",
4929+
r#"
4930+
#[cfg(test)]
4931+
pub mod tests {
4932+
#[test]
4933+
fn test_add() {
4934+
assert!(std::env::var("OUT_DIR").is_ok());
4935+
assert_eq!(foo::add(2, 5), 7);
4936+
}
4937+
}
4938+
"#,
4939+
)
4940+
.build();
4941+
4942+
p.cargo("test").run();
4943+
p.cargo("test --package foo --test case -- tests::test_add --exact --nocapture")
4944+
.with_stdout_contains("test tests::test_add ... FAILED")
4945+
.with_status(101)
4946+
.run();
4947+
}

0 commit comments

Comments
 (0)