forked from bazelbuild/rules_rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow crate test configurations to allow for ‟dev-deps”
Due to the way unit tests are handled with the rules, it is tricky for a crate containing internal test configuration to have additional (test only) deps. Consider some source code like such ```rust fn some_fn() -> u32 { 2 } mod tests { use super::some_fn(); // This following line is not going to work use pretty_assertions::assert_eq; #[test] fn test_is_2() { assert_eq!(1, some_fn()); } } ``` With a build function like so ```python rust_library( name = "example", srcs = ["lib.rs"] ) rust_test( name = "example_test", deps = [ ":example", "//third_party/rust:pretty_assertion", ], ) ``` Presently, due to the handling of ‟unit tests” the extra deps will conflict with rust_rules ideas about how to identify the test, and give an error along the lines of ``` attribute srcs: No lib.rs or example_test.rs source file found. ``` With this change we make it possible for tests to express ‟dev dependencies”. This lets us avoid adding deps that are strictly for testing. This is somewhat distinct from `testonly` attributes as it does not always hold that a dependency is always and only ever `testonly` in all library circumstances, consider for example the usage of https://github.com/pingcap/fail-rs. There are instances where this needs to be used both in source code *and* test code, and is not easily seperated from a cargo-raze perspective. Closes bazelbuild#202 WIP
- Loading branch information
1 parent
b3cc7e4
commit 15ab5a1
Showing
18 changed files
with
173 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,5 @@ rust_binary( | |
|
||
rust_test( | ||
name = "simple_test", | ||
deps = [":simple_example"], | ||
crate = ":simple_example", | ||
) |
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 |
---|---|---|
|
@@ -32,5 +32,5 @@ rust_library( | |
|
||
rust_test( | ||
name = "printer_test", | ||
deps = [":printer"], | ||
crate = ":printer", | ||
) |
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
Empty file.
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 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load( | ||
"//rust:rust.bzl", | ||
"rust_library", | ||
) | ||
|
||
rust_library( | ||
name = "dep", | ||
srcs = ["src/lib.rs"], | ||
) |
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,4 @@ | ||
/// This exists purely to give us a dep to compile against | ||
pub fn example_test_dep_fn() -> u32 { | ||
1 | ||
} |
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,19 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load( | ||
"//rust:rust.bzl", | ||
"rust_library", | ||
"rust_test", | ||
) | ||
|
||
rust_library( | ||
name = "inline", | ||
edition = "2018", | ||
srcs = ["src/lib.rs"], | ||
) | ||
|
||
rust_test( | ||
name = "inline_test", | ||
crate = ":inline", | ||
deps = ["//test/inline_test_with_deps/dep"], | ||
) |
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 @@ | ||
#[allow(dead_code)] | ||
fn multiply(val: u32) -> u32 { | ||
val * 100 | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::multiply; | ||
use dep::example_test_dep_fn; | ||
|
||
#[test] | ||
fn test() { | ||
assert_eq!(100, multiply(example_test_dep_fn())); | ||
} | ||
} |
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,20 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load( | ||
"//rust:rust.bzl", | ||
"rust_library", | ||
"rust_test", | ||
) | ||
|
||
rust_library( | ||
name = "inline", | ||
edition = "2018", | ||
srcs = ["src/lib.rs"], | ||
) | ||
|
||
rust_test( | ||
name = "inline_test", | ||
crate = ":inline", | ||
srcs = ["src/extra.rs"], | ||
deps = ["//test/inline_test_with_deps/dep"], | ||
) |
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,4 @@ | ||
#[cfg(test)] | ||
pub(crate) fn extra_test_fn() -> u32 { | ||
100 | ||
} |
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,18 @@ | ||
#[allow(dead_code)] | ||
fn multiply(val: u32) -> u32 { | ||
val * 100 | ||
} | ||
|
||
#[cfg(test)] | ||
mod extra; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::{multiply, extra}; | ||
use dep::example_test_dep_fn; | ||
|
||
#[test] | ||
fn test() { | ||
assert_eq!(extra::extra_test_fn(), multiply(example_test_dep_fn())); | ||
} | ||
} |
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