aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar dslomov <dslomov@google.com>2017-04-11 10:34:25 +0000
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-04-11 13:50:39 +0200
commit1dadb878a59b180bf950c72ee3b4bdb8d7ea7d67 (patch)
treef5d982f173e2a37e104105e66b12a28a623e5081 /src/test
parent039b9eefc26a5816ec305f86d442affe0d8e45ba (diff)
Better error messages for non-exported values.
RELNOTES: None. PiperOrigin-RevId: 152793682
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
index 004443b0b5..76c80b6cf9 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkAspectsTest.java
@@ -534,6 +534,86 @@ public class SkylarkAspectsTest extends AnalysisTestCase {
}
@Test
+ public void aspectsNonExported() throws Exception {
+ scratch.file(
+ "test/aspect.bzl",
+ "def _aspect_impl(target, ctx):",
+ " return []",
+ "",
+ "def _rule_impl(ctx):",
+ " pass",
+ "",
+ "def mk_aspect():",
+ " return aspect(implementation=_aspect_impl)",
+ "my_rule = rule(",
+ " implementation=_rule_impl,",
+ " attrs = { 'attr' : attr.label_list(aspects = [mk_aspect()]) },",
+ ")");
+
+ scratch.file(
+ "test/BUILD",
+ "load('//test:aspect.bzl', 'my_rule')",
+ "java_library(",
+ " name = 'yyy',",
+ ")",
+ "my_rule(",
+ " name = 'xxx',",
+ " attr = [':yyy'],",
+ ")");
+
+ reporter.removeHandler(failFastHandler);
+ try {
+ AnalysisResult analysisResult = update("//test:xxx");
+ assertThat(keepGoing()).isTrue();
+ assertThat(analysisResult.hasError()).isTrue();
+ } catch (ViewCreationFailedException | TargetParsingException e) {
+ // expected
+ }
+
+ assertContainsEvent("ERROR /workspace/test/aspect.bzl:11:23");
+ assertContainsEvent("Aspects should be top-level values in extension files that define them.");
+ }
+
+ @Test
+ public void providerNonExported() throws Exception {
+ scratch.file(
+ "test/rule.bzl",
+ "def mk_provider():",
+ " return provider()",
+ "def _rule_impl(ctx):",
+ " pass",
+ "my_rule = rule(",
+ " implementation=_rule_impl,",
+ " attrs = { 'attr' : attr.label_list(providers = [mk_provider()]) },",
+ ")");
+
+ scratch.file(
+ "test/BUILD",
+ "load('//test:rule.bzl', 'my_rule')",
+ "java_library(",
+ " name = 'yyy',",
+ ")",
+ "my_rule(",
+ " name = 'xxx',",
+ " attr = [':yyy'],",
+ ")");
+
+ reporter.removeHandler(failFastHandler);
+ try {
+ AnalysisResult analysisResult = update("//test:xxx");
+ assertThat(keepGoing()).isTrue();
+ assertThat(analysisResult.hasError()).isTrue();
+ } catch (ViewCreationFailedException | TargetParsingException e) {
+ // expected
+ }
+
+ assertContainsEvent("ERROR /workspace/test/rule.bzl:7:23");
+ assertContainsEvent(
+ "Providers should be top-level values in extension files that define them.");
+ }
+
+
+ @Test
public void aspectOnLabelAttr() throws Exception {
scratch.file(
"test/aspect.bzl",