diff --git a/test/renamed_deps/BUILD b/test/renamed_deps/BUILD new file mode 100644 index 0000000000..909ae16734 --- /dev/null +++ b/test/renamed_deps/BUILD @@ -0,0 +1,54 @@ +load( + "//rust:rust.bzl", + "rust_doc_test", + "rust_library", + "rust_test", +) + +rust_library( + name = "mod1", + srcs = ["mod1.rs"], +) + +rust_library( + name = "mod2", + srcs = ["mod2.rs"], + deps = [":mod1"], +) + +rust_library( + name = "mod3", + srcs = ["mod3.rs"], + aliases = { + ":mod1": "alias_a", + ":mod2": "alias_b", + }, + deps = [ + ":mod1", + ":mod2", + ], +) + +rust_test( + name = "mod1_test", + crate = ":mod1", +) + +rust_test( + name = "mod2_test", + crate = ":mod2", +) + +rust_test( + name = "mod3_test", + crate = ":mod3", + aliases = { + ":mod1": "alias_a", + ":mod2": "alias_b", + }, +) + +rust_doc_test( + name = "mod3_doc_test", + dep = ":mod3", +) diff --git a/test/renamed_deps/mod1.rs b/test/renamed_deps/mod1.rs new file mode 100644 index 0000000000..a66f490afb --- /dev/null +++ b/test/renamed_deps/mod1.rs @@ -0,0 +1,11 @@ +pub fn world() -> String { + "world".to_owned() +} + +#[cfg(test)] +mod test { + #[test] + fn test_world() { + assert_eq!(super::world(), "world"); + } +} diff --git a/test/renamed_deps/mod2.rs b/test/renamed_deps/mod2.rs new file mode 100644 index 0000000000..cff993b33f --- /dev/null +++ b/test/renamed_deps/mod2.rs @@ -0,0 +1,22 @@ +extern crate mod1; + +pub fn greeter(name: &str) -> String { + format!("Hello, {}!", name) +} + +pub fn default_greeter() -> String { + greeter(&mod1::world()) +} + +#[cfg(test)] +mod test { + #[test] + fn test_greeter() { + assert_eq!(super::greeter("Bob"), "Hello, Bob!"); + } + + #[test] + fn test_default_greeter() { + assert_eq!(super::default_greeter(), "Hello, world!"); + } +} diff --git a/test/renamed_deps/mod3.rs b/test/renamed_deps/mod3.rs new file mode 100644 index 0000000000..4942bf2086 --- /dev/null +++ b/test/renamed_deps/mod3.rs @@ -0,0 +1,38 @@ +// This crate depends on 2 crates with one of them depending on the other one. +// If the crates are not set correctly in the dependency chain, this crate won't +// compile. The order of the `extern crate` is important to trigger that bug. +extern crate alias_a; +extern crate alias_b; + +pub fn greet(name: &str) { + println!("{}", alias_b::greeter(name)) +} + +pub fn greet_default() { + println!("{}", alias_b::default_greeter()) +} + +/// This is a documentation. +/// +/// # Examples +/// +/// ```rust +/// assert!( +/// mod3::am_i_the_world("world") == true +/// ); +/// assert!( +/// mod3::am_i_the_world("myself") == false +/// ); +/// ``` +pub fn am_i_the_world(me: &str) -> bool { + return me == alias_a::world(); +} + +#[cfg(test)] +mod test { + #[test] + fn test_am_i_the_world() { + assert!(super::am_i_the_world("world")); + assert!(!super::am_i_the_world("bob")); + } +}