Migrate more tests from TPETest to LPRTest
PiperOrigin-RevId: 214224564
diff --git a/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java b/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java
index 1506dfd..f48257e 100644
--- a/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java
+++ b/src/test/java/com/google/devtools/build/lib/cmdline/TargetPatternTest.java
@@ -25,6 +25,13 @@
/** Tests for {@link com.google.devtools.build.lib.cmdline.TargetPattern}. */
@RunWith(JUnit4.class)
public class TargetPatternTest {
+ private void expectError(String pattern) {
+ try {
+ parse(pattern);
+ fail();
+ } catch (TargetParsingException expected) {
+ }
+ }
@Test
public void testPassingValidations() throws TargetParsingException {
@@ -49,11 +56,9 @@
@Test
public void testInvalidPatterns() throws TargetParsingException {
- try {
- parse("Bar\\java");
- fail();
- } catch (TargetParsingException expected) {
- }
+ expectError("Bar\\java");
+ expectError("");
+ expectError("\\");
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java
index 5f7ba67..4d2624c 100644
--- a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java
@@ -36,6 +36,7 @@
import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.util.AnalysisMock;
import com.google.devtools.build.lib.cmdline.Label;
+import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventKind;
@@ -116,6 +117,8 @@
// Expected.
tester.assertContainsError("circular symlinks detected");
}
+ TargetPatternPhaseValue result = tester.loadKeepGoing(targetPattern);
+ assertThat(result.hasError()).isTrue();
}
private TargetPatternPhaseValue assertNoErrors(TargetPatternPhaseValue loadingResult) {
@@ -186,6 +189,60 @@
}
@Test
+ public void testRecursiveAllRules() throws Exception {
+ tester.addFile("base/BUILD",
+ "filegroup(name = 'base', srcs = ['base.txt'])");
+ tester.addFile("base/foo/BUILD",
+ "filegroup(name = 'foo', srcs = ['foo.txt'])");
+ tester.addFile("base/bar/BUILD",
+ "filegroup(name = 'bar', srcs = ['bar.txt'])");
+ TargetPatternPhaseValue loadingResult = tester.load("//base/...");
+ assertThat(loadingResult.getTargetLabels())
+ .containsExactlyElementsIn(getLabels("//base", "//base/foo", "//base/bar"));
+
+ loadingResult = tester.load("//base/bar/...");
+ assertThat(loadingResult.getTargetLabels())
+ .containsExactlyElementsIn(getLabels("//base/bar"));
+ }
+
+ @Test
+ public void testRecursiveAllTargets() throws Exception {
+ tester.addFile("base/BUILD",
+ "filegroup(name = 'base', srcs = ['base.txt'])");
+ tester.addFile("base/foo/BUILD",
+ "filegroup(name = 'foo', srcs = ['foo.txt'])");
+ tester.addFile("base/bar/BUILD",
+ "filegroup(name = 'bar', srcs = ['bar.txt'])");
+ TargetPatternPhaseValue loadingResult = tester.load("//base/...:*");
+ assertThat(loadingResult.getTargetLabels())
+ .containsExactlyElementsIn(
+ getLabels(
+ "//base:BUILD",
+ "//base:base",
+ "//base:base.txt",
+ "//base/foo:BUILD",
+ "//base/foo:foo",
+ "//base/foo:foo.txt",
+ "//base/bar:BUILD",
+ "//base/bar:bar",
+ "//base/bar:bar.txt"));
+
+ loadingResult = tester.load("//base/...:all-targets");
+ assertThat(loadingResult.getTargetLabels())
+ .containsExactlyElementsIn(
+ getLabels(
+ "//base:BUILD",
+ "//base:base",
+ "//base:base.txt",
+ "//base/foo:BUILD",
+ "//base/foo:foo",
+ "//base/foo:foo.txt",
+ "//base/bar:BUILD",
+ "//base/bar:bar",
+ "//base/bar:bar.txt"));
+ }
+
+ @Test
public void testNonExistentRecursive() throws Exception {
TargetPatternPhaseValue loadingResult = tester.loadKeepGoing("//base/...");
assertThat(loadingResult.hasError()).isTrue();
@@ -292,6 +349,42 @@
assertThat(tester.getTestFilteredTargets()).isEmpty();
}
+ @Test
+ public void testFindLongestPrefix() throws Exception {
+ tester.addFile("base/BUILD", "exports_files(['bar', 'bar/bar', 'bar/baz'])");
+ TargetPatternPhaseValue result = assertNoErrors(tester.load("base/bar/baz"));
+ assertThat(result.getTargetLabels()).containsExactlyElementsIn(getLabels("//base:bar/baz"));
+ result = assertNoErrors(tester.load("base/bar"));
+ assertThat(result.getTargetLabels()).containsExactlyElementsIn(getLabels("//base:bar"));
+ }
+
+ @Test
+ public void testMultiSegmentLabel() throws Exception {
+ tester.addFile("base/foo/BUILD", "exports_files(['bar/baz'])");
+ TargetPatternPhaseValue value = assertNoErrors(tester.load("base/foo:bar/baz"));
+ assertThat(value.getTargetLabels()).containsExactlyElementsIn(getLabels("//base/foo:bar/baz"));
+ }
+
+ @Test
+ public void testMultiSegmentLabelRelative() throws Exception {
+ tester.addFile("base/foo/BUILD", "exports_files(['bar/baz'])");
+ tester.setRelativeWorkingDirectory("base");
+ TargetPatternPhaseValue value = assertNoErrors(tester.load("foo:bar/baz"));
+ assertThat(value.getTargetLabels()).containsExactlyElementsIn(getLabels("//base/foo:bar/baz"));
+ }
+
+ @Test
+ public void testDeletedPackage() throws Exception {
+ tester.addFile("base/BUILD", "exports_files(['base'])");
+ tester.setDeletedPackages(PackageIdentifier.createInMainRepo("base"));
+ TargetPatternPhaseValue result = tester.loadKeepGoing("//base");
+ assertThat(result.hasError()).isTrue();
+ tester.assertContainsError(
+ "no such package 'base': Package is considered deleted due to --deleted_packages");
+ ParsingFailedEvent err = tester.findPostOnce(ParsingFailedEvent.class);
+ assertThat(err.getPattern()).isEqualTo("//base");
+ }
+
private void writeBuildFilesForTestFiltering() throws Exception {
tester.addFile("tests/BUILD",
"sh_test(name = 't1', srcs = ['pass.sh'], size= 'small', local=1)",
@@ -738,6 +831,21 @@
}
@Test
+ public void testWildcard() throws Exception {
+ tester.addFile("foo/lib/BUILD",
+ "sh_library(name = 'lib2', srcs = ['foo.cc'])");
+ TargetPatternPhaseValue value = assertNoErrors(tester.load("//foo/lib:all-targets"));
+ assertThat(value.getTargetLabels())
+ .containsExactlyElementsIn(
+ getLabels("//foo/lib:BUILD", "//foo/lib:lib2", "//foo/lib:foo.cc"));
+
+ value = assertNoErrors(tester.load("//foo/lib:*"));
+ assertThat(value.getTargetLabels())
+ .containsExactlyElementsIn(
+ getLabels("//foo/lib:BUILD", "//foo/lib:lib2", "//foo/lib:foo.cc"));
+ }
+
+ @Test
public void testWildcardConflict() throws Exception {
tester.addFile("foo/lib/BUILD",
"cc_library(name = 'lib1')",
@@ -790,52 +898,52 @@
assertThat(value.getTargetLabels()).containsExactlyElementsIn(getLabels("//base:hello"));
}
- @Test
- public void testPatternWithSingleSlashIsError() throws Exception {
+ private void expectError(String pattern, String message) throws Exception {
try {
- tester.load("/single/slash");
+ tester.load(pattern);
fail();
} catch (TargetParsingException e) {
- assertThat(e).hasMessageThat().contains(
- "not a valid absolute pattern (absolute target patterns must start with exactly "
- + "two slashes): '/single/slash'");
+ assertThat(e).hasMessageThat().contains(message);
}
}
@Test
+ public void testPatternWithSingleSlashIsError() throws Exception {
+ expectError(
+ "/single/slash",
+ "not a valid absolute pattern (absolute target patterns must start with exactly "
+ + "two slashes): '/single/slash'");
+ }
+
+ @Test
public void testPatternWithSingleSlashIsErrorAndOffset() throws Exception {
tester.setRelativeWorkingDirectory("base");
- try {
- tester.load("/single/slash");
- fail();
- } catch (TargetParsingException e) {
- assertThat(e).hasMessageThat().contains(
- "not a valid absolute pattern (absolute target patterns must start with exactly "
- + "two slashes): '/single/slash'");
- }
+ expectError(
+ "/single/slash",
+ "not a valid absolute pattern (absolute target patterns must start with exactly "
+ + "two slashes): '/single/slash'");
}
@Test
public void testPatternWithTripleSlashIsError() throws Exception {
- try {
- tester.load("///triple/slash");
- fail();
- } catch (TargetParsingException e) {
- assertThat(e).hasMessageThat().contains(
- "not a valid absolute pattern (absolute target patterns must start with exactly "
- + "two slashes): '///triple/slash'");
- }
+ expectError(
+ "///triple/slash",
+ "not a valid absolute pattern (absolute target patterns must start with exactly "
+ + "two slashes): '///triple/slash'");
}
@Test
public void testPatternEndingWithSingleSlashIsError() throws Exception {
- try {
- tester.load("foo/");
- fail();
- } catch (TargetParsingException e) {
- assertThat(e).hasMessageThat().contains(
- "The package part of 'foo/' should not end in a slash");
- }
+ expectError(
+ "foo/",
+ "The package part of 'foo/' should not end in a slash");
+ }
+
+ @Test
+ public void testPatternStartingWithDotDotSlash() throws Exception {
+ expectError(
+ "../foo",
+ "Bad target pattern '../foo': package name component contains only '.' characters");
}
private static class LoadingPhaseTester {
@@ -942,6 +1050,10 @@
this.relativeWorkingDirectory = PathFragment.create(relativeWorkingDirectory);
}
+ public void setDeletedPackages(PackageIdentifier... packages) {
+ skyframeExecutor.setDeletedPackages(ImmutableList.copyOf(packages));
+ }
+
public TargetPatternPhaseValue load(String... patterns) throws Exception {
return loadWithFlags(/*keepGoing=*/false, /*determineTests=*/false, patterns);
}
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 192f077..2414a77 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
@@ -26,7 +26,6 @@
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
import com.google.devtools.build.lib.cmdline.TargetParsingException;
-import com.google.devtools.build.lib.cmdline.TargetPattern;
import com.google.devtools.build.lib.packages.ImplicitOutputsFunction;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.util.Pair;
@@ -47,17 +46,11 @@
private PathFragment fooOffset;
private Set<Label> rulesBeneathFoo;
- private Set<Label> rulesBeneathFooBar;
- private Set<Label> rulesBeneathOtherrules;
- private Set<Label> rulesInTopLevelPackage;
private Set<Label> rulesInFoo;
- private Set<Label> rulesInFooBar;
- private Set<Label> rulesInOtherrules;
private Set<Label> targetsInFoo;
private Set<Label> targetsInFooBar;
private Set<Label> targetsBeneathFoo;
private Set<Label> targetsInOtherrules;
- private Set<Label> targetsInTopLevelPackage;
@Before
public final void createFiles() throws Exception {
@@ -89,14 +82,7 @@
fooOffset = foo.relativeTo(rootDirectory);
rulesBeneathFoo = labels("//foo:foo1", "//foo/bar:bar1", "//foo/bar:bar2");
- rulesBeneathFooBar = labels("//foo/bar:bar1", "//foo/bar:bar2");
- rulesBeneathOtherrules = labels(
- "//otherrules:suite1", "//otherrules:wiz", "//otherrules:group");
- rulesInTopLevelPackage = labels("//:fg");
rulesInFoo = labels("//foo:foo1");
- rulesInFooBar = labels("//foo/bar:bar1", "//foo/bar:bar2");
- rulesInOtherrules = rulesBeneathOtherrules;
- targetsInTopLevelPackage = labels("//:BUILD", "//:foo.cc", "//:fg");
targetsInFoo = labels(
"//foo:foo1",
@@ -217,14 +203,6 @@
.getLabel();
}
- private Label parseIndividualTargetRelative(String targetLabel) throws Exception {
- return Iterables.getOnlyElement(
- getFailFast(
- parseTargetPatternList(
- fooOffset, parser, parsingListener, ImmutableList.of(targetLabel), false)))
- .getLabel();
- }
-
@Test
public void testModifiedBuildFile() throws Exception {
assertThat(parseList("foo:all")).containsExactlyElementsIn(rulesInFoo);
@@ -237,107 +215,6 @@
assertThat(parseList("foo:all")).containsExactlyElementsIn(labels("//foo:foo1", "//foo:foo2"));
}
- private void runFindTargetsInPackage(String suffix) throws Exception {
- // 'my_package:all'
- assertThat(parseList("foo" + suffix)).containsExactlyElementsIn(rulesInFoo);
- assertThat(parseList("foo/bar" + suffix)).containsExactlyElementsIn(rulesInFooBar);
- assertThat(parseList("otherrules" + suffix)).containsExactlyElementsIn(rulesInOtherrules);
- assertNoEvents();
- String msg1 = "while parsing 'nosuchpkg" + suffix + "': no such package 'nosuchpkg': "
- + "BUILD file not found on package path";
- expectError(msg1, "nosuchpkg" + suffix);
-
- String msg2 = "while parsing 'nosuchdirectory" + suffix
- + "': no such package 'nosuchdirectory': "
- + "BUILD file not found on package path";
- expectError(msg2, "nosuchdirectory" + suffix);
- assertThat(parsingListener.events).containsExactly(Pair.of("nosuchpkg" + suffix, msg1),
- Pair.of("nosuchdirectory" + suffix, msg2));
- }
-
- private void runFindTargetsInPackageAbsolute(String suffix) throws Exception {
- // '//my_package:all'
- assertThat(parseList("//foo" + suffix)).containsExactlyElementsIn(rulesInFoo);
- assertThat(parseList("//foo/bar" + suffix)).containsExactlyElementsIn(rulesInFooBar);
- assertThat(parseList("//otherrules" + suffix)).containsExactlyElementsIn(rulesInOtherrules);
- assertNoEvents();
- expectError("while parsing '//nosuchpkg" + suffix + "': no such package 'nosuchpkg': "
- + "BUILD file not found on package path",
- "//nosuchpkg" + suffix);
- expectError("while parsing '//nosuchpkg" + suffix + "': no such package 'nosuchpkg': "
- + "BUILD file not found on package path",
- "//nosuchpkg" + suffix);
- }
-
- @Test
- public void testFindRulesInPackage() throws Exception {
- runFindTargetsInPackage(":all");
- runFindTargetsInPackageAbsolute(":all");
- }
-
- private void runFindRulesRecursively(String suffix) throws Exception {
- assertThat(parseList("foo" + suffix)).containsExactlyElementsIn(rulesBeneathFoo);
- assertThat(parseList("//foo" + suffix)).containsExactlyElementsIn(rulesBeneathFoo);
- assertThat(parseList("//foo/bar" + suffix)).containsExactlyElementsIn(rulesBeneathFooBar);
- assertThat(parseList("//foo" + suffix)).containsExactlyElementsIn(rulesBeneathFoo);
- assertThat(parseList("otherrules" + suffix)).containsExactlyElementsIn(rulesBeneathOtherrules);
- assertThat(parseList("//foo" + suffix)).containsExactlyElementsIn(rulesBeneathFoo);
- assertNoEvents();
- eventCollector.clear();
- }
-
- @Test
- public void testNoTargetsFoundRecursiveDirectory() throws Exception {
- try {
- parseList("nosuchpkg/...");
- fail();
- } catch (TargetParsingException e) {
- assertThat(e).hasMessage("no targets found beneath 'nosuchpkg'");
- }
- }
-
- @Test
- public void testFindRulesRecursively() throws Exception {
- runFindRulesRecursively("/...:all");
- runFindRulesRecursively("/...");
- }
-
- private void runFindAllRules(String pattern) throws Exception {
- assertThat(parseList(pattern))
- .containsExactlyElementsIn(ImmutableSet.builder()
- .addAll(rulesBeneathFoo)
- .addAll(rulesBeneathOtherrules)
- .addAll(rulesInTopLevelPackage)
- .build());
- assertNoEvents();
- eventCollector.clear();
- }
-
- @Test
- public void testFindAllRules() throws Exception {
- runFindAllRules("//...:all");
- runFindAllRules("//...");
- runFindAllRules("...");
- }
-
- private void runFindAllTargets(String pattern) throws Exception {
- assertThat(parseList(pattern))
- .containsExactlyElementsIn(ImmutableSet.builder()
- .addAll(targetsBeneathFoo)
- .addAll(targetsInOtherrules)
- .addAll(targetsInTopLevelPackage)
- .build());
- assertNoEvents();
- eventCollector.clear();
- }
-
- @Test
- public void testFindAllTargets() throws Exception {
- runFindAllTargets("//...:all-targets");
- runFindAllTargets("//...:*");
- runFindAllTargets("...:*");
- }
-
/**
* Test that the relative path label parsing behaves as stated in the target-syntax documentation.
*/
@@ -354,49 +231,6 @@
assertThat(parseIndividualTarget("sub/dir2/dir2").toString()).isEqualTo("//sub:dir2/dir2");
}
- @Test
- public void testFindsLongestPlausiblePackageName() throws Exception {
- assertThat(parseIndividualTarget("foo/bar/baz").toString()).isEqualTo("//foo/bar:baz");
- assertThat(parseIndividualTarget("foo/bar/baz/bang").toString())
- .isEqualTo("//foo/bar:baz/bang");
- assertThat(parseIndividualTarget("foo/baz/bang").toString()).isEqualTo("//foo:baz/bang");
- }
-
- @Test
- public void testParsesIterableOfLabels() throws Exception {
- 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", ImmutableMap.of()),
- Label.parseAbsolute("//foo:foo1", ImmutableMap.of()));
- assertThat(parseListRelative("//foo/bar:bar1", "//foo:foo1")).isEqualTo(labels);
- parsingListener.assertEmpty();
- }
-
- @Test
- public void testMultisegmentLabelsWithNoSlashSlash() throws Exception {
- assertThat(parseIndividualTarget("foo/bar:wiz/bang").toString())
- .isEqualTo("//foo/bar:wiz/bang");
- assertThat(parseIndividualTarget("foo/bar:wiz/all").toString()).isEqualTo("//foo/bar:wiz/all");
- }
-
- @Test
- public void testMultisegmentLabelsWithNoSlashSlashRelative() throws Exception {
- assertThat(parseIndividualTargetRelative("bar:wiz/bang").toString())
- .isEqualTo("//foo/bar:wiz/bang");
- assertThat(parseIndividualTargetRelative("bar:wiz/all").toString())
- .isEqualTo("//foo/bar:wiz/all");
- }
-
/** Regression test for a bug. */
@Test
public void testDotDotDotDoesntMatchDeletedPackages() throws Exception {
@@ -453,13 +287,6 @@
}
@Test
- public void testSequenceOfTargetPatterns_UnionRelative() throws Exception {
- // No prefix negation operator => union. Order is not significant.
- assertThat(parseListRelative("...", "bar/...")).containsExactlyElementsIn(rulesBeneathFoo);
- assertThat(parseListRelative("bar/...", "...")).containsExactlyElementsIn(rulesBeneathFoo);
- }
-
- @Test
public void testSequenceOfTargetPatterns_SetDifference() throws Exception {
// Prefix negation operator => set difference. Order is significant.
assertThat(parseList("foo/...", "-foo/bar/...")).containsExactlyElementsIn(rulesInFoo);
@@ -473,81 +300,6 @@
assertThat(parseListRelative("-bar/...", "...")).containsExactlyElementsIn(rulesBeneathFoo);
}
- @Test
- public void testAllTargetsWildcard() throws Exception {
- assertThat(parseList("foo:all-targets")).containsExactlyElementsIn(targetsInFoo);
- assertThat(parseList("foo/bar:all-targets")).containsExactlyElementsIn(targetsInFooBar);
- assertThat(parseList("otherrules:all-targets")).containsExactlyElementsIn(targetsInOtherrules);
- assertThat(parseList("foo/...:all-targets")).containsExactlyElementsIn(targetsBeneathFoo);
-
- assertThat(parseList("foo:*")).containsExactlyElementsIn(targetsInFoo);
- assertThat(parseList("foo/bar:*")).containsExactlyElementsIn(targetsInFooBar);
- assertThat(parseList("otherrules:*")).containsExactlyElementsIn(targetsInOtherrules);
- assertThat(parseList("foo/...:*")).containsExactlyElementsIn(targetsBeneathFoo);
- }
-
- @Test
- public void testAllTargetsWildcardRelative() throws Exception {
- assertThat(parseListRelative(":all-targets")).containsExactlyElementsIn(targetsInFoo);
- assertThat(parseListRelative("//foo:all-targets")).containsExactlyElementsIn(targetsInFoo);
- assertThat(parseListRelative("bar:all-targets")).containsExactlyElementsIn(targetsInFooBar);
- assertThat(parseListRelative("//foo/bar:all-targets"))
- .containsExactlyElementsIn(targetsInFooBar);
- assertThat(parseListRelative("...:all-targets")).containsExactlyElementsIn(targetsBeneathFoo);
- assertThat(parseListRelative("//foo/...:all-targets"))
- .containsExactlyElementsIn(targetsBeneathFoo);
-
- assertThat(parseListRelative(":*")).containsExactlyElementsIn(targetsInFoo);
- assertThat(parseListRelative("//foo:*")).containsExactlyElementsIn(targetsInFoo);
- assertThat(parseListRelative("bar:*")).containsExactlyElementsIn(targetsInFooBar);
- assertThat(parseListRelative("//foo/bar:*")).containsExactlyElementsIn(targetsInFooBar);
- assertThat(parseListRelative("...:*")).containsExactlyElementsIn(targetsBeneathFoo);
- assertThat(parseListRelative("//foo/...:*")).containsExactlyElementsIn(targetsBeneathFoo);
- }
-
- private void setupSubDirectoryCircularSymlink() throws Exception {
- Path parent = scratch.file("parent/BUILD", "sh_library(name = 'parent')").getParentDirectory();
- Path child = parent.getRelative("child");
- child.createDirectory();
- Path badBuild = child.getRelative("BUILD");
- badBuild.createSymbolicLink(badBuild);
- reporter.removeHandler(failFastHandler);
- }
-
- @Test
- public void testSubdirectoryCircularSymlinkKeepGoing() throws Exception {
- setupSubDirectoryCircularSymlink();
- assertThat(parseListKeepGoing("//parent/...").getFirst())
- .containsExactlyElementsIn(labels("//parent:parent"));
- }
-
- @Test
- public void testSubdirectoryCircularSymlinkNoKeepGoing() throws Exception {
- setupSubDirectoryCircularSymlink();
- try {
- parseList("//parent/...");
- fail();
- } catch (TargetParsingException e) {
- // Expected.
- }
- }
-
- @Test
- public void testSubdirectoryCircularSymlinkNoKeepGoingPrimedParent() throws Exception {
- setupSubDirectoryCircularSymlink();
- // 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", ImmutableMap.of()));
- try {
- parseList("//parent/...");
- fail();
- } catch (TargetParsingException e) {
- // Expected.
- }
- }
-
/** Regression test for bug: "Bogus 'helpful' error message" */
@Test
public void testHelpfulMessageForDirectoryWhichIsASubdirectoryOfAPackage() throws Exception {
@@ -560,80 +312,6 @@
"bar/quux");
}
- /** Regression test for bug: "Uplevel references in blaze target patterns cause crash" */
- @Test
- public void testNoCrashWhenUplevelReferencesUsed() throws Exception {
- scratch.file("/other/workspace/project/BUILD");
- expectError(
- "Invalid package name '../other/workspace/project': ",
- "../other/workspace/project/...:all");
- expectError(
- "Invalid package name '../other/workspace/project': ", "../other/workspace/project/...");
- expectError(
- "Invalid package name 'foo/../../other/workspace/project': ",
- "foo/../../other/workspace/project/...");
- expectError(
- "Invalid package name '../other/workspace/project': ", "../other/workspace/project:all");
- }
-
- @Test
- public void testPassingValidations() {
- expectValidationPass("foo:bar");
- expectValidationPass("foo:all");
- expectValidationPass("foo/...:all");
- expectValidationPass("foo:*");
-
- expectValidationPass("//foo");
- expectValidationPass("foo");
- expectValidationPass("foo/bar");
- expectValidationPass("//foo:bar");
- expectValidationPass("//foo:all");
-
- expectValidationPass("//foo/all");
- expectValidationPass("java/com/google/foo/Bar.java");
- expectValidationPass("//foo/...:all");
- }
-
- @Test
- public void testFailingValidations() {
- expectValidationFail("");
- expectValidationFail("\\");
- }
-
- private void expectValidationFail(String target) {
- try {
- TargetPattern.defaultParser().parse(target);
- fail("TargetParsingException expected from parse(" + target + ")");
- } catch (TargetParsingException expected) {
- /* ignore */
- }
-
- // Ensure that validateTargetPattern's checking is strictly weaker than
- // that of parseTargetPattern.
- try {
- parseTargetPatternList(parser, parsingListener, ImmutableList.of(target), false);
- fail("parseTargetPattern(" + target + ") inconsistent with parseTargetPattern!");
- } catch (TargetParsingException expected) {
- /* ignore */
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- private void expectValidationPass(String target) {
- try {
- TargetPattern.defaultParser().parse(target);
- } catch (TargetParsingException e) {
- fail("Expected " + target + " to pass; got exception: " + e);
- }
- }
-
- @Test
- public void testSetOffset() throws Exception {
- assertThat(parseIndividualTarget("foo:foo1").toString()).isEqualTo("//foo:foo1");
- assertThat(parseIndividualTargetRelative(":foo1").toString()).isEqualTo("//foo:foo1");
- }
-
@Test
public void testTestTargetParsing() throws Exception {
scratch.file("test/BUILD",