blob: e205cabf1c649deedf3e925f5a357747bc9297dc [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
Florian Weikert92b22362015-12-03 10:17:18 +000016import static org.junit.Assert.fail;
17
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000018import com.google.common.collect.ImmutableSet;
Florian Weikertcca703a2015-12-07 09:56:38 +000019import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
Kristina Chodorowec5c07a2016-01-25 17:12:29 +000020import com.google.devtools.build.lib.cmdline.RepositoryName;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000021import com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey;
22import com.google.devtools.build.lib.vfs.PathFragment;
23import com.google.devtools.build.lib.vfs.RootedPath;
24import com.google.devtools.build.skyframe.SkyKey;
25
Florian Weikert92b22362015-12-03 10:17:18 +000026import org.junit.Test;
27import org.junit.runner.RunWith;
28import org.junit.runners.JUnit4;
29
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000030/** Tests for {@link RecursivePkgKey}. */
Florian Weikert92b22362015-12-03 10:17:18 +000031@RunWith(JUnit4.class)
Florian Weikertcca703a2015-12-07 09:56:38 +000032public class RecursivePkgKeyTest extends BuildViewTestCase {
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000033
34 private SkyKey buildRecursivePkgKey(
35 RepositoryName repository,
36 PathFragment rootRelativePath,
37 ImmutableSet<PathFragment> excludedPaths) {
38 RootedPath rootedPath = RootedPath.toRootedPath(rootDirectory, rootRelativePath);
39 return RecursivePkgValue.key(repository, rootedPath, excludedPaths);
40 }
41
42 private void invalidHelper(
43 PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) {
44 try {
45 buildRecursivePkgKey(
Kristina Chodorowa1a31ff2016-07-27 16:34:27 +000046 RepositoryName.MAIN, rootRelativePath, excludedPaths);
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000047 fail();
48 } catch (IllegalArgumentException expected) {
49 }
50 }
51
Florian Weikert92b22362015-12-03 10:17:18 +000052 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000053 public void testValidRecursivePkgKeys() throws Exception {
54 buildRecursivePkgKey(
Kristina Chodorowa1a31ff2016-07-27 16:34:27 +000055 RepositoryName.MAIN,
nharmatab4060b62017-04-04 17:11:39 +000056 PathFragment.create(""),
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000057 ImmutableSet.<PathFragment>of());
58 buildRecursivePkgKey(
Kristina Chodorowa1a31ff2016-07-27 16:34:27 +000059 RepositoryName.MAIN,
nharmatab4060b62017-04-04 17:11:39 +000060 PathFragment.create(""),
61 ImmutableSet.of(PathFragment.create("a")));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000062
63 buildRecursivePkgKey(
Kristina Chodorowa1a31ff2016-07-27 16:34:27 +000064 RepositoryName.MAIN,
nharmatab4060b62017-04-04 17:11:39 +000065 PathFragment.create("a"),
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000066 ImmutableSet.<PathFragment>of());
67 buildRecursivePkgKey(
Kristina Chodorowa1a31ff2016-07-27 16:34:27 +000068 RepositoryName.MAIN,
nharmatab4060b62017-04-04 17:11:39 +000069 PathFragment.create("a"),
70 ImmutableSet.of(PathFragment.create("a/b")));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000071
72 buildRecursivePkgKey(
Kristina Chodorowa1a31ff2016-07-27 16:34:27 +000073 RepositoryName.MAIN,
nharmatab4060b62017-04-04 17:11:39 +000074 PathFragment.create("a/b"),
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000075 ImmutableSet.<PathFragment>of());
76 buildRecursivePkgKey(
Kristina Chodorowa1a31ff2016-07-27 16:34:27 +000077 RepositoryName.MAIN,
nharmatab4060b62017-04-04 17:11:39 +000078 PathFragment.create("a/b"),
79 ImmutableSet.of(PathFragment.create("a/b/c")));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000080 }
81
Florian Weikert92b22362015-12-03 10:17:18 +000082 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000083 public void testInvalidRecursivePkgKeys() throws Exception {
nharmatab4060b62017-04-04 17:11:39 +000084 invalidHelper(PathFragment.create(""), ImmutableSet.of(PathFragment.create("")));
85 invalidHelper(PathFragment.create("a"), ImmutableSet.of(PathFragment.create("a")));
86 invalidHelper(PathFragment.create("a"), ImmutableSet.of(PathFragment.create("b")));
87 invalidHelper(PathFragment.create("a/b"), ImmutableSet.of(PathFragment.create("a")));
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000088 }
89}