-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for shared test-only modules (#2734)
Currently, `rust_test_suite` is not capable of supporting integration tests with shared modules. A very basic example is: ``` [crate]/ src/ lib.rs tests/ integration_test_a.rs integration_test_b.rs util/ mod.rs ``` With `integration_test_a.rs` and `integration_test_b.rs` importing code from `util`. This PR adds a `shared_srcs` argument to `rust_test_suite`. That way, we can finally compile and run those tests with: ```python rust_test_suite( name = "integrated_tests_suite", srcs = glob(["tests/**"]), shared_srcs = ["tests/util/mod.rs"], deps = [":example_dep"], ) ```
- Loading branch information
1 parent
6080e49
commit b3fe74c
Showing
8 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//rust:defs.bzl", "rust_library", "rust_test_suite") | ||
|
||
rust_library( | ||
name = "math_lib", | ||
srcs = ["src/lib.rs"], | ||
edition = "2018", | ||
) | ||
|
||
rust_test_suite( | ||
name = "tests_suite", | ||
srcs = glob(["tests/**"]), | ||
edition = "2018", | ||
shared_srcs = glob(["tests/helpers/**"]), | ||
deps = [":math_lib"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Calculate the n'th fibonacci number | ||
pub fn fibonacci(n: i32) -> i32 { | ||
match n { | ||
0 => 1, | ||
1 => 1, | ||
_ => fibonacci(n - 1) + fibonacci(n - 2), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Binet's formula for checking Fibonacci numbers | ||
pub fn is_fibonacci(x: i32) -> bool { | ||
is_perfect_square(5 * x * x + 4) || is_perfect_square(5 * x * x - 4) | ||
} | ||
|
||
fn is_perfect_square(x: i32) -> bool { | ||
if x < 0 { | ||
return false; | ||
} | ||
let y = (x as f64).sqrt() as i32; | ||
y * y == x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod helpers; | ||
|
||
use helpers::is_fibonacci; | ||
use math_lib::fibonacci; | ||
|
||
#[test] | ||
fn fibonacci_test() { | ||
let fib6 = fibonacci(6); | ||
assert_eq!(fib6, fibonacci(5) + fibonacci(4)); | ||
assert!(is_fibonacci(fib6)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod helpers; | ||
|
||
use helpers::is_fibonacci; | ||
use math_lib::fibonacci; | ||
|
||
#[test] | ||
fn fibonacci_test() { | ||
let fib7 = fibonacci(7); | ||
assert_eq!(fib7, fibonacci(6) + fibonacci(5)); | ||
assert!(is_fibonacci(fib7)); | ||
} |