diff options
author | c-parsons <cparsons@google.com> | 2019-02-20 15:32:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-20 15:32:47 -0500 |
commit | a35b13a1c9a3d43e81fcfaca42155c53d4b31cb7 (patch) | |
tree | 9a6a2afb0256375ef039c24a7f702982aebb2196 /tests/unittest_tests.bzl | |
parent | a5655124382ccbf7214456468cec6b7ec2e39c41 (diff) | |
download | bazel-skylib-a35b13a1c9a3d43e81fcfaca42155c53d4b31cb7.tar.gz |
analysistest API for retrieval of actions registered by target under test
Diffstat (limited to 'tests/unittest_tests.bzl')
-rw-r--r-- | tests/unittest_tests.bzl | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 9bdecc6..20fd890 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -35,7 +35,7 @@ def _change_setting_test(ctx): """Test to verify that an analysis test may change configuration.""" env = analysistest.begin(ctx) - dep_min_os_version = ctx.attr.target_under_test[0][_ChangeSettingInfo].min_os_version + dep_min_os_version = analysistest.target_under_test(env)[_ChangeSettingInfo].min_os_version asserts.equals(env, "1234.5678", dep_min_os_version) return analysistest.end(env) @@ -132,6 +132,35 @@ change_setting_with_failure_test = analysistest.make( }, ) +#################################### +####### inspect_actions_test ####### +#################################### +def _inspect_actions_test(ctx): + """Test verifying actions registered by a target.""" + env = analysistest.begin(ctx) + + actions = analysistest.target_actions(env) + asserts.equals(env, 1, len(actions)) + action_output = actions[0].outputs.to_list()[0] + asserts.equals(env, "out.txt", action_output.basename) + return analysistest.end(env) + +def _inspect_actions_fake_rule(ctx): + out_file = ctx.actions.declare_file("out.txt") + ctx.actions.run_shell( + command = "echo 'hello' > %s" % out_file.basename, + outputs = [out_file], + ) + return [DefaultInfo(files = depset([out_file]))] + +inspect_actions_fake_rule = rule( + implementation = _inspect_actions_fake_rule, +) + +inspect_actions_test = analysistest.make( + _inspect_actions_test, +) + ######################################### def unittest_passing_tests_suite(): @@ -171,3 +200,12 @@ def unittest_passing_tests_suite(): name = "change_setting_with_failure_fake_target", tags = ["manual"], ) + + inspect_actions_test( + name = "inspect_actions_test", + target_under_test = ":inspect_actions_fake_target", + ) + inspect_actions_fake_rule( + name = "inspect_actions_fake_target", + tags = ["manual"], + ) |