Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 1 | // 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. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame^] | 16 | import static org.junit.Assert.fail; |
| 17 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame^] | 19 | import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 20 | import com.google.devtools.build.lib.cmdline.PackageIdentifier; |
| 21 | import com.google.devtools.build.lib.cmdline.PackageIdentifier.RepositoryName; |
| 22 | import com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey; |
| 23 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 24 | import com.google.devtools.build.lib.vfs.RootedPath; |
| 25 | import com.google.devtools.build.skyframe.SkyKey; |
| 26 | |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame^] | 27 | import org.junit.Test; |
| 28 | import org.junit.runner.RunWith; |
| 29 | import org.junit.runners.JUnit4; |
| 30 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 31 | /** Tests for {@link RecursivePkgKey}. */ |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame^] | 32 | @RunWith(JUnit4.class) |
| 33 | public class RecursivePkgKeyTest extends BuildViewTestCaseForJunit4 { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 34 | |
| 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 Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame^] | 53 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 54 | 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 Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame^] | 83 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 84 | 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 | } |