blob: 0ab1f82c5a0a105f25bbb71d9db22d5f3c911ff9 [file] [log] [blame]
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +00001// Copyright 2015 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.skyframe;
15
lberkiaea56b32017-05-30 12:35:33 +020016import static com.google.common.truth.Truth.assertThat;
Florian Weikert92b22362015-12-03 10:17:18 +000017
Klaus Aehlig8eb47482018-09-17 09:14:58 -070018import com.google.common.base.Optional;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000019import com.google.common.collect.ImmutableList;
John Cater45932962017-09-06 21:57:46 +020020import com.google.common.collect.ImmutableMap;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000021import com.google.common.collect.ImmutableSet;
22import com.google.common.testing.EqualsTester;
shahan602cc852018-06-06 20:09:57 -070023import com.google.devtools.build.lib.actions.FileStateValue;
24import com.google.devtools.build.lib.actions.FileValue;
Kristina Chodorow5a2936f2016-04-22 17:02:19 +000025import com.google.devtools.build.lib.analysis.BlazeDirectories;
janakr3b63a4e2017-09-14 09:55:40 +020026import com.google.devtools.build.lib.analysis.ServerDirectories;
John Cater45932962017-09-06 21:57:46 +020027import com.google.devtools.build.lib.analysis.util.AnalysisMock;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000028import com.google.devtools.build.lib.cmdline.PackageIdentifier;
John Cater45932962017-09-06 21:57:46 +020029import com.google.devtools.build.lib.cmdline.RepositoryName;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000030import com.google.devtools.build.lib.events.NullEventHandler;
John Cater45932962017-09-06 21:57:46 +020031import com.google.devtools.build.lib.packages.RuleClassProvider;
janakr15e15c22019-01-30 11:24:49 -080032import com.google.devtools.build.lib.packages.WorkspaceFileValue;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000033import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
John Cater45932962017-09-06 21:57:46 +020034import com.google.devtools.build.lib.rules.repository.LocalRepositoryFunction;
35import com.google.devtools.build.lib.rules.repository.LocalRepositoryRule;
36import com.google.devtools.build.lib.rules.repository.RepositoryDelegatorFunction;
37import com.google.devtools.build.lib.rules.repository.RepositoryFunction;
38import com.google.devtools.build.lib.rules.repository.RepositoryLoaderFunction;
Googler06eb1bb2019-02-26 15:33:15 -080039import com.google.devtools.build.lib.skyframe.ContainingPackageLookupValue.ContainingPackage;
40import com.google.devtools.build.lib.skyframe.ContainingPackageLookupValue.NoContainingPackage;
Nathan Harmatad4f75942016-10-18 08:55:17 +000041import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction;
John Cater5e9ce942016-10-12 17:23:30 +000042import com.google.devtools.build.lib.skyframe.PackageLookupFunction.CrossRepositoryLabelViolationStrategy;
Googler06eb1bb2019-02-26 15:33:15 -080043import com.google.devtools.build.lib.skyframe.PackageLookupValue.ErrorReason;
laurentlb6659b4c2019-02-18 07:23:36 -080044import com.google.devtools.build.lib.syntax.StarlarkSemantics;
Florian Weikertcca703a2015-12-07 09:56:38 +000045import com.google.devtools.build.lib.testutil.FoundationTestCase;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000046import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor;
Eric Fellheimere040fe92015-11-09 23:54:46 +000047import com.google.devtools.build.lib.vfs.PathFragment;
tomluee6a6862018-01-17 14:36:26 -080048import com.google.devtools.build.lib.vfs.Root;
Klaus Aehlig8eb47482018-09-17 09:14:58 -070049import com.google.devtools.build.lib.vfs.RootedPath;
djasperb109a5f2019-02-14 01:05:34 -080050import com.google.devtools.build.lib.vfs.UnixGlob;
Googler10028672018-10-25 12:14:34 -070051import com.google.devtools.build.skyframe.EvaluationContext;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000052import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator;
53import com.google.devtools.build.skyframe.MemoizingEvaluator;
54import com.google.devtools.build.skyframe.RecordingDifferencer;
janakr1cde8722017-10-10 03:22:21 +020055import com.google.devtools.build.skyframe.SequencedRecordingDifferencer;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000056import com.google.devtools.build.skyframe.SequentialBuildDriver;
57import com.google.devtools.build.skyframe.SkyFunction;
58import com.google.devtools.build.skyframe.SkyFunctionName;
59import com.google.devtools.build.skyframe.SkyKey;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000060import java.util.HashMap;
61import java.util.Map;
62import java.util.UUID;
John Cater45932962017-09-06 21:57:46 +020063import java.util.concurrent.atomic.AtomicBoolean;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000064import java.util.concurrent.atomic.AtomicReference;
John Cater5e9ce942016-10-12 17:23:30 +000065import org.junit.Before;
66import org.junit.Test;
67import org.junit.runner.RunWith;
68import org.junit.runners.JUnit4;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000069
70/**
71 * Tests for {@link ContainingPackageLookupFunction}.
72 */
Florian Weikert92b22362015-12-03 10:17:18 +000073@RunWith(JUnit4.class)
Florian Weikertcca703a2015-12-07 09:56:38 +000074public class ContainingPackageLookupFunctionTest extends FoundationTestCase {
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000075
76 private AtomicReference<ImmutableSet<PackageIdentifier>> deletedPackages;
77 private MemoizingEvaluator evaluator;
78 private SequentialBuildDriver driver;
John Cater45932962017-09-06 21:57:46 +020079 private RecordingDifferencer differencer;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000080
Florian Weikert92b22362015-12-03 10:17:18 +000081 @Before
82 public final void setUp() throws Exception {
John Cater45932962017-09-06 21:57:46 +020083 AnalysisMock analysisMock = AnalysisMock.get();
84
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000085 AtomicReference<PathPackageLocator> pkgLocator =
John Catere0d1d0e2017-11-28 20:47:41 -080086 new AtomicReference<>(
87 new PathPackageLocator(
88 outputBase,
tomluee6a6862018-01-17 14:36:26 -080089 ImmutableList.of(Root.fromPath(rootDirectory)),
John Catere0d1d0e2017-11-28 20:47:41 -080090 BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000091 deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of());
John Cater45932962017-09-06 21:57:46 +020092 BlazeDirectories directories =
Nathan Harmatad4f75942016-10-18 08:55:17 +000093 new BlazeDirectories(
Klaus Aehligc2499c42018-02-27 05:47:21 -080094 new ServerDirectories(rootDirectory, outputBase, outputBase),
janakr3b63a4e2017-09-14 09:55:40 +020095 rootDirectory,
cushon849df362018-05-14 01:51:45 -070096 /* defaultSystemJavabase= */ null,
janakr3b63a4e2017-09-14 09:55:40 +020097 analysisMock.getProductName());
John Cater45932962017-09-06 21:57:46 +020098 ExternalFilesHelper externalFilesHelper =
nharmata3fb7d342018-02-23 11:37:51 -080099 ExternalFilesHelper.createForTesting(
John Cater45932962017-09-06 21:57:46 +0200100 pkgLocator,
101 ExternalFileAction.DEPEND_ON_EXTERNAL_PKG_FOR_EXTERNAL_REPO_PATHS,
102 directories);
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000103
104 Map<SkyFunctionName, SkyFunction> skyFunctions = new HashMap<>();
John Cater45932962017-09-06 21:57:46 +0200105 skyFunctions.put(SkyFunctions.CONTAINING_PACKAGE_LOOKUP, new ContainingPackageLookupFunction());
106
John Cater5e9ce942016-10-12 17:23:30 +0000107 skyFunctions.put(
108 SkyFunctions.PACKAGE_LOOKUP,
John Cater0c0735a2016-11-11 01:52:02 +0000109 new PackageLookupFunction(
110 deletedPackages,
111 CrossRepositoryLabelViolationStrategy.ERROR,
ajurkowski2018b872020-04-14 09:59:00 -0700112 BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY,
113 BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
John Cater45932962017-09-06 21:57:46 +0200114 skyFunctions.put(
ajurkowski2018b872020-04-14 09:59:00 -0700115 SkyFunctions.PACKAGE, new PackageFunction(null, null, null, null, null, null, null, null));
nharmataa32ac672020-01-08 12:54:25 -0800116 skyFunctions.put(
117 SkyFunctions.BLACKLISTED_PACKAGE_PREFIXES,
nharmatae4eb23f2017-12-05 09:27:45 -0800118 new BlacklistedPackagePrefixesFunction(
nharmataa32ac672020-01-08 12:54:25 -0800119 /*blacklistedPackagePrefixesFile=*/ PathFragment.EMPTY_FRAGMENT));
shahan602cc852018-06-06 20:09:57 -0700120 skyFunctions.put(
121 FileStateValue.FILE_STATE,
122 new FileStateFunction(
djasper7faa0ef2019-03-28 10:00:00 -0700123 new AtomicReference<TimestampGranularityMonitor>(),
124 new AtomicReference<>(UnixGlob.DEFAULT_SYSCALLS),
125 externalFilesHelper));
shahan602cc852018-06-06 20:09:57 -0700126 skyFunctions.put(FileValue.FILE, new FileFunction(pkgLocator));
John Caterb4f461e2016-10-25 16:16:35 +0000127 skyFunctions.put(SkyFunctions.DIRECTORY_LISTING, new DirectoryListingFunction());
128 skyFunctions.put(
129 SkyFunctions.DIRECTORY_LISTING_STATE,
djasperb109a5f2019-02-14 01:05:34 -0800130 new DirectoryListingStateFunction(
131 externalFilesHelper, new AtomicReference<>(UnixGlob.DEFAULT_SYSCALLS)));
John Cater45932962017-09-06 21:57:46 +0200132 RuleClassProvider ruleClassProvider = analysisMock.createRuleClassProvider();
133 skyFunctions.put(SkyFunctions.WORKSPACE_AST, new WorkspaceASTFunction(ruleClassProvider));
134 skyFunctions.put(
janakr15e15c22019-01-30 11:24:49 -0800135 WorkspaceFileValue.WORKSPACE_FILE,
John Cater45932962017-09-06 21:57:46 +0200136 new WorkspaceFileFunction(
137 ruleClassProvider,
138 analysisMock
janakr52d05e82017-09-22 13:27:14 -0400139 .getPackageFactoryBuilderForTesting(directories)
nharmatafde0bd2f2018-12-21 10:17:56 -0800140 .build(ruleClassProvider, fileSystem),
mjhalupkaf0e48112019-01-14 13:01:56 -0800141 directories,
gregceebd616f2020-04-10 16:47:41 -0700142 /*starlarkImportLookupFunctionForInlining=*/ null));
ajurkowski2018b872020-04-14 09:59:00 -0700143 skyFunctions.put(
144 SkyFunctions.EXTERNAL_PACKAGE,
145 new ExternalPackageFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
146 skyFunctions.put(
147 SkyFunctions.LOCAL_REPOSITORY_LOOKUP,
148 new LocalRepositoryLookupFunction(BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
John Cater45932962017-09-06 21:57:46 +0200149 skyFunctions.put(
150 SkyFunctions.FILE_SYMLINK_CYCLE_UNIQUENESS, new FileSymlinkCycleUniquenessFunction());
151 ImmutableMap<String, RepositoryFunction> repositoryHandlers =
152 ImmutableMap.of(
153 LocalRepositoryRule.NAME, (RepositoryFunction) new LocalRepositoryFunction());
154 skyFunctions.put(
155 SkyFunctions.REPOSITORY_DIRECTORY,
janakrca6b46d2017-09-22 14:07:15 -0400156 new RepositoryDelegatorFunction(
Googler22913422019-05-02 12:42:20 -0700157 repositoryHandlers,
158 null,
159 new AtomicBoolean(true),
160 ImmutableMap::of,
161 directories,
ajurkowski2018b872020-04-14 09:59:00 -0700162 ManagedDirectoriesKnowledge.NO_MANAGED_DIRECTORIES,
163 BazelSkyframeExecutorConstants.EXTERNAL_PACKAGE_HELPER));
John Cater45932962017-09-06 21:57:46 +0200164 skyFunctions.put(SkyFunctions.REPOSITORY, new RepositoryLoaderFunction());
165
janakr1cde8722017-10-10 03:22:21 +0200166 differencer = new SequencedRecordingDifferencer();
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000167 evaluator = new InMemoryMemoizingEvaluator(skyFunctions, differencer);
168 driver = new SequentialBuildDriver(evaluator);
169 PrecomputedValue.BUILD_ID.set(differencer, UUID.randomUUID());
brandjondbff8b82017-10-23 19:02:31 +0200170 PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get());
adonovanb85d0b72020-05-08 11:59:19 -0700171 PrecomputedValue.STARLARK_SEMANTICS.set(differencer, StarlarkSemantics.DEFAULT);
John Cater45932962017-09-06 21:57:46 +0200172 RepositoryDelegatorFunction.REPOSITORY_OVERRIDES.set(
173 differencer, ImmutableMap.<RepositoryName, PathFragment>of());
Klaus Aehlig93fe20c2018-06-14 05:48:46 -0700174 RepositoryDelegatorFunction.DEPENDENCY_FOR_UNCONDITIONAL_FETCHING.set(
175 differencer, RepositoryDelegatorFunction.DONT_FETCH_UNCONDITIONALLY);
Klaus Aehlig8eb47482018-09-17 09:14:58 -0700176 RepositoryDelegatorFunction.RESOLVED_FILE_INSTEAD_OF_WORKSPACE.set(
177 differencer, Optional.<RootedPath>absent());
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000178 }
179
180 private ContainingPackageLookupValue lookupContainingPackage(String packageName)
181 throws InterruptedException {
John Cater45932962017-09-06 21:57:46 +0200182 return lookupContainingPackage(PackageIdentifier.createInMainRepo(packageName));
183 }
184
185 private ContainingPackageLookupValue lookupContainingPackage(PackageIdentifier packageIdentifier)
186 throws InterruptedException {
187 SkyKey key = ContainingPackageLookupValue.key(packageIdentifier);
Googler10028672018-10-25 12:14:34 -0700188 EvaluationContext evaluationContext =
189 EvaluationContext.newBuilder()
190 .setKeepGoing(false)
191 .setNumThreads(SkyframeExecutor.DEFAULT_THREAD_COUNT)
192 .setEventHander(NullEventHandler.INSTANCE)
193 .build();
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000194 return driver
Googler10028672018-10-25 12:14:34 -0700195 .<ContainingPackageLookupValue>evaluate(ImmutableList.of(key), evaluationContext)
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000196 .get(key);
197 }
198
Googler06eb1bb2019-02-26 15:33:15 -0800199 private PackageLookupValue lookupPackage(PackageIdentifier packageIdentifier)
200 throws InterruptedException {
201 SkyKey key = PackageLookupValue.key(packageIdentifier);
202 EvaluationContext evaluationContext =
203 EvaluationContext.newBuilder()
204 .setKeepGoing(false)
205 .setNumThreads(SkyframeExecutor.DEFAULT_THREAD_COUNT)
206 .setEventHander(NullEventHandler.INSTANCE)
207 .build();
208 return driver.<PackageLookupValue>evaluate(ImmutableList.of(key), evaluationContext).get(key);
209 }
210
Florian Weikert92b22362015-12-03 10:17:18 +0000211 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000212 public void testNoContainingPackage() throws Exception {
213 ContainingPackageLookupValue value = lookupContainingPackage("a/b");
lberkiaea56b32017-05-30 12:35:33 +0200214 assertThat(value.hasContainingPackage()).isFalse();
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000215 }
216
Florian Weikert92b22362015-12-03 10:17:18 +0000217 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000218 public void testContainingPackageIsParent() throws Exception {
219 scratch.file("a/BUILD");
220 ContainingPackageLookupValue value = lookupContainingPackage("a/b");
lberkiaea56b32017-05-30 12:35:33 +0200221 assertThat(value.hasContainingPackage()).isTrue();
222 assertThat(value.getContainingPackageName()).isEqualTo(PackageIdentifier.createInMainRepo("a"));
tomluee6a6862018-01-17 14:36:26 -0800223 assertThat(value.getContainingPackageRoot()).isEqualTo(Root.fromPath(rootDirectory));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000224 }
225
Florian Weikert92b22362015-12-03 10:17:18 +0000226 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000227 public void testContainingPackageIsSelf() throws Exception {
228 scratch.file("a/b/BUILD");
229 ContainingPackageLookupValue value = lookupContainingPackage("a/b");
lberkiaea56b32017-05-30 12:35:33 +0200230 assertThat(value.hasContainingPackage()).isTrue();
231 assertThat(value.getContainingPackageName())
232 .isEqualTo(PackageIdentifier.createInMainRepo("a/b"));
tomluee6a6862018-01-17 14:36:26 -0800233 assertThat(value.getContainingPackageRoot()).isEqualTo(Root.fromPath(rootDirectory));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000234 }
235
Florian Weikert92b22362015-12-03 10:17:18 +0000236 @Test
John Cater45932962017-09-06 21:57:46 +0200237 public void testContainingPackageIsExternalRepositoryViaExternalRepository() throws Exception {
238 scratch.overwriteFile(
239 "WORKSPACE",
240 "local_repository(name='a', path='a')");
241 scratch.file("a/WORKSPACE");
242 scratch.file("a/BUILD");
243 scratch.file("a/b/BUILD");
244 ContainingPackageLookupValue value =
245 lookupContainingPackage(
246 PackageIdentifier.create(RepositoryName.create("@a"), PathFragment.create("b")));
247 assertThat(value.hasContainingPackage()).isTrue();
248 assertThat(value.getContainingPackageName())
249 .isEqualTo(PackageIdentifier.create(RepositoryName.create("@a"), PathFragment.create("b")));
250 }
251
252 @Test
253 public void testContainingPackageIsExternalRepositoryViaLocalPath() throws Exception {
254 scratch.overwriteFile(
255 "WORKSPACE",
256 "local_repository(name='a', path='a')");
257 scratch.file("a/WORKSPACE");
258 scratch.file("a/BUILD");
259 scratch.file("a/b/BUILD");
260 ContainingPackageLookupValue value = lookupContainingPackage("a/b");
261 assertThat(value.hasContainingPackage()).isTrue();
262 assertThat(value.getContainingPackageName())
263 .isEqualTo(PackageIdentifier.create(RepositoryName.create("@a"), PathFragment.create("b")));
264 }
265
266 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000267 public void testEqualsAndHashCodeContract() throws Exception {
268 ContainingPackageLookupValue valueA1 = ContainingPackageLookupValue.NONE;
269 ContainingPackageLookupValue valueA2 = ContainingPackageLookupValue.NONE;
270 ContainingPackageLookupValue valueB1 =
271 ContainingPackageLookupValue.withContainingPackage(
tomluee6a6862018-01-17 14:36:26 -0800272 PackageIdentifier.createInMainRepo("b"), Root.fromPath(rootDirectory));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000273 ContainingPackageLookupValue valueB2 =
274 ContainingPackageLookupValue.withContainingPackage(
tomluee6a6862018-01-17 14:36:26 -0800275 PackageIdentifier.createInMainRepo("b"), Root.fromPath(rootDirectory));
Brian Silvermand7d6d622016-03-17 09:53:39 +0000276 PackageIdentifier cFrag = PackageIdentifier.createInMainRepo("c");
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000277 ContainingPackageLookupValue valueC1 =
tomluee6a6862018-01-17 14:36:26 -0800278 ContainingPackageLookupValue.withContainingPackage(cFrag, Root.fromPath(rootDirectory));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000279 ContainingPackageLookupValue valueC2 =
tomluee6a6862018-01-17 14:36:26 -0800280 ContainingPackageLookupValue.withContainingPackage(cFrag, Root.fromPath(rootDirectory));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000281 ContainingPackageLookupValue valueCOther =
282 ContainingPackageLookupValue.withContainingPackage(
tomluee6a6862018-01-17 14:36:26 -0800283 cFrag, Root.fromPath(rootDirectory.getRelative("other_root")));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000284 new EqualsTester()
285 .addEqualityGroup(valueA1, valueA2)
286 .addEqualityGroup(valueB1, valueB2)
287 .addEqualityGroup(valueC1, valueC2)
288 .addEqualityGroup(valueCOther)
289 .testEquals();
290 }
Googler06eb1bb2019-02-26 15:33:15 -0800291
292 @Test
293 public void testNonExistentExternalRepositoryErrorReason() throws Exception {
294 PackageIdentifier identifier =
295 PackageIdentifier.create("@some_repo", PathFragment.create(":atarget"));
296 ContainingPackageLookupValue value = lookupContainingPackage(identifier);
297 assertThat(value.hasContainingPackage()).isFalse();
298 assertThat(value.getClass()).isEqualTo(NoContainingPackage.class);
299 assertThat(value.getReasonForNoContainingPackage())
300 .isEqualTo("The repository '@some_repo' could not be resolved");
301 }
302
303 @Test
304 public void testInvalidPackageLabelErrorReason() throws Exception {
305 ContainingPackageLookupValue value = lookupContainingPackage("invalidpackagename:42/BUILD");
306 assertThat(value.hasContainingPackage()).isFalse();
307 assertThat(value.getClass()).isEqualTo(NoContainingPackage.class);
308 // As for invalid package name we continue to climb up the parent packages,
309 // we will find the top-level package with the path "" - empty string.
310 assertThat(value.getReasonForNoContainingPackage()).isNull();
311 }
312
313 @Test
314 public void testDeletedPackageErrorReason() throws Exception {
315 PackageIdentifier identifier = PackageIdentifier.createInMainRepo("deletedpackage");
316 deletedPackages.set(ImmutableSet.of(identifier));
317 scratch.file("BUILD");
318
319 PackageLookupValue packageLookupValue = lookupPackage(identifier);
320 assertThat(packageLookupValue.packageExists()).isFalse();
321 assertThat(packageLookupValue.getErrorReason()).isEqualTo(ErrorReason.DELETED_PACKAGE);
322 assertThat(packageLookupValue.getErrorMsg())
323 .isEqualTo("Package is considered deleted due to --deleted_packages");
324
325 ContainingPackageLookupValue value = lookupContainingPackage(identifier);
326 assertThat(value.hasContainingPackage()).isTrue();
327 assertThat(value.getContainingPackageName().toString()).isEmpty();
328 assertThat(value.getClass()).isEqualTo(ContainingPackage.class);
329 }
330
331 @Test
332 public void testNoBuildFileErrorReason() throws Exception {
333 ContainingPackageLookupValue value = lookupContainingPackage("abc");
334 assertThat(value.hasContainingPackage()).isFalse();
335 assertThat(value.getClass()).isEqualTo(NoContainingPackage.class);
336 assertThat(value.getReasonForNoContainingPackage()).isNull();
337 }
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000338}