diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index b763f5b317f..1995501b6cc 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -889,7 +889,7 @@ fn build_base_args<'a, 'cfg>( let exe_path = cx .files() .bin_link_for_target(bin_target, unit.kind, cx.bcx)?; - let key = format!("CARGO_BIN_EXE_{}", bin_target.crate_name().to_uppercase()); + let key = format!("CARGO_BIN_EXE_{}", bin_target.name()); cmd.env(&key, exe_path); } } diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index c99f708e236..6ba68c6ae7a 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -190,9 +190,10 @@ let version = env!("CARGO_PKG_VERSION"); * `CARGO_BIN_EXE_` — The absolute path to a binary target's executable. This is only set when building an [integration test] or benchmark. This may be used with the [`env` macro] to find the executable to run for testing - purposes. The `` is the name of the binary converted to uppercase, and - `-` converted to `_`. Binaries are automatically built when the test is - built, unless the binary has required features that are not enabled. + purposes. The `` is the name of the binary target, exactly as-is. For + example, `CARGO_BIN_EXE_my-program` for a binary named `my-program`. + Binaries are automatically built when the test is built, unless the binary + has required features that are not enabled. [integration test]: manifest.md#integration-tests [`env` macro]: ../../std/macro.env.html diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index c685b51ce8c..9d356bc92fe 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -4029,9 +4029,9 @@ fn bin_env_for_test() { &r#" #[test] fn run_bins() { - assert_eq!(env!("CARGO_BIN_EXE_FOO"), ""); - assert_eq!(env!("CARGO_BIN_EXE_WITH_DASH"), ""); - assert_eq!(env!("CARGO_BIN_EXE_GRÜSSEN"), ""); + assert_eq!(env!("CARGO_BIN_EXE_foo"), ""); + assert_eq!(env!("CARGO_BIN_EXE_with-dash"), ""); + assert_eq!(env!("CARGO_BIN_EXE_grüßen"), ""); } "# .replace("", &bin_path("foo"))