-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cd5498
commit 0b7e46b
Showing
8 changed files
with
143 additions
and
30 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
load(":compile_data_test.bzl", "compile_data_test_suite") | ||
|
||
compile_data_test_suite( | ||
name = "compile_data_test_suite", | ||
) |
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,28 @@ | ||
/// Data loaded from compile data | ||
pub const COMPILE_DATA: &str = include_str!("compile_data.txt"); | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
/// A test that is expected to be compiled from a target that does not | ||
/// directly populate the `compile_data` attribute | ||
#[test] | ||
fn test_compile_data_contents() { | ||
assert_eq!(COMPILE_DATA, "compile data contents\n"); | ||
} | ||
|
||
|
||
/// An extra module that tests the `rust_test` rule wrapping the | ||
/// `rust_library` is able to provide it's own compile data. | ||
#[cfg(test_compile_data)] | ||
mod test_compile_data { | ||
const TEST_COMPILE_DATA: &str = include_str!("test_compile_data.txt"); | ||
|
||
#[test] | ||
fn test_compile_data_contents() { | ||
assert_eq!(TEST_COMPILE_DATA, "test compile data contents\n"); | ||
} | ||
} | ||
|
||
} |
File renamed without changes.
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,100 @@ | ||
"""Unittest to verify compile_data (attribute) propagation""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
load("//rust:defs.bzl", "rust_common", "rust_library", "rust_test") | ||
|
||
def _target_has_compile_data(ctx, expected): | ||
env = analysistest.begin(ctx) | ||
target = analysistest.target_under_test(env) | ||
|
||
# Extract compile_data from a target expected to have a `CrateInfo` provider | ||
crate_info = target[rust_common.crate_info] | ||
compile_data = crate_info.compile_data.to_list() | ||
|
||
# Ensure compile data was correctly propagated to the provider | ||
asserts.equals( | ||
env, | ||
sorted([data.short_path for data in compile_data]), | ||
expected, | ||
) | ||
|
||
return analysistest.end(env) | ||
|
||
def _compile_data_propagates_to_crate_info_test_impl(ctx): | ||
return _target_has_compile_data( | ||
ctx, | ||
["test/unit/compile_data/compile_data.txt"], | ||
) | ||
|
||
def _wrapper_rule_propagates_to_crate_info_test_impl(ctx): | ||
return _target_has_compile_data( | ||
ctx, | ||
["test/unit/compile_data/compile_data.txt"], | ||
) | ||
|
||
def _wrapper_rule_propagates_and_joins_compiel_data_test_impl(ctx): | ||
return _target_has_compile_data( | ||
ctx, | ||
[ | ||
"test/unit/compile_data/compile_data.txt", | ||
"test/unit/compile_data/test_compile_data.txt", | ||
], | ||
) | ||
|
||
compile_data_propagates_to_crate_info_test = analysistest.make(_compile_data_propagates_to_crate_info_test_impl) | ||
wrapper_rule_propagates_to_crate_info_test = analysistest.make(_wrapper_rule_propagates_to_crate_info_test_impl) | ||
wrapper_rule_propagates_and_joins_compiel_data_test = analysistest.make(_wrapper_rule_propagates_and_joins_compiel_data_test_impl) | ||
|
||
def _define_test_targets(): | ||
# Note that this is the only target which assigns the `compile_data` attribute | ||
rust_library( | ||
name = "compile_data", | ||
srcs = ["compile_data.rs"], | ||
compile_data = ["compile_data.txt"], | ||
edition = "2018", | ||
) | ||
|
||
rust_test( | ||
name = "compile_data_unit_test", | ||
crate = ":compile_data", | ||
) | ||
|
||
rust_test( | ||
name = "test_compile_data_unit_test", | ||
compile_data = ["test_compile_data.txt"], | ||
crate = ":compile_data", | ||
rustc_flags = ["--cfg=test_compile_data"], | ||
) | ||
|
||
def compile_data_test_suite(name): | ||
"""Entry-point macro called from the BUILD file. | ||
Args: | ||
name (str): Name of the macro. | ||
""" | ||
|
||
_define_test_targets() | ||
|
||
compile_data_propagates_to_crate_info_test( | ||
name = "compile_data_propagates_to_crate_info_test", | ||
target_under_test = ":compile_data", | ||
) | ||
|
||
wrapper_rule_propagates_to_crate_info_test( | ||
name = "wrapper_rule_propagates_to_crate_info_test", | ||
target_under_test = ":compile_data_unit_test", | ||
) | ||
|
||
wrapper_rule_propagates_and_joins_compiel_data_test( | ||
name = "wrapper_rule_propagates_and_joins_compiel_data_test", | ||
target_under_test = ":test_compile_data_unit_test", | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [ | ||
":compile_data_propagates_to_crate_info_test", | ||
":wrapper_rule_propagates_to_crate_info_test", | ||
":wrapper_rule_propagates_and_joins_compiel_data_test", | ||
], | ||
) |
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 @@ | ||
test compile data contents |