Skip to content

Commit 0e8a67f

Browse files
committed
test(doctest): doctest doesn't set shared libs to search path
This new test demonstrate the current behavior.
1 parent 91f75ac commit 0e8a67f

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/testsuite/test.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use cargo_test_support::{
77
};
88
use cargo_test_support::{cross_compile, paths};
99
use cargo_test_support::{rustc_host, rustc_host_env, sleep_ms};
10+
use cargo_util::paths::dylib_path_envvar;
1011
use std::fs;
1112

1213
#[cargo_test]
@@ -2767,6 +2768,53 @@ fn only_test_docs() {
27672768
.run();
27682769
}
27692770

2771+
#[cargo_test]
2772+
fn doctest_with_library_paths() {
2773+
let p = project();
2774+
// Only link search directories within the target output directory are
2775+
// propagated through to dylib_path_envvar() (see #3366).
2776+
let dir1 = p.target_debug_dir().join("foo\\backslash");
2777+
let dir2 = p.target_debug_dir().join("dir=containing=equal=signs");
2778+
2779+
let p = p
2780+
.file("Cargo.toml", &basic_manifest("foo", "0.0.0"))
2781+
.file(
2782+
"build.rs",
2783+
&format!(
2784+
r##"
2785+
fn main() {{
2786+
println!(r#"cargo::rustc-link-search=native={}"#);
2787+
println!(r#"cargo::rustc-link-search={}"#);
2788+
}}
2789+
"##,
2790+
dir1.display(),
2791+
dir2.display()
2792+
),
2793+
)
2794+
.file(
2795+
"src/lib.rs",
2796+
&format!(
2797+
r##"
2798+
/// ```
2799+
/// foo::assert_search_path();
2800+
/// ```
2801+
pub fn assert_search_path() {{
2802+
let search_path = std::env::var_os("{}").unwrap();
2803+
let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
2804+
assert!(!paths.contains(&r#"{}"#.into()));
2805+
assert!(!paths.contains(&r#"{}"#.into()));
2806+
}}
2807+
"##,
2808+
dylib_path_envvar(),
2809+
dir1.display(),
2810+
dir2.display()
2811+
),
2812+
)
2813+
.build();
2814+
2815+
p.cargo("test --doc").run();
2816+
}
2817+
27702818
#[cargo_test]
27712819
fn test_panic_abort_with_dep() {
27722820
let p = project()

0 commit comments

Comments
 (0)