-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #7697 - ehuss:bin-test-env, r=alexcrichton
Set an environment variable for tests to find executables. This adds the environment variable `CARGO_BIN_EXE_<name>` so that integration tests can find binaries to execute, instead of doing things like inspecting `env::current_exe()`. The use of uppercase is primarily motivated by Windows whose Rust implementation behaves in a strange way. It always ascii-upper-cases keys to implement case-insensitive matching (which loses the original case). Seems less likely to result in confusion? Closes #5758.
- Loading branch information
Showing
8 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3995,3 +3995,50 @@ fn panic_abort_test_profile_inherits() { | |
.with_status(0) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn bin_env_for_test() { | ||
// Test for the `CARGO_BIN_` environment variables for tests. | ||
This comment has been minimized.
Sorry, something went wrong.
jiangying000
Contributor
|
||
// | ||
// Note: The Unicode binary uses a `[[bin]]` definition because different | ||
// filesystems normalize utf-8 in different ways. For example, HFS uses | ||
// "gru\u{308}ßen" and APFS uses "gr\u{fc}ßen". Defining it in TOML forces | ||
// one form to be used. | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
edition = "2018" | ||
[[bin]] | ||
name = 'grüßen' | ||
path = 'src/bin/grussen.rs' | ||
"#, | ||
) | ||
.file("src/bin/foo.rs", "fn main() {}") | ||
.file("src/bin/with-dash.rs", "fn main() {}") | ||
.file("src/bin/grussen.rs", "fn main() {}") | ||
.build(); | ||
|
||
let bin_path = |name| p.bin(name).to_string_lossy().replace("\\", "\\\\"); | ||
p.change_file( | ||
"tests/check_env.rs", | ||
&r#" | ||
#[test] | ||
fn run_bins() { | ||
assert_eq!(env!("CARGO_BIN_EXE_foo"), "<FOO_PATH>"); | ||
assert_eq!(env!("CARGO_BIN_EXE_with-dash"), "<WITH_DASH_PATH>"); | ||
assert_eq!(env!("CARGO_BIN_EXE_grüßen"), "<GRÜSSEN_PATH>"); | ||
} | ||
"# | ||
.replace("<FOO_PATH>", &bin_path("foo")) | ||
.replace("<WITH_DASH_PATH>", &bin_path("with-dash")) | ||
.replace("<GRÜSSEN_PATH>", &bin_path("grüßen")), | ||
); | ||
|
||
p.cargo("test --test check_env").run(); | ||
p.cargo("check --test check_env").run(); | ||
} |
should this be
// Add
CARGO_BIN_EXE_
environment variables for building tests.