Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| 15 | package com.google.devtools.build.lib.analysis; |
| 16 | |
| 17 | import static com.google.common.truth.Truth.assertThat; |
| 18 | import static com.google.devtools.build.lib.analysis.OutputGroupProvider.determineOutputGroups; |
| 19 | import static java.util.Arrays.asList; |
| 20 | |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | |
| 23 | import org.junit.Test; |
| 24 | import org.junit.runner.RunWith; |
| 25 | import org.junit.runners.JUnit4; |
| 26 | |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * Tests for {@link OutputGroupProvider}. |
| 31 | */ |
| 32 | @RunWith(JUnit4.class) |
| 33 | public final class OutputGroupProviderTest { |
| 34 | |
| 35 | @Test |
| 36 | public void testDetermineOutputGroupsOverridesDefaults() throws Exception { |
| 37 | Set<String> outputGroups = |
| 38 | determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("a", "b", "c")); |
| 39 | assertThat(outputGroups).containsExactly("a", "b", "c"); |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void testDetermineOutputGroupsAddsToDefaults() throws Exception { |
| 44 | Set<String> outputGroups = determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("+a")); |
Michael Staib | 0cdc492 | 2016-06-20 20:13:27 +0000 | [diff] [blame] | 45 | assertThat(outputGroups).containsExactly("x", "y", "z", "a"); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void testDetermineOutputGroupsRemovesFromDefaults() throws Exception { |
| 50 | Set<String> outputGroups = determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("-y")); |
Michael Staib | 0cdc492 | 2016-06-20 20:13:27 +0000 | [diff] [blame] | 51 | assertThat(outputGroups).containsExactly("x", "z"); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Test |
| 55 | public void testDetermineOutputGroupsMixedOverrideAdditionOverrides() throws Exception { |
| 56 | Set<String> outputGroups = |
| 57 | determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("a", "+b")); |
| 58 | // The plain "a" causes the default output groups to be overridden. |
| 59 | assertThat(outputGroups).containsExactly("a", "b"); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void testDetermineOutputGroupsIgnoresUnknownGroup() throws Exception { |
| 64 | Set<String> outputGroups = |
| 65 | determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("-foo")); |
| 66 | // "foo" doesn't exist, but that shouldn't be a problem. |
Michael Staib | 0cdc492 | 2016-06-20 20:13:27 +0000 | [diff] [blame] | 67 | assertThat(outputGroups).containsExactly("x", "y", "z"); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void testDetermineOutputGroupsRemovesPreviouslyAddedGroup() throws Exception { |
| 72 | Set<String> outputGroups; |
| 73 | outputGroups = determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("+a", "-a")); |
Michael Staib | 0cdc492 | 2016-06-20 20:13:27 +0000 | [diff] [blame] | 74 | assertThat(outputGroups).containsExactly("x", "y", "z"); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 75 | |
| 76 | // Order matters here. |
| 77 | outputGroups = determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("-a", "+a")); |
Michael Staib | 0cdc492 | 2016-06-20 20:13:27 +0000 | [diff] [blame] | 78 | assertThat(outputGroups).containsExactly("x", "y", "z", "a"); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 79 | } |
| 80 | } |