|
17 | 17 | load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") |
18 | 18 | load("//lib:analysis_test.bzl", "analysis_test", "test_suite") |
19 | 19 | load("//lib:truth.bzl", "matching") |
20 | | -load("//lib:util.bzl", "TestingAspectInfo") |
| 20 | +load("//lib:util.bzl", "TestingAspectInfo", "util") |
21 | 21 |
|
22 | 22 | _TestingFlagsInfo = provider( |
23 | 23 | doc = "Flags used for testing", |
@@ -223,6 +223,42 @@ def test_inspect_aspect(name): |
223 | 223 | def _test_inspect_aspect(env, target): |
224 | 224 | env.expect.that_str(target[_AddedByAspectInfo].value).equals("attached by aspect") |
225 | 225 |
|
| 226 | +#################################### |
| 227 | +####### inspect_aspect_actions_test ####### |
| 228 | +#################################### |
| 229 | +def _inspect_actions_fake_aspect_impl(_target, ctx): |
| 230 | + out_file = ctx.actions.declare_file("aspect_out.txt") |
| 231 | + ctx.actions.run_shell( |
| 232 | + command = "echo 'hello' > %s" % out_file.basename, |
| 233 | + outputs = [out_file], |
| 234 | + mnemonic = "RunningHello", |
| 235 | + ) |
| 236 | + return [] |
| 237 | + |
| 238 | +_inspect_actions_fake_aspect = aspect( |
| 239 | + implementation = _inspect_actions_fake_aspect_impl, |
| 240 | +) |
| 241 | + |
| 242 | +_inspect_actions_fake_aspect_testing_aspect = util.make_testing_aspect( |
| 243 | + aspects = [_inspect_actions_fake_aspect], |
| 244 | +) |
| 245 | + |
| 246 | +def test_inspect_aspect_actions(name): |
| 247 | + """Test verifying actions registered by an aspect.""" |
| 248 | + native.filegroup(name = name + "_subject") |
| 249 | + |
| 250 | + analysis_test( |
| 251 | + name = name, |
| 252 | + target = name + "_subject", |
| 253 | + impl = _test_inspect_aspect_actions, |
| 254 | + testing_aspect = _inspect_actions_fake_aspect_testing_aspect, |
| 255 | + ) |
| 256 | + |
| 257 | +def _test_inspect_aspect_actions(env, target): |
| 258 | + env.expect.that_int(len(target[TestingAspectInfo].actions)).equals(1) |
| 259 | + action_output = target[TestingAspectInfo].actions[0].outputs.to_list()[0] |
| 260 | + env.expect.that_str(action_output.basename).equals("aspect_out.txt") |
| 261 | + |
226 | 262 | ######################################## |
227 | 263 | ####### inspect_output_dirs_test ####### |
228 | 264 | ######################################## |
@@ -449,5 +485,6 @@ def analysis_test_test_suite(name): |
449 | 485 | test_change_setting_with_failure, |
450 | 486 | test_inspect_actions, |
451 | 487 | test_inspect_aspect, |
| 488 | + test_inspect_aspect_actions, |
452 | 489 | ], |
453 | 490 | ) |
0 commit comments