|
43 | 43 | import com.google.devtools.build.lib.events.EventKind; |
44 | 44 | import com.google.devtools.build.lib.events.ExtendedEventHandler.Postable; |
45 | 45 | import com.google.devtools.build.lib.events.StoredEventHandler; |
| 46 | +import com.google.devtools.build.lib.packages.BuildFileContainsErrorsException; |
46 | 47 | import com.google.devtools.build.lib.packages.ConstantRuleVisibility; |
47 | 48 | import com.google.devtools.build.lib.packages.PackageFactory; |
48 | 49 | import com.google.devtools.build.lib.packages.SkylarkSemanticsOptions; |
@@ -1003,6 +1004,51 @@ public void testPatternStartingWithDotDotSlash() throws Exception { |
1003 | 1004 | "Bad target pattern '../foo': package name component contains only '.' characters"); |
1004 | 1005 | } |
1005 | 1006 |
|
| 1007 | + private void runTestPackageLoadingError(boolean keepGoing, String... patterns) throws Exception { |
| 1008 | + tester.addFile("bad/BUILD", "nope"); |
| 1009 | + if (keepGoing) { |
| 1010 | + TargetPatternPhaseValue value = tester.loadKeepGoing(patterns); |
| 1011 | + assertThat(value.hasError()).isTrue(); |
| 1012 | + tester.assertContainsWarning("Target pattern parsing failed"); |
| 1013 | + } else { |
| 1014 | + TargetParsingException exn = |
| 1015 | + assertThrows(TargetParsingException.class, () -> tester.load(patterns)); |
| 1016 | + assertThat(exn).hasCauseThat().isInstanceOf(BuildFileContainsErrorsException.class); |
| 1017 | + assertThat(exn).hasCauseThat().hasMessageThat().contains("Package 'bad' contains errors"); |
| 1018 | + } |
| 1019 | + tester.assertContainsError("/workspace/bad/BUILD:1:1: name 'nope' is not defined"); |
| 1020 | + } |
| 1021 | + |
| 1022 | + @Test |
| 1023 | + public void testPackageLoadingError_KeepGoing_ExplicitTarget() throws Exception { |
| 1024 | + runTestPackageLoadingError(/*keepGoing=*/ true, "//bad:BUILD"); |
| 1025 | + } |
| 1026 | + |
| 1027 | + @Test |
| 1028 | + public void testPackageLoadingError_NoKeepGoing_ExplicitTarget() throws Exception { |
| 1029 | + runTestPackageLoadingError(/*keepGoing=*/ false, "//bad:BUILD"); |
| 1030 | + } |
| 1031 | + |
| 1032 | + @Test |
| 1033 | + public void testPackageLoadingError_KeepGoing_TargetsInPackage() throws Exception { |
| 1034 | + runTestPackageLoadingError(/*keepGoing=*/ true, "//bad:all"); |
| 1035 | + } |
| 1036 | + |
| 1037 | + @Test |
| 1038 | + public void testPackageLoadingError_NoKeepGoing_TargetsInPackage() throws Exception { |
| 1039 | + runTestPackageLoadingError(/*keepGoing=*/ false, "//bad:all"); |
| 1040 | + } |
| 1041 | + |
| 1042 | + @Test |
| 1043 | + public void testPackageLoadingError_KeepGoing_TargetsBeneathDirectory() throws Exception { |
| 1044 | + runTestPackageLoadingError(/*keepGoing=*/ true, "//bad/..."); |
| 1045 | + } |
| 1046 | + |
| 1047 | + @Test |
| 1048 | + public void testPackageLoadingError_NoKeepGoing_TargetsBeneathDirectory() throws Exception { |
| 1049 | + runTestPackageLoadingError(/*keepGoing=*/ false, "//bad/..."); |
| 1050 | + } |
| 1051 | + |
1006 | 1052 | private static class LoadingPhaseTester { |
1007 | 1053 | private final ManualClock clock = new ManualClock(); |
1008 | 1054 | private final Path workspace; |
|
0 commit comments