blob: 2e5df9e9a1548aa94af5c6453dd250a87b0e9ab0 [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 Weikert92b22362015-12-03 10:17:18 +000019import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000020import com.google.devtools.build.lib.cmdline.PackageIdentifier;
21import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName;
22import com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey;
23import com.google.devtools.build.lib.vfs.PathFragment;
24import com.google.devtools.build.lib.vfs.RootedPath;
25import com.google.devtools.build.skyframe.SkyKey;
26
Florian Weikert92b22362015-12-03 10:17:18 +000027import org.junit.Test;
28import org.junit.runner.RunWith;
29import org.junit.runners.JUnit4;
30
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000031/** Tests for {@link RecursivePkgKey}. */
Florian Weikert92b22362015-12-03 10:17:18 +000032@RunWith(JUnit4.class)
33public class RecursivePkgKeyTest extends BuildViewTestCaseForJunit4 {
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000034
35 private SkyKey buildRecursivePkgKey(
36 RepositoryName repository,
37 PathFragment rootRelativePath,
38 ImmutableSet<PathFragment> excludedPaths) {
39 RootedPath rootedPath = RootedPath.toRootedPath(rootDirectory, rootRelativePath);
40 return RecursivePkgValue.key(repository, rootedPath, excludedPaths);
41 }
42
43 private void invalidHelper(
44 PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) {
45 try {
46 buildRecursivePkgKey(
47 PackageIdentifier.DEFAULT_REPOSITORY_NAME, rootRelativePath, excludedPaths);
48 fail();
49 } catch (IllegalArgumentException expected) {
50 }
51 }
52
Florian Weikert92b22362015-12-03 10:17:18 +000053 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000054 public void testValidRecursivePkgKeys() throws Exception {
55 buildRecursivePkgKey(
56 PackageIdentifier.DEFAULT_REPOSITORY_NAME,
57 new PathFragment(""),
58 ImmutableSet.<PathFragment>of());
59 buildRecursivePkgKey(
60 PackageIdentifier.DEFAULT_REPOSITORY_NAME,
61 new PathFragment(""),
62 ImmutableSet.of(new PathFragment("a")));
63
64 buildRecursivePkgKey(
65 PackageIdentifier.DEFAULT_REPOSITORY_NAME,
66 new PathFragment("a"),
67 ImmutableSet.<PathFragment>of());
68 buildRecursivePkgKey(
69 PackageIdentifier.DEFAULT_REPOSITORY_NAME,
70 new PathFragment("a"),
71 ImmutableSet.of(new PathFragment("a/b")));
72
73 buildRecursivePkgKey(
74 PackageIdentifier.DEFAULT_REPOSITORY_NAME,
75 new PathFragment("a/b"),
76 ImmutableSet.<PathFragment>of());
77 buildRecursivePkgKey(
78 PackageIdentifier.DEFAULT_REPOSITORY_NAME,
79 new PathFragment("a/b"),
80 ImmutableSet.of(new PathFragment("a/b/c")));
81 }
82
Florian Weikert92b22362015-12-03 10:17:18 +000083 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000084 public void testInvalidRecursivePkgKeys() throws Exception {
85 invalidHelper(new PathFragment(""), ImmutableSet.of(new PathFragment("")));
86 invalidHelper(new PathFragment("a"), ImmutableSet.of(new PathFragment("a")));
87 invalidHelper(new PathFragment("a"), ImmutableSet.of(new PathFragment("b")));
88 invalidHelper(new PathFragment("a/b"), ImmutableSet.of(new PathFragment("a")));
89 }
90}