Skip to content

Commit

Permalink
fix a number of warnings found by Starlark analyzer (bazelbuild#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-parsons authored Feb 22, 2019
1 parent a35b13a commit a2ec479
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 19 additions & 1 deletion lib/unittest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def _impl_function_name(impl):
"""Derives the name of the given rule implementation function.
This can be used for better test feedback.
Args:
impl: the rule implementation function
Returns:
The name of the given function
"""

# Starlark currently stringifies a function as "<function NAME>", so we use
Expand Down Expand Up @@ -123,6 +129,7 @@ def _make(impl, attrs = None):
_ActionInfo = provider(fields = ["actions"])

def _action_retrieving_aspect_impl(target, ctx):
_ignore = [ctx]
return [_ActionInfo(actions = target.actions)]

_action_retrieving_aspect = aspect(
Expand Down Expand Up @@ -282,6 +289,9 @@ def _end_analysis_test(env):
Args:
env: The test environment returned by `analysistest.begin`.
Returns:
A list of providers needed to automatically register the analysis test result.
"""
return [AnalysisTestResultInfo(
success = (len(env.failures) == 0),
Expand All @@ -296,6 +306,9 @@ def _end(env):
Args:
env: The test environment returned by `unittest.begin`.
Returns:
A list of providers needed to automatically register the test result.
"""

tc = env.ctx.toolchains[TOOLCHAIN_TYPE].unittest_toolchain_info
Expand Down Expand Up @@ -419,7 +432,6 @@ def _expect_failure(env, expected_failure_msg = ""):
"""
dep = _target_under_test(env)
if AnalysisFailureInfo in dep:
dep_failure = dep[AnalysisFailureInfo]
actual_errors = ""
for cause in dep[AnalysisFailureInfo].causes.to_list():
actual_errors += cause.message + "\n"
Expand All @@ -435,6 +447,9 @@ def _target_actions(env):
Args:
env: The test environment returned by `analysistest.begin`.
Returns:
A list of actions registered by the target under test
"""

# Validate?
Expand All @@ -446,6 +461,9 @@ def _target_under_test(env):
Args:
env: The test environment returned by `analysistest.begin`.
Returns:
The target under test.
"""
result = getattr(env.ctx.attr, "target_under_test")
if types.is_list(result):
Expand Down
1 change: 1 addition & 0 deletions rules/analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

def _analysis_test_impl(ctx):
"""Implementation function for analysis_test. """
_ignore = [ctx]
return [AnalysisTestResultInfo(
success = True,
message = "All targets succeeded analysis",
Expand Down
5 changes: 4 additions & 1 deletion tests/unittest_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _failure_testing_test(ctx):
return analysistest.end(env)

def _failure_testing_fake_rule(ctx):
ignore = [ctx]
fail("This rule should never work")

failure_testing_fake_rule = rule(
Expand All @@ -92,6 +93,7 @@ def _fail_unexpected_passing_test(ctx):
return analysistest.end(env)

def _fail_unexpected_passing_fake_rule(ctx):
_ignore = [ctx]
return []

fail_unexpected_passing_fake_rule = rule(
Expand Down Expand Up @@ -168,7 +170,8 @@ def unittest_passing_tests_suite():
Not all tests are included. Some unittest.bzl tests verify a test fails
when assertions are not met. Such tests must be run in an e2e shell test.
This suite only includes tests which verify success tests."""
This suite only includes tests which verify success tests.
"""
unittest.suite(
"unittest_tests",
basic_passing_test,
Expand Down

0 comments on commit a2ec479

Please sign in to comment.