Skip to content

Commit

Permalink
Add tests for renamed crates
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBowyer committed Jan 6, 2020
1 parent 5cc6f80 commit f97bbc2
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/renamed_deps/BUILD
Original file line number Diff line number Diff line change
@@ -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",
)
11 changes: 11 additions & 0 deletions test/renamed_deps/mod1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub fn world() -> String {
"world".to_owned()
}

#[cfg(test)]
mod test {
#[test]
fn test_world() {
assert_eq!(super::world(), "world");
}
}
22 changes: 22 additions & 0 deletions test/renamed_deps/mod2.rs
Original file line number Diff line number Diff line change
@@ -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!");
}
}
38 changes: 38 additions & 0 deletions test/renamed_deps/mod3.rs
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit f97bbc2

Please sign in to comment.