blob: a6857b7089dfa184091c440ab271da6996870fc2 [file] [log] [blame]
Alex Humesky152feb02016-06-20 19:43:11 +00001// 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
15package com.google.devtools.build.lib.analysis;
16
17import static com.google.common.truth.Truth.assertThat;
18import static com.google.devtools.build.lib.analysis.OutputGroupProvider.determineOutputGroups;
19import static java.util.Arrays.asList;
20
21import com.google.common.collect.ImmutableSet;
22
23import org.junit.Test;
24import org.junit.runner.RunWith;
25import org.junit.runners.JUnit4;
26
Alex Humesky152feb02016-06-20 19:43:11 +000027import java.util.Set;
28
29/**
30 * Tests for {@link OutputGroupProvider}.
31 */
32@RunWith(JUnit4.class)
33public 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 Staib0cdc4922016-06-20 20:13:27 +000045 assertThat(outputGroups).containsExactly("x", "y", "z", "a");
Alex Humesky152feb02016-06-20 19:43:11 +000046 }
47
48 @Test
49 public void testDetermineOutputGroupsRemovesFromDefaults() throws Exception {
50 Set<String> outputGroups = determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("-y"));
Michael Staib0cdc4922016-06-20 20:13:27 +000051 assertThat(outputGroups).containsExactly("x", "z");
Alex Humesky152feb02016-06-20 19:43:11 +000052 }
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 Staib0cdc4922016-06-20 20:13:27 +000067 assertThat(outputGroups).containsExactly("x", "y", "z");
Alex Humesky152feb02016-06-20 19:43:11 +000068 }
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 Staib0cdc4922016-06-20 20:13:27 +000074 assertThat(outputGroups).containsExactly("x", "y", "z");
Alex Humesky152feb02016-06-20 19:43:11 +000075
76 // Order matters here.
77 outputGroups = determineOutputGroups(ImmutableSet.of("x", "y", "z"), asList("-a", "+a"));
Michael Staib0cdc4922016-06-20 20:13:27 +000078 assertThat(outputGroups).containsExactly("x", "y", "z", "a");
Alex Humesky152feb02016-06-20 19:43:11 +000079 }
80}