Skip to content

Commit

Permalink
Add a test for subrule bug that permits a subrule to call another
Browse files Browse the repository at this point in the history
The current code assumes a subrule is always called from a rule/aspect implementation and does not check if we're evaluating a subrule. So the call works as long the called subrule was declared on the rule/aspect.

PiperOrigin-RevId: 580145481
Change-Id: I1e2fcf44b3b6245589dddc91c524cffc473ca186
  • Loading branch information
hvadehra authored and copybara-github committed Nov 7, 2023
1 parent 3018d2c commit 41a1fbc
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ public void testSubrule_aspectMustDeclareSubrule() throws Exception {
+ " declare '_my_subrule' in 'subrules'");
}

// this is a bug that must be fixed
@Test
public void testSubruleCallingSibling_succeeds() throws Exception {
scratch.file(
"subrule_testing/myrule.bzl",
"def _subrule1_impl(ctx):",
" return 'result from subrule1'",
"_my_subrule1 = subrule(implementation = _subrule1_impl)",
"",
"def _subrule2_impl(ctx):",
" return _my_subrule1()",
"_my_subrule2 = subrule(implementation = _subrule2_impl)",
"",
"MyInfo=provider()",
"def _rule_impl(ctx):",
" res = _my_subrule2()",
" return [MyInfo(result = res)]",
"",
"my_rule = rule(_rule_impl, subrules = [_my_subrule2, _my_subrule1])");
scratch.file(
"subrule_testing/BUILD",
//
"load('myrule.bzl', 'my_rule')",
"my_rule(name = 'foo')");

StructImpl provider =
getProvider("//subrule_testing:foo", "//subrule_testing:myrule.bzl", "MyInfo");

assertThat(provider).isNotNull();
assertThat(provider.getValue("result")).isEqualTo("result from subrule1");
}

@Test
public void testSubrule_implementationMustAcceptSubruleContext() throws Exception {
scratch.file(
Expand Down

0 comments on commit 41a1fbc

Please sign in to comment.