aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Wagner-Hall <dawagner@gmail.com>2021-09-23 21:21:58 +0100
committerGitHub <noreply@github.com>2021-09-23 16:21:58 -0400
commit08398cdc99b2042dfb5748fd49ef8393b9045c8e (patch)
tree8a9bbd533bd4606b0ee09cf3af7a5816690e477c /tests
parentdf3c9e2735f02a7fe8cd80db4db00fec8e13d25f (diff)
downloadbazel-skylib-08398cdc99b2042dfb5748fd49ef8393b9045c8e.tar.gz
Allow specifying additional aspects to tut (#299)
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_tests.bzl53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl
index a3741f6..abddbdd 100644
--- a/tests/unittest_tests.bzl
+++ b/tests/unittest_tests.bzl
@@ -194,6 +194,50 @@ inspect_actions_test = analysistest.make(
_inspect_actions_test,
)
+####################################
+####### inspect_aspect_test #######
+####################################
+_AddedByAspectInfo = provider(
+ doc = "Example provider added by example aspect",
+ fields = {
+ "value": "(str)",
+ },
+)
+
+def _example_aspect_impl(target, ctx):
+ return [
+ _AddedByAspectInfo(value = "attached by aspect"),
+ ]
+
+example_aspect = aspect(
+ implementation = _example_aspect_impl,
+)
+
+def _inspect_aspect_test(ctx):
+ """Test verifying aspect run on a target."""
+ env = analysistest.begin(ctx)
+
+ tut = env.ctx.attr.target_under_test
+ asserts.equals(env, "attached by aspect", tut[_AddedByAspectInfo].value)
+ return analysistest.end(env)
+
+def _inspect_aspect_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_aspect_fake_rule = rule(
+ implementation = _inspect_aspect_fake_rule,
+)
+
+inspect_aspect_test = analysistest.make(
+ _inspect_aspect_test,
+ extra_target_under_test_aspects = [example_aspect],
+)
+
########################################
####### inspect_output_dirs_test #######
########################################
@@ -293,6 +337,15 @@ def unittest_passing_tests_suite():
tags = ["manual"],
)
+ inspect_aspect_test(
+ name = "inspect_aspect_test",
+ target_under_test = ":inspect_aspect_fake_target",
+ )
+ inspect_aspect_fake_rule(
+ name = "inspect_aspect_fake_target",
+ tags = ["manual"],
+ )
+
inspect_output_dirs_test(
name = "inspect_output_dirs_test",
target_under_test = ":inspect_output_dirs_fake_target",