Expose target_under_test's bin and genfiles path (#202)
The output directories for the target under test may differ when the target is under a config transition (config_settings is passed to analysistest.make). Since analysis tests may assert about the command-line of generated actions, and those command-lines may contain paths to output files, this is useful information to expose.
This commit is contained in:
parent
0e9da0dd08
commit
376680d276
|
@ -126,11 +126,16 @@ def _make(impl, attrs = {}):
|
||||||
toolchains = [TOOLCHAIN_TYPE],
|
toolchains = [TOOLCHAIN_TYPE],
|
||||||
)
|
)
|
||||||
|
|
||||||
_ActionInfo = provider(fields = ["actions"])
|
_ActionInfo = provider(fields = ["actions", "bin_path", "genfiles_path"])
|
||||||
|
|
||||||
def _action_retrieving_aspect_impl(target, ctx):
|
def _action_retrieving_aspect_impl(target, ctx):
|
||||||
_ignore = [ctx]
|
return [
|
||||||
return [_ActionInfo(actions = target.actions)]
|
_ActionInfo(
|
||||||
|
actions = target.actions,
|
||||||
|
bin_path = ctx.bin_dir.path,
|
||||||
|
genfiles_path = ctx.genfiles_dir.path,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
_action_retrieving_aspect = aspect(
|
_action_retrieving_aspect = aspect(
|
||||||
attr_aspects = [],
|
attr_aspects = [],
|
||||||
|
@ -463,8 +468,29 @@ def _target_actions(env):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Validate?
|
# Validate?
|
||||||
dep = _target_under_test(env)
|
return _target_under_test(env)[_ActionInfo].actions
|
||||||
return dep[_ActionInfo].actions
|
|
||||||
|
def _target_bin_dir_path(env):
|
||||||
|
"""Returns ctx.bin_dir.path for the target under test.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
env: The test environment returned by `analysistest.begin`.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Output bin dir path string.
|
||||||
|
"""
|
||||||
|
return _target_under_test(env)[_ActionInfo].bin_path
|
||||||
|
|
||||||
|
def _target_genfiles_dir_path(env):
|
||||||
|
"""Returns ctx.genfiles_dir.path for the target under test.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
env: The test environment returned by `analysistest.begin`.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Output genfiles dir path string.
|
||||||
|
"""
|
||||||
|
return _target_under_test(env)[_ActionInfo].genfiles_path
|
||||||
|
|
||||||
def _target_under_test(env):
|
def _target_under_test(env):
|
||||||
"""Returns the target under test.
|
"""Returns the target under test.
|
||||||
|
@ -506,5 +532,7 @@ analysistest = struct(
|
||||||
end = _end_analysis_test,
|
end = _end_analysis_test,
|
||||||
fail = _fail,
|
fail = _fail,
|
||||||
target_actions = _target_actions,
|
target_actions = _target_actions,
|
||||||
|
target_bin_dir_path = _target_bin_dir_path,
|
||||||
|
target_genfiles_dir_path = _target_genfiles_dir_path,
|
||||||
target_under_test = _target_under_test,
|
target_under_test = _target_under_test,
|
||||||
)
|
)
|
||||||
|
|
|
@ -177,6 +177,63 @@ inspect_actions_test = analysistest.make(
|
||||||
_inspect_actions_test,
|
_inspect_actions_test,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
########################################
|
||||||
|
####### inspect_output_dirs_test #######
|
||||||
|
########################################
|
||||||
|
_OutputDirInfo = provider(fields = ["bin_path", "genfiles_path"])
|
||||||
|
|
||||||
|
def _inspect_output_dirs_test(ctx):
|
||||||
|
"""Test verifying output directories used by a test."""
|
||||||
|
env = analysistest.begin(ctx)
|
||||||
|
|
||||||
|
# Assert that the output dirs observed by the aspect added by analysistest
|
||||||
|
# are the same as those observed by the rule directly, even when that's
|
||||||
|
# under a config transition and therefore not the same as the output
|
||||||
|
# dirs used by the test rule.
|
||||||
|
bin_path = analysistest.target_bin_dir_path(env)
|
||||||
|
genfiles_path = analysistest.target_genfiles_dir_path(env)
|
||||||
|
target_under_test = analysistest.target_under_test(env)
|
||||||
|
asserts.false(env, not bin_path, "bin dir path not found.")
|
||||||
|
asserts.false(env, not genfiles_path, "genfiles path not found.")
|
||||||
|
asserts.false(
|
||||||
|
env,
|
||||||
|
bin_path == ctx.bin_dir.path,
|
||||||
|
"bin dir path expected to differ between test and target_under_test.",
|
||||||
|
)
|
||||||
|
asserts.false(
|
||||||
|
env,
|
||||||
|
genfiles_path == ctx.genfiles_dir.path,
|
||||||
|
"genfiles dir path expected to differ between test and target_under_test.",
|
||||||
|
)
|
||||||
|
asserts.equals(env, bin_path, target_under_test[_OutputDirInfo].bin_path)
|
||||||
|
asserts.equals(
|
||||||
|
env,
|
||||||
|
genfiles_path,
|
||||||
|
target_under_test[_OutputDirInfo].genfiles_path,
|
||||||
|
)
|
||||||
|
return analysistest.end(env)
|
||||||
|
|
||||||
|
def _inspect_output_dirs_fake_rule(ctx):
|
||||||
|
return [
|
||||||
|
_OutputDirInfo(
|
||||||
|
bin_path = ctx.bin_dir.path,
|
||||||
|
genfiles_path = ctx.genfiles_dir.path,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
inspect_output_dirs_fake_rule = rule(
|
||||||
|
implementation = _inspect_output_dirs_fake_rule,
|
||||||
|
)
|
||||||
|
|
||||||
|
inspect_output_dirs_test = analysistest.make(
|
||||||
|
_inspect_output_dirs_test,
|
||||||
|
# The output directories differ between the test and target under test when
|
||||||
|
# the target under test is under a config transition.
|
||||||
|
config_settings = {
|
||||||
|
"//command_line_option:compilation_mode": "fastbuild",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
def unittest_passing_tests_suite():
|
def unittest_passing_tests_suite():
|
||||||
|
@ -226,3 +283,12 @@ def unittest_passing_tests_suite():
|
||||||
name = "inspect_actions_fake_target",
|
name = "inspect_actions_fake_target",
|
||||||
tags = ["manual"],
|
tags = ["manual"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
inspect_output_dirs_test(
|
||||||
|
name = "inspect_output_dirs_test",
|
||||||
|
target_under_test = ":inspect_output_dirs_fake_target",
|
||||||
|
)
|
||||||
|
inspect_output_dirs_fake_rule(
|
||||||
|
name = "inspect_output_dirs_fake_target",
|
||||||
|
tags = ["manual"],
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue