diff options
author | dannark <dannark@google.com> | 2018-06-27 13:35:04 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-27 13:36:25 -0700 |
commit | 90e2b4b5e745fe2de9ca82bc8163c198e5be8ca9 (patch) | |
tree | f827defac036acf55c4253c01f11126e0c502572 /src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java | |
parent | 116971c08caa3f9bd94fc91066cd4cd1e432cafe (diff) |
Automated refactor of Label.parseAbsolute() to always pass a repository mapping
RELNOTES: None
PiperOrigin-RevId: 202360925
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java | 106 |
1 files changed, 63 insertions, 43 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java index 94029ac5c7..502e90c924 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java @@ -18,6 +18,7 @@ import static com.google.devtools.build.lib.pkgcache.FilteringPolicies.FILTER_TE import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -484,16 +485,20 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe @Test public void testParsesIterableOfLabels() throws Exception { - Set<Label> labels = Sets.newHashSet(Label.parseAbsolute("//foo/bar:bar1"), - Label.parseAbsolute("//foo:foo1")); + Set<Label> labels = + Sets.newHashSet( + Label.parseAbsolute("//foo/bar:bar1", ImmutableMap.of()), + Label.parseAbsolute("//foo:foo1", ImmutableMap.of())); assertThat(parseList("//foo/bar:bar1", "//foo:foo1")).isEqualTo(labels); parsingListener.assertEmpty(); } @Test public void testParseAbsoluteWithRelativeParser() throws Exception { - Set<Label> labels = Sets.newHashSet(Label.parseAbsolute("//foo/bar:bar1"), - Label.parseAbsolute("//foo:foo1")); + Set<Label> labels = + Sets.newHashSet( + Label.parseAbsolute("//foo/bar:bar1", ImmutableMap.of()), + Label.parseAbsolute("//foo:foo1", ImmutableMap.of())); assertThat(parseListRelative("//foo/bar:bar1", "//foo:foo1")).isEqualTo(labels); parsingListener.assertEmpty(); } @@ -519,7 +524,8 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe scratch.file("x/y/BUILD", "cc_library(name='y')"); scratch.file("x/z/BUILD", "cc_library(name='z')"); setDeletedPackages(Sets.newHashSet(PackageIdentifier.createInMainRepo("x/y"))); - assertThat(parseList("x/...")).isEqualTo(Sets.newHashSet(Label.parseAbsolute("//x/z"))); + assertThat(parseList("x/...")) + .isEqualTo(Sets.newHashSet(Label.parseAbsolute("//x/z", ImmutableMap.of()))); } @Test @@ -529,14 +535,15 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe setDeletedPackages(Sets.newHashSet(PackageIdentifier.createInMainRepo("x/y"))); assertThat( - targetsToLabels(getFailFast( - parseTargetPatternList( - PathFragment.create("x"), - parser, - parsingListener, - ImmutableList.of("..."), - false)))) - .isEqualTo(Sets.newHashSet(Label.parseAbsolute("//x/z"))); + targetsToLabels( + getFailFast( + parseTargetPatternList( + PathFragment.create("x"), + parser, + parsingListener, + ImmutableList.of("..."), + false)))) + .isEqualTo(Sets.newHashSet(Label.parseAbsolute("//x/z", ImmutableMap.of()))); } @Test @@ -544,15 +551,19 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe scratch.file("x/y/BUILD", "cc_library(name='y')"); scratch.file("x/z/BUILD", "cc_library(name='z')"); - assertThat(parseList("x/...")).containsExactly( - Label.parseAbsolute("//x/y"), Label.parseAbsolute("//x/z")); + assertThat(parseList("x/...")) + .containsExactly( + Label.parseAbsolute("//x/y", ImmutableMap.of()), + Label.parseAbsolute("//x/z", ImmutableMap.of())); setDeletedPackages(Sets.newHashSet(PackageIdentifier.createInMainRepo("x/y"))); - assertThat(parseList("x/...")).containsExactly(Label.parseAbsolute("//x/z")); + assertThat(parseList("x/...")).containsExactly(Label.parseAbsolute("//x/z", ImmutableMap.of())); setDeletedPackages(ImmutableSet.<PackageIdentifier>of()); - assertThat(parseList("x/...")).containsExactly( - Label.parseAbsolute("//x/y"), Label.parseAbsolute("//x/z")); + assertThat(parseList("x/...")) + .containsExactly( + Label.parseAbsolute("//x/y", ImmutableMap.of()), + Label.parseAbsolute("//x/z", ImmutableMap.of())); } @Test @@ -648,7 +659,8 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe // We make sure that the parent package is present, so that in the subsequent nokeep_going // build, the pattern parsing will have as many of its deps available as possible, which // exercises more code coverage during error bubbling. - assertThat(parseList("//parent:all")).containsExactly(Label.parseAbsolute("//parent:parent")); + assertThat(parseList("//parent:all")) + .containsExactly(Label.parseAbsolute("//parent:parent", ImmutableMap.of())); try { parseList("//parent/..."); fail(); @@ -821,7 +833,9 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe assertContainsEvent("name 'BROKEN' is not defined"); assertThat(result.first) .containsExactlyElementsIn( - Sets.newHashSet(Label.parseAbsolute("//x/y:a"), Label.parseAbsolute("//x/y:b"))); + Sets.newHashSet( + Label.parseAbsolute("//x/y:a", ImmutableMap.of()), + Label.parseAbsolute("//x/y:b", ImmutableMap.of()))); assertThat(result.second).isFalse(); } @@ -907,7 +921,7 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe "genrule(name='c', outs=['c.out'])"); Pair<Set<Label>, Boolean> result = parseListKeepGoing("//loading:y"); - assertThat(result.first).containsExactly(Label.parseAbsolute("//loading:y")); + assertThat(result.first).containsExactly(Label.parseAbsolute("//loading:y", ImmutableMap.of())); assertContainsEvent("missing value for mandatory attribute"); assertThat(result.second).isFalse(); } @@ -947,8 +961,10 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe .modify(PathFragment.create("h/i/j/BUILD")).build(); invalidate(modifiedFileSet); - assertThat(parseList("//h/...")).containsExactly(Label.parseAbsolute("//h/i/j:j"), - Label.parseAbsolute("//h")); + assertThat(parseList("//h/...")) + .containsExactly( + Label.parseAbsolute("//h/i/j:j", ImmutableMap.of()), + Label.parseAbsolute("//h", ImmutableMap.of())); } @Test @@ -974,7 +990,8 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe invalidate(modifiedFileSet); reporter.addHandler(failFastHandler); Set<Label> nonEmptyResult = parseList("//h/..."); - assertThat(nonEmptyResult).containsExactly(Label.parseAbsolute("//h/i/j/k:l")); + assertThat(nonEmptyResult) + .containsExactly(Label.parseAbsolute("//h/i/j/k:l", ImmutableMap.of())); } @Test @@ -999,8 +1016,10 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe reporter.addHandler(failFastHandler); Set<Label> result = parseList("//t/..."); - assertThat(result).containsExactly(Label.parseAbsolute("//t:t"), - Label.parseAbsolute("//t/u/v:t")); + assertThat(result) + .containsExactly( + Label.parseAbsolute("//t:t", ImmutableMap.of()), + Label.parseAbsolute("//t/u/v:t", ImmutableMap.of())); } @Test @@ -1011,8 +1030,8 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe scratch.file("a/b/BUILD", "filegroup(name='g')"); ResolvedTargets<Target> result = parseTargetPatternList(parser, parsingListener, ImmutableList.of("//a/b/..."), true); - assertThat(targetsToLabels(result.getTargets())).containsExactly( - Label.parseAbsolute("//a/b:g")); + assertThat(targetsToLabels(result.getTargets())) + .containsExactly(Label.parseAbsolute("//a/b:g", ImmutableMap.of())); } @Test @@ -1023,8 +1042,8 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe scratch.file("a/b/BUILD", "filegroup(name='g')"); ResolvedTargets<Target> result = parseTargetPatternList(parser, parsingListener, ImmutableList.of("//a/b/..."), true); - assertThat(targetsToLabels(result.getTargets())).contains( - Label.parseAbsolute("//a/b:g")); + assertThat(targetsToLabels(result.getTargets())) + .contains(Label.parseAbsolute("//a/b:g", ImmutableMap.of())); } @Test @@ -1043,9 +1062,10 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe ac.getChild("symlink").createSymbolicLink(PathFragment.create("../../from-c")); ResolvedTargets<Target> result = parseTargetPatternList(parser, parsingListener, ImmutableList.of("//a/..."), true); - assertThat(targetsToLabels(result.getTargets())).containsExactly( - Label.parseAbsolute("//a/c/symlink:from-c"), - Label.parseAbsolute("//a/b/not-a-symlink:not-a-symlink")); + assertThat(targetsToLabels(result.getTargets())) + .containsExactly( + Label.parseAbsolute("//a/c/symlink:from-c", ImmutableMap.of()), + Label.parseAbsolute("//a/b/not-a-symlink:not-a-symlink", ImmutableMap.of())); } @Test @@ -1057,8 +1077,8 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe d.getChild("c").createSymbolicLink(targetFragment); rootDirectory.getChild("convenience").createSymbolicLink(targetFragment); Set<Label> result = parseList("//..."); - assertThat(result).doesNotContain(Label.parseAbsolute("//convenience:c")); - assertThat(result).doesNotContain(Label.parseAbsolute("//d/c:c")); + assertThat(result).doesNotContain(Label.parseAbsolute("//convenience:c", ImmutableMap.of())); + assertThat(result).doesNotContain(Label.parseAbsolute("//d/c:c", ImmutableMap.of())); } @Test @@ -1069,13 +1089,13 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe @Test public void testTopLevelPackage_Relative_BuildFile() throws Exception { Set<Label> result = parseList("BUILD"); - assertThat(result).containsExactly(Label.parseAbsolute("//:BUILD")); + assertThat(result).containsExactly(Label.parseAbsolute("//:BUILD", ImmutableMap.of())); } @Test public void testTopLevelPackage_Relative_DeclaredTarget() throws Exception { Set<Label> result = parseList("fg"); - assertThat(result).containsExactly(Label.parseAbsolute("//:fg")); + assertThat(result).containsExactly(Label.parseAbsolute("//:fg", ImmutableMap.of())); } @Test @@ -1086,13 +1106,13 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe @Test public void testTopLevelPackage_Relative_ColonAll() throws Exception { Set<Label> result = parseList(":all"); - assertThat(result).containsExactly(Label.parseAbsolute("//:fg")); + assertThat(result).containsExactly(Label.parseAbsolute("//:fg", ImmutableMap.of())); } @Test public void testTopLevelPackage_Relative_InputFile() throws Exception { Set<Label> result = parseList("foo.cc"); - assertThat(result).containsExactly(Label.parseAbsolute("//:foo.cc")); + assertThat(result).containsExactly(Label.parseAbsolute("//:foo.cc", ImmutableMap.of())); } @Test @@ -1103,25 +1123,25 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe @Test public void testTopLevelPackage_Absolute_BuildFile() throws Exception { Set<Label> result = parseList("//:BUILD"); - assertThat(result).containsExactly(Label.parseAbsolute("//:BUILD")); + assertThat(result).containsExactly(Label.parseAbsolute("//:BUILD", ImmutableMap.of())); } @Test public void testTopLevelPackage_Absolute_DeclaredTarget() throws Exception { Set<Label> result = parseList("//:fg"); - assertThat(result).containsExactly(Label.parseAbsolute("//:fg")); + assertThat(result).containsExactly(Label.parseAbsolute("//:fg", ImmutableMap.of())); } @Test public void testTopLevelPackage_Absolute_All() throws Exception { Set<Label> result = parseList("//:all"); - assertThat(result).containsExactly(Label.parseAbsolute("//:fg")); + assertThat(result).containsExactly(Label.parseAbsolute("//:fg", ImmutableMap.of())); } @Test public void testTopLevelPackage_Absolute_InputFile() throws Exception { Set<Label> result = parseList("//:foo.cc"); - assertThat(result).containsExactly(Label.parseAbsolute("//:foo.cc")); + assertThat(result).containsExactly(Label.parseAbsolute("//:foo.cc", ImmutableMap.of())); } @Test |