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 | |
jcater | 83130f4 | 2019-04-30 14:29:28 -0700 | [diff] [blame] | 16 | import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows; |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 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.vfs.PathFragment; |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 22 | import com.google.devtools.build.lib.vfs.Root; |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 23 | import com.google.devtools.build.lib.vfs.RootedPath; |
| 24 | import com.google.devtools.build.skyframe.SkyKey; |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 25 | import org.junit.Test; |
| 26 | import org.junit.runner.RunWith; |
| 27 | import org.junit.runners.JUnit4; |
| 28 | |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 29 | /** Tests for {@link RecursivePkgKey}. */ |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 30 | @RunWith(JUnit4.class) |
Florian Weikert | cca703a | 2015-12-07 09:56:38 +0000 | [diff] [blame] | 31 | public class RecursivePkgKeyTest extends BuildViewTestCase { |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 32 | |
| 33 | private SkyKey buildRecursivePkgKey( |
| 34 | RepositoryName repository, |
| 35 | PathFragment rootRelativePath, |
| 36 | ImmutableSet<PathFragment> excludedPaths) { |
tomlu | ee6a686 | 2018-01-17 14:36:26 -0800 | [diff] [blame] | 37 | RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(rootDirectory), rootRelativePath); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 38 | return RecursivePkgValue.key(repository, rootedPath, excludedPaths); |
| 39 | } |
| 40 | |
| 41 | private void invalidHelper( |
| 42 | PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) { |
jcater | 83130f4 | 2019-04-30 14:29:28 -0700 | [diff] [blame] | 43 | assertThrows( |
| 44 | IllegalArgumentException.class, |
| 45 | () -> buildRecursivePkgKey(RepositoryName.MAIN, rootRelativePath, excludedPaths)); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 48 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 49 | public void testValidRecursivePkgKeys() throws Exception { |
| 50 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 51 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 52 | PathFragment.create(""), |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 53 | ImmutableSet.<PathFragment>of()); |
| 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(""), |
| 57 | ImmutableSet.of(PathFragment.create("a"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 58 | |
| 59 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 60 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 61 | PathFragment.create("a"), |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 62 | ImmutableSet.<PathFragment>of()); |
| 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"), |
| 66 | ImmutableSet.of(PathFragment.create("a/b"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 67 | |
| 68 | buildRecursivePkgKey( |
Kristina Chodorow | a1a31ff | 2016-07-27 16:34:27 +0000 | [diff] [blame] | 69 | RepositoryName.MAIN, |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 70 | PathFragment.create("a/b"), |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 71 | ImmutableSet.<PathFragment>of()); |
| 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"), |
| 75 | ImmutableSet.of(PathFragment.create("a/b/c"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Florian Weikert | 92b2236 | 2015-12-03 10:17:18 +0000 | [diff] [blame] | 78 | @Test |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 79 | public void testInvalidRecursivePkgKeys() throws Exception { |
nharmata | b4060b6 | 2017-04-04 17:11:39 +0000 | [diff] [blame] | 80 | invalidHelper(PathFragment.create(""), ImmutableSet.of(PathFragment.create(""))); |
| 81 | invalidHelper(PathFragment.create("a"), ImmutableSet.of(PathFragment.create("a"))); |
| 82 | invalidHelper(PathFragment.create("a"), ImmutableSet.of(PathFragment.create("b"))); |
| 83 | invalidHelper(PathFragment.create("a/b"), ImmutableSet.of(PathFragment.create("a"))); |
Han-Wen Nienhuys | 81b9083 | 2015-10-26 16:57:27 +0000 | [diff] [blame] | 84 | } |
| 85 | } |