Skip to content

Commit

Permalink
Pass fragments through to analysis tests rule constructors. (bazelb…
Browse files Browse the repository at this point in the history
…uild#190)

Passing fragments through to the rule allows rules to access language specific features.
  • Loading branch information
gabebear authored and aiuto committed Oct 2, 2019
1 parent d8387f7 commit 720f594
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/unittest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ _action_retrieving_aspect = aspect(
)

# TODO(cparsons): Provide more full documentation on analysis testing in README.
def _make_analysis_test(impl, expect_failure = False, attrs = {}, config_settings = {}):
def _make_analysis_test(
impl,
expect_failure = False,
attrs = {},
fragments = [],
config_settings = {}):
"""Creates an analysis test rule from its implementation function.
An analysis test verifies the behavior of a "real" rule target by examining
Expand Down Expand Up @@ -170,6 +175,8 @@ def _make_analysis_test(impl, expect_failure = False, attrs = {}, config_setting
to fail. Assertions can be made on the underlying failure using asserts.expect_failure
attrs: An optional dictionary to supplement the attrs passed to the
unit test's `rule()` constructor.
fragments: An optional list of fragment names that can be used to give rules access to
language-specific parts of configuration.
config_settings: A dictionary of configuration settings to change for the target under
test and its dependencies. This may be used to essentially change 'build flags' for
the target under test, and may thus be utilized to test multiple targets with different
Expand Down Expand Up @@ -204,6 +211,7 @@ def _make_analysis_test(impl, expect_failure = False, attrs = {}, config_setting
return rule(
impl,
attrs = attrs,
fragments = fragments,
test = True,
toolchains = [TOOLCHAIN_TYPE],
analysis_test = True,
Expand Down

0 comments on commit 720f594

Please sign in to comment.