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 | cca703a | 2015-12-07 09:56:38 +0000 | [diff] [blame] | 19 | import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; |
Kristina Chodorow | ec5c07a | 2016-01-25 17:12:29 +0000 | [diff] [blame] | 20 | import com.google.devtools.build.lib.cmdline.RepositoryName; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 21 | import com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey; |
| 22 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 23 | import com.google.devtools.build.lib.vfs.RootedPath; |
| 24 | import com.google.devtools.build.skyframe.SkyKey; |
| 25 | |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 26 | import org.junit.Test; |
| 27 | import org.junit.runner.RunWith; |
| 28 | import org.junit.runners.JUnit4; |
| 29 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 30 | /** Tests for {@link RecursivePkgKey}. */ |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 31 | @RunWith(JUnit4.class) |
Florian Weikert | cca703a | 2015-12-07 09:56:38 +0000 | [diff] [blame] | 32 | public class RecursivePkgKeyTest extends BuildViewTestCase { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 33 | |
| 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 Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 46 | RepositoryName.MAIN, rootRelativePath, excludedPaths); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 47 | fail(); |
| 48 | } catch (IllegalArgumentException expected) { |
| 49 | } |
| 50 | } |
| 51 | |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 52 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 53 | public void testValidRecursivePkgKeys() throws Exception { |
| 54 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 55 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 56 | PathFragment.create(""), |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 57 | ImmutableSet.<PathFragment>of()); |
| 58 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 59 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 60 | PathFragment.create(""), |
| 61 | ImmutableSet.of(PathFragment.create("a"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 62 | |
| 63 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 64 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 65 | PathFragment.create("a"), |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 66 | ImmutableSet.<PathFragment>of()); |
| 67 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 68 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 69 | PathFragment.create("a"), |
| 70 | ImmutableSet.of(PathFragment.create("a/b"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 71 | |
| 72 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 73 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 74 | PathFragment.create("a/b"), |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 75 | ImmutableSet.<PathFragment>of()); |
| 76 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 77 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 78 | PathFragment.create("a/b"), |
| 79 | ImmutableSet.of(PathFragment.create("a/b/c"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 82 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 83 | public void testInvalidRecursivePkgKeys() throws Exception { |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 84 | 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 Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 88 | } |
| 89 | } |