Skip to content

Commit

Permalink
test(doctest): doctest doesn't set shared libs to search path
Browse files Browse the repository at this point in the history
This new test demonstrate the current behavior.
  • Loading branch information
weihanglo committed Feb 26, 2024
1 parent 91f75ac commit 0e8a67f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use cargo_test_support::{
};
use cargo_test_support::{cross_compile, paths};
use cargo_test_support::{rustc_host, rustc_host_env, sleep_ms};
use cargo_util::paths::dylib_path_envvar;
use std::fs;

#[cargo_test]
Expand Down Expand Up @@ -2767,6 +2768,53 @@ fn only_test_docs() {
.run();
}

#[cargo_test]
fn doctest_with_library_paths() {
let p = project();
// Only link search directories within the target output directory are
// propagated through to dylib_path_envvar() (see #3366).
let dir1 = p.target_debug_dir().join("foo\\backslash");
let dir2 = p.target_debug_dir().join("dir=containing=equal=signs");

let p = p
.file("Cargo.toml", &basic_manifest("foo", "0.0.0"))
.file(
"build.rs",
&format!(
r##"
fn main() {{
println!(r#"cargo::rustc-link-search=native={}"#);
println!(r#"cargo::rustc-link-search={}"#);
}}
"##,
dir1.display(),
dir2.display()
),
)
.file(
"src/lib.rs",
&format!(
r##"
/// ```
/// foo::assert_search_path();
/// ```
pub fn assert_search_path() {{
let search_path = std::env::var_os("{}").unwrap();
let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
assert!(!paths.contains(&r#"{}"#.into()));
assert!(!paths.contains(&r#"{}"#.into()));
}}
"##,
dylib_path_envvar(),
dir1.display(),
dir2.display()
),
)
.build();

p.cargo("test --doc").run();
}

#[cargo_test]
fn test_panic_abort_with_dep() {
let p = project()
Expand Down

0 comments on commit 0e8a67f

Please sign in to comment.