diff options
author | laurentlb <laurentlb@google.com> | 2017-05-04 20:19:16 +0200 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2017-05-04 23:06:03 +0200 |
commit | ba51cda99733a9facb9479683755944229f63ee3 (patch) | |
tree | d023c85f1d8f1a5e8b8da191a1b5962634766988 /src/test/java/com/google/devtools/build/lib | |
parent | 54c3cbefcc0b6f5a6fb50b48fe2da915122238d6 (diff) |
Introduce package_name() function to replace the magic PACKAGE_NAME constant.
Also, repository_name() replaces REPOSITORY_NAME.
In .bzl files, they are prefixed with "native.".
RELNOTES: None.
PiperOrigin-RevId: 155102221
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java b/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java index 2cff49ba29..99c811d729 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/packages/PackageFactoryTest.java @@ -252,6 +252,18 @@ public class PackageFactoryTest extends PackageFactoryTestBase { } @Test + public void testPackageNameFunction() throws Exception { + Path buildFile = scratch.file("/pina/BUILD", "cc_library(name=package_name() + '-colada')"); + + Package pkg = packages.createPackage("pina", buildFile); + events.assertNoWarningsOrErrors(); + assertFalse(pkg.containsErrors()); + assertNotNull(pkg.getRule("pina-colada")); + assertFalse(pkg.getRule("pina-colada").containsErrors()); + assertSame(1, Sets.newHashSet(pkg.getTargets(Rule.class)).size()); + } + + @Test public void testPackageConstantInExternalRepository() throws Exception { Path buildFile = scratch.file( @@ -265,6 +277,19 @@ public class PackageFactoryTest extends PackageFactoryTestBase { } @Test + public void testPackageFunctionInExternalRepository() throws Exception { + Path buildFile = + scratch.file( + "/external/a/b/BUILD", + "genrule(name='c', srcs=[], outs=['o'], cmd=repository_name() + ' ' + package_name())"); + Package pkg = + packages.createPackage( + PackageIdentifier.create("@a", PathFragment.create("b")), buildFile, events.reporter()); + Rule c = pkg.getRule("c"); + assertThat(AggregatingAttributeMapper.of(c).get("cmd", Type.STRING)).isEqualTo("@a b"); + } + + @Test public void testMultipleDuplicateRuleName() throws Exception { events.setFailFast(false); |