Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ignore CARGO_BUILD_TARGET in tests #1010

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions tests/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ fn build_using_bin(extra_args: &[&str]) -> tempfile::TempDir {
Command::new(cbindgen_path)
.current_dir(expand_dep_test_dir)
.env("CARGO_EXPAND_TARGET_DIR", tmp_dir.path())
.env_remove("CARGO_BUILD_TARGET")
// ^ avoid unexpected change of layout of the target directory;
// ... see: https://doc.rust-lang.org/cargo/guide/build-cache.html
.args(extra_args)
.output()
.expect("build should succeed");
Expand Down Expand Up @@ -87,6 +90,18 @@ fn bin_default_uses_debug_build() {
assert_eq!(get_contents_of_dir(target_dir.path()), &["debug"]);
}

#[test]
bryango marked this conversation as resolved.
Show resolved Hide resolved
fn bin_ignore_cargo_build_target_in_tests() {
use std::env;
env::set_var("CARGO_BUILD_TARGET", "x86_64-unknown-linux-gnu");
assert_eq!(
env::var("CARGO_BUILD_TARGET"),
Ok("x86_64-unknown-linux-gnu".into())
bryango marked this conversation as resolved.
Show resolved Hide resolved
);
// ^ this env var should be ignored:
bin_default_uses_debug_build();
}

#[test]
fn bin_explicit_debug_build() {
let target_dir = build_using_bin(&["--profile", "debug"]);
Expand Down
Loading