diff options
author | 2016-09-30 20:52:31 +0000 | |
---|---|---|
committer | 2016-10-04 08:53:14 +0000 | |
commit | 3c0d64886d2f7f6b2015780f1628b1391c320d0f (patch) | |
tree | 5fa355b7828a9ad924da8f7c4c60d4c43de38e3d /src/test/java/com/google | |
parent | bba8f91a309e9c715ac8a1ac76821247f4887d50 (diff) |
Proper error messages when built-in rule attributes are overridden #1811
--
MOS_MIGRATED_REVID=134823021
Diffstat (limited to 'src/test/java/com/google')
2 files changed, 42 insertions, 1 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java index 5365d855a3..2692f5de0b 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryIntegrationTest.java @@ -335,4 +335,30 @@ public class SkylarkRepositoryIntegrationTest extends BuildViewTestCase { invalidatePackages(); assertThat(getRuleContext(getConfiguredTarget("//:data")).getWorkspaceName()).isEqualTo("bleh"); } + + @Test + public void testSkylarkRepositoryCannotOverrideBuiltInAttribute() throws Exception { + scratch.file( + "def.bzl", + "def _impl(ctx):", + " print(ctx.attr.name)", + "", + "repo = repository_rule(", + " implementation=_impl,", + " attrs={'name': attr.string(mandatory=True)})"); + scratch.file(rootDirectory.getRelative("BUILD").getPathString()); + scratch.overwriteFile( + rootDirectory.getRelative("WORKSPACE").getPathString(), + "load('//:def.bzl', 'repo')", + "repo(name='foo')"); + + invalidatePackages(); + try { + getConfiguredTarget("@foo//:bar"); + fail(); + } catch (AssertionError e) { + assertThat(e.getMessage()).contains("There is already a built-in attribute 'name' " + + "which cannot be overridden"); + } + } } diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java index 03590c7979..2367da2cf5 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java @@ -97,13 +97,28 @@ public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase { Assert.fail("Expected error '" + "There is already a built-in attribute 'tags' which cannot be overridden" + "' but got no error"); - } catch (IllegalArgumentException | EvalException e) { + } catch (EvalException e) { assertThat(e).hasMessage( "There is already a built-in attribute 'tags' which cannot be overridden"); } } @Test + public void testCannotOverrideBuiltInAttributeName() throws Exception { + ev.setFailFast(true); + try { + evalAndExport( + "def impl(ctx): return", "r = rule(impl, attrs = {'name': attr.string()})"); + Assert.fail("Expected error '" + + "There is already a built-in attribute 'name' which cannot be overridden" + + "' but got no error"); + } catch (EvalException e) { + assertThat(e).hasMessage( + "There is already a built-in attribute 'name' which cannot be overridden"); + } + } + + @Test public void testImplicitArgsAttribute() throws Exception { evalAndExport( "def _impl(ctx):", |