diff options
author | 2016-02-10 16:03:47 +0000 | |
---|---|---|
committer | 2016-02-11 11:48:32 +0000 | |
commit | 466873e272d040f466150469ceb172e80a6a67f4 (patch) | |
tree | 3f326630f3f17fc7dc3ed3940b5affe6f871d39d /src/test/java/com/google/devtools/build/lib/skylark | |
parent | 6e638ef4e756e4d53925be580096b254d7f764eb (diff) |
Forbid overloading of a repository outside of the first part of the workspace file
Fixes #824.
--
MOS_MIGRATED_REVID=114326952
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/skylark')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java index 7f9e9e1713..4040b86faf 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java @@ -81,7 +81,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { ")"); } - private void setUpAttributeErrorTest() throws Exception { + private void setUpAttributeErrorTest() throws Exception { scratch.file("test/BUILD", "load('/test/macros', 'macro_native_rule', 'macro_skylark_rule', 'skylark_rule')", "macro_native_rule(name = 'm_native',", @@ -121,7 +121,7 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { // about the macro. assertContainsEvent( "ERROR /workspace/test/BUILD:2:1: in deps attribute of cc_library rule //test:m_native: " - + "java_library rule '//test:jlib' is misplaced here (expected "); + + "java_library rule '//test:jlib' is misplaced here (expected "); // Skip the part of the error message that has details about the allowed deps since the mocks // for the mac tests might have different values for them. assertContainsEvent(". Since this " @@ -141,9 +141,9 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { // about the macro. assertContainsEvent( "ERROR /workspace/test/BUILD:4:1: in deps attribute of skylark_rule rule " - + "//test:m_skylark: '//test:jlib' does not have mandatory provider 'some_provider'. " - + "Since this rule was created by the macro 'macro_skylark_rule', the error might have " - + "been caused by the macro implementation in /workspace/test/macros.bzl:12:36"); + + "//test:m_skylark: '//test:jlib' does not have mandatory provider 'some_provider'. " + + "Since this rule was created by the macro 'macro_skylark_rule', the error might " + + "have been caused by the macro implementation in /workspace/test/macros.bzl:12:36"); } } @@ -216,8 +216,8 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { getConfiguredTarget("//test:skyrule"); assertContainsEvent( "ERROR /workspace/test/BUILD:3:10: Label '//test:sub/my_sub_lib.h' crosses boundary of " - + "subpackage 'test/sub' (perhaps you meant to put the colon here: " - + "'//test/sub:my_sub_lib.h'?)"); + + "subpackage 'test/sub' (perhaps you meant to put the colon here: " + + "'//test/sub:my_sub_lib.h'?)"); } @Test @@ -650,10 +650,11 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { @Test public void testParamFileSuffix() throws Exception { SkylarkRuleContext ruleContext = createRuleContext("//foo:foo"); - Object result = evalRuleContextCode( - ruleContext, - "ruleContext.new_file(ruleContext.files.tools[0], " - + "ruleContext.files.tools[0].basename + '.params')"); + Object result = + evalRuleContextCode( + ruleContext, + "ruleContext.new_file(ruleContext.files.tools[0], " + + "ruleContext.files.tools[0].basename + '.params')"); PathFragment fragment = ((Artifact) result).getRootRelativePath(); assertEquals("foo/t.exe.params", fragment.getPathString()); } @@ -755,4 +756,46 @@ public class SkylarkRuleContextTest extends SkylarkTestCase { invalidatePackages(); assertThat(getConfiguredTarget("@r1//:test")).isNotNull(); } + + @Test + @SuppressWarnings("unchecked") + public void testLoadBlockRepositoryRedefinition() throws Exception { + reporter.removeHandler(failFastHandler); + scratch.file("/bar/WORKSPACE"); + scratch.file("/bar/bar.txt"); + scratch.file("/bar/BUILD", "filegroup(name = 'baz', srcs = ['bar.txt'])"); + scratch.file("/baz/WORKSPACE"); + scratch.file("/baz/baz.txt"); + scratch.file("/baz/BUILD", "filegroup(name = 'baz', srcs = ['baz.txt'])"); + scratch.overwriteFile( + "WORKSPACE", + "local_repository(name = 'foo', path = '/bar')", + "local_repository(name = 'foo', path = '/baz')"); + invalidatePackages(); + assertThat( + (List<Label>) + getConfiguredTarget("@foo//:baz") + .getTarget() + .getAssociatedRule() + .getAttributeContainer() + .getAttr("srcs")) + .contains(Label.parseAbsolute("@foo//:baz.txt")); + + scratch.overwriteFile("BUILD"); + scratch.overwriteFile("bar.bzl", "dummy = 1"); + scratch.overwriteFile( + "WORKSPACE", + "local_repository(name = 'foo', path = '/bar')", + "load('//:bar.bzl', 'dummy')", + "local_repository(name = 'foo', path = '/baz')"); + try { + invalidatePackages(); + createRuleContext("@foo//:baz"); + fail("Should have failed because repository 'foo' is overloading after a load!"); + } catch (Exception ex) { + assertContainsEvent( + "ERROR /workspace/WORKSPACE:3:1: Cannot redefine repository after any load statement " + + "in the WORKSPACE file (for repository 'foo')"); + } + } } |