aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/google/devtools')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java68
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java15
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java7
3 files changed, 65 insertions, 25 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
index e60bfebff6..a3cb103758 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
@@ -409,16 +409,25 @@ public class AspectTest extends AnalysisTestCase {
* Rule definitions to be used in emptyAspectAttributesAreAvailableInRuleContext().
*/
public static class EmptyAspectAttributesAreAvailableInRuleContext {
- public static final MockRule TEST_RULE = () ->
- MockRule.ancestor(TestAspects.BASE_RULE.getClass()).factory(DummyRuleFactory.class).define(
- "testrule",
- (builder, env) ->
- builder
- .add(attr("foo", LABEL_LIST).legacyAllowAnyFileType()
- .aspect(new AspectWithEmptyLateBoundAttribute())));
+ public static final MockRule TEST_RULE =
+ () ->
+ MockRule.ancestor(TestAspects.BASE_RULE.getClass())
+ .factory(DummyRuleFactory.class)
+ .define(
+ "testrule",
+ (builder, env) ->
+ builder.add(
+ attr("foo", LABEL_LIST)
+ .legacyAllowAnyFileType()
+ .aspect(AspectWithEmptyLateBoundAttribute.INSTANCE)));
public static class AspectWithEmptyLateBoundAttribute extends NativeAspectClass
implements ConfiguredAspectFactory {
+ static final AspectWithEmptyLateBoundAttribute INSTANCE =
+ new AspectWithEmptyLateBoundAttribute();
+
+ private AspectWithEmptyLateBoundAttribute() {}
+
@Override
public AspectDefinition getDefinition(AspectParameters params) {
return new AspectDefinition.Builder(this)
@@ -449,8 +458,13 @@ public class AspectTest extends AnalysisTestCase {
*/
@Test
public void emptyAspectAttributesAreAvailableInRuleContext() throws Exception {
- setRulesAvailableInTests(TestAspects.BASE_RULE,
- EmptyAspectAttributesAreAvailableInRuleContext.TEST_RULE);
+ setRulesAndAspectsAvailableInTests(
+ ImmutableList.of(
+ TestAspects.SIMPLE_ASPECT,
+ EmptyAspectAttributesAreAvailableInRuleContext.AspectWithEmptyLateBoundAttribute
+ .INSTANCE),
+ ImmutableList.of(
+ TestAspects.BASE_RULE, EmptyAspectAttributesAreAvailableInRuleContext.TEST_RULE));
pkg("a",
"testrule(name='a', foo=[':b'])",
"testrule(name='b')");
@@ -462,19 +476,30 @@ public class AspectTest extends AnalysisTestCase {
* Rule definitions to be used in extraActionsAreEmitted().
*/
public static class ExtraActionsAreEmitted {
- public static final MockRule TEST_RULE = () ->
- MockRule.ancestor(TestAspects.BASE_RULE.getClass()).factory(DummyRuleFactory.class).define(
- "testrule",
- (builder, env) ->
- builder
- .add(attr("foo", LABEL_LIST).legacyAllowAnyFileType()
- .aspect(new AspectThatRegistersAction()))
- .add(attr(":action_listener", LABEL_LIST)
- .cfg(HostTransition.INSTANCE)
- .value(ACTION_LISTENER)));
+ public static final MockRule TEST_RULE =
+ () ->
+ MockRule.ancestor(TestAspects.BASE_RULE.getClass())
+ .factory(DummyRuleFactory.class)
+ .define(
+ "testrule",
+ (builder, env) ->
+ builder
+ .add(
+ attr("foo", LABEL_LIST)
+ .legacyAllowAnyFileType()
+ .aspect(AspectThatRegistersAction.INSTANCE))
+ .add(
+ attr(":action_listener", LABEL_LIST)
+ .cfg(HostTransition.INSTANCE)
+ .value(ACTION_LISTENER)));
public static class AspectThatRegistersAction extends NativeAspectClass
implements ConfiguredAspectFactory {
+
+ static final AspectThatRegistersAction INSTANCE = new AspectThatRegistersAction();
+
+ private AspectThatRegistersAction() {}
+
@Override
public AspectDefinition getDefinition(AspectParameters params) {
return new AspectDefinition.Builder(this).build();
@@ -500,7 +525,10 @@ public class AspectTest extends AnalysisTestCase {
*/
@Test
public void extraActionsAreEmitted() throws Exception {
- setRulesAvailableInTests(TestAspects.BASE_RULE, ExtraActionsAreEmitted.TEST_RULE);
+ setRulesAndAspectsAvailableInTests(
+ ImmutableList.of(
+ TestAspects.SIMPLE_ASPECT, ExtraActionsAreEmitted.AspectThatRegistersAction.INSTANCE),
+ ImmutableList.of(TestAspects.BASE_RULE, ExtraActionsAreEmitted.TEST_RULE));
useConfiguration("--experimental_action_listener=//extra_actions:listener");
scratch.file(
"extra_actions/BUILD",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
index fc9aa99a9a..279675f12c 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java
@@ -500,8 +500,21 @@ public abstract class AnalysisTestCase extends FoundationTestCase {
* Also see {@link AnalysisTestCase#setRulesAndAspectsAvailableInTests(Iterable, Iterable)}.
*/
protected void setRulesAvailableInTests(RuleDefinition... rules) throws Exception {
+ // Not all of these aspects are needed for all tests, but it makes it simple to offer them all.
setRulesAndAspectsAvailableInTests(
- ImmutableList.<NativeAspectClass>of(),
+ ImmutableList.of(
+ TestAspects.SIMPLE_ASPECT,
+ TestAspects.PARAMETRIZED_DEFINITION_ASPECT,
+ TestAspects.ASPECT_REQUIRING_PROVIDER,
+ TestAspects.FALSE_ADVERTISEMENT_ASPECT,
+ TestAspects.ALL_ATTRIBUTES_ASPECT,
+ TestAspects.ALL_ATTRIBUTES_WITH_TOOL_ASPECT,
+ TestAspects.BAR_PROVIDER_ASPECT,
+ TestAspects.EXTRA_ATTRIBUTE_ASPECT,
+ TestAspects.FOO_PROVIDER_ASPECT,
+ TestAspects.ASPECT_REQUIRING_PROVIDER_SETS,
+ TestAspects.WARNING_ASPECT,
+ TestAspects.ERROR_ASPECT),
ImmutableList.copyOf(rules));
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java b/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java
index 353f62f4a4..dcea00a3ac 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/util/TestAspects.java
@@ -444,12 +444,11 @@ public class TestAspects {
}
}
- private static final ParametrizedDefinitionAspect PARAMETRIZED_DEFINITION_ASPECT =
+ static final ParametrizedDefinitionAspect PARAMETRIZED_DEFINITION_ASPECT =
new ParametrizedDefinitionAspect();
- private static final AspectRequiringProvider ASPECT_REQUIRING_PROVIDER =
- new AspectRequiringProvider();
- private static final AspectRequiringProviderSets ASPECT_REQUIRING_PROVIDER_SETS =
+ static final AspectRequiringProvider ASPECT_REQUIRING_PROVIDER = new AspectRequiringProvider();
+ static final AspectRequiringProviderSets ASPECT_REQUIRING_PROVIDER_SETS =
new AspectRequiringProviderSets();
private static final AspectDefinition ASPECT_REQUIRING_PROVIDER_DEFINITION =
new AspectDefinition.Builder(ASPECT_REQUIRING_PROVIDER)