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; |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 18 | import static com.google.devtools.build.lib.analysis.OutputGroupInfo.DEFAULT; |
dslomov | 69c45f8 | 2017-12-14 11:15:43 -0500 | [diff] [blame] | 19 | import static com.google.devtools.build.lib.analysis.OutputGroupInfo.determineOutputGroups; |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 20 | import static java.util.Arrays.asList; |
| 21 | |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 22 | import com.google.common.collect.ImmutableList; |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 23 | import com.google.common.collect.ImmutableSet; |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 24 | import com.google.devtools.build.lib.analysis.OutputGroupInfo.ValidationMode; |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 25 | import com.google.testing.junit.testparameterinjector.TestParameter; |
| 26 | import com.google.testing.junit.testparameterinjector.TestParameterInjector; |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 27 | import java.util.Set; |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 28 | import org.junit.Test; |
| 29 | import org.junit.runner.RunWith; |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 30 | |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 31 | /** Tests for {@link OutputGroupInfo}. */ |
| 32 | @RunWith(TestParameterInjector.class) |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 33 | public final class OutputGroupProviderTest { |
| 34 | |
| 35 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 36 | public void testDetermineOutputGroupsOverridesDefaults(@TestParameter boolean shouldRunTests) { |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 37 | Set<String> outputGroups = |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 38 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 39 | ImmutableSet.of("x", "y", "z"), |
| 40 | asList("a", "b", "c"), |
| 41 | ValidationMode.OFF, |
| 42 | /*shouldRunTests=*/ shouldRunTests); |
| 43 | assertThat(outputGroups) |
| 44 | .containsExactlyElementsIn( |
| 45 | outputGroupsWithDefaultIfRunningTests(shouldRunTests, "a", "b", "c")); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 49 | public void testDetermineOutputGroupsAddsToDefaults(@TestParameter boolean shouldRunTests) { |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 50 | Set<String> outputGroups = |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 51 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 52 | ImmutableSet.of("x", "y", "z"), |
| 53 | asList("+a"), |
| 54 | ValidationMode.OFF, |
| 55 | /*shouldRunTests=*/ shouldRunTests); |
| 56 | assertThat(outputGroups) |
| 57 | .containsExactlyElementsIn( |
| 58 | outputGroupsWithDefaultIfRunningTests(shouldRunTests, "x", "y", "z", "a")); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void testDetermineOutputGroupsRemovesFromDefaults(@TestParameter boolean shouldRunTests) { |
| 63 | Set<String> outputGroups = |
| 64 | determineOutputGroups( |
| 65 | ImmutableSet.of("x", "y", "z"), |
| 66 | asList("-y"), |
| 67 | ValidationMode.OFF, |
| 68 | /*shouldRunTests=*/ shouldRunTests); |
| 69 | assertThat(outputGroups) |
| 70 | .containsExactlyElementsIn(outputGroupsWithDefaultIfRunningTests(shouldRunTests, "x", "z")); |
| 71 | } |
| 72 | |
| 73 | @Test |
| 74 | public void testDetermineOutputGroupsMixedOverrideAdditionOverrides( |
| 75 | @TestParameter boolean shouldRunTests) { |
| 76 | Set<String> outputGroups = |
| 77 | determineOutputGroups( |
| 78 | ImmutableSet.of("x", "y", "z"), |
| 79 | asList("a", "+b"), |
| 80 | ValidationMode.OFF, |
| 81 | /*shouldRunTests=*/ shouldRunTests); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 82 | // The plain "a" causes the default output groups to be overridden. |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 83 | assertThat(outputGroups) |
| 84 | .containsExactlyElementsIn(outputGroupsWithDefaultIfRunningTests(shouldRunTests, "a", "b")); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 88 | public void testDetermineOutputGroupsIgnoresUnknownGroup(@TestParameter boolean shouldRunTests) { |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 89 | Set<String> outputGroups = |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 90 | determineOutputGroups( |
| 91 | ImmutableSet.of("x", "y", "z"), |
| 92 | asList("-foo"), |
| 93 | ValidationMode.OFF, |
| 94 | /*shouldRunTests=*/ shouldRunTests); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 95 | // "foo" doesn't exist, but that shouldn't be a problem. |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 96 | assertThat(outputGroups) |
| 97 | .containsExactlyElementsIn( |
| 98 | outputGroupsWithDefaultIfRunningTests(shouldRunTests, "x", "y", "z")); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 102 | public void testDetermineOutputGroupsRemovesPreviouslyAddedGroup( |
| 103 | @TestParameter boolean shouldRunTests) { |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 104 | Set<String> outputGroups; |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 105 | outputGroups = |
| 106 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 107 | ImmutableSet.of("x", "y", "z"), |
| 108 | asList("+a", "-a"), |
| 109 | ValidationMode.OFF, |
| 110 | /*shouldRunTests=*/ shouldRunTests); |
| 111 | assertThat(outputGroups) |
| 112 | .containsExactlyElementsIn( |
| 113 | outputGroupsWithDefaultIfRunningTests(shouldRunTests, "x", "y", "z")); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 114 | |
| 115 | // Order matters here. |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 116 | outputGroups = |
| 117 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 118 | ImmutableSet.of("x", "y", "z"), |
| 119 | asList("-a", "+a"), |
| 120 | ValidationMode.OFF, |
| 121 | /*shouldRunTests=*/ shouldRunTests); |
| 122 | assertThat(outputGroups) |
| 123 | .containsExactlyElementsIn( |
| 124 | outputGroupsWithDefaultIfRunningTests(shouldRunTests, "x", "y", "z", "a")); |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 125 | } |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 126 | |
| 127 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 128 | public void testDetermineOutputGroupsContainsValidationGroup( |
| 129 | @TestParameter boolean shouldRunTests) { |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 130 | Set<String> outputGroups = |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 131 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 132 | ImmutableSet.of("x", "y", "z"), |
| 133 | asList(), |
| 134 | ValidationMode.OUTPUT_GROUP, |
| 135 | /*shouldRunTests=*/ shouldRunTests); |
| 136 | assertThat(outputGroups) |
| 137 | .containsExactlyElementsIn( |
| 138 | outputGroupsWithDefaultIfRunningTests( |
| 139 | shouldRunTests, "x", "y", "z", OutputGroupInfo.VALIDATION)); |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 143 | public void testDetermineOutputGroupsContainsValidationGroupAfterOverride( |
| 144 | @TestParameter boolean shouldRunTests) { |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 145 | Set<String> outputGroups = |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 146 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 147 | ImmutableSet.of("x", "y", "z"), |
| 148 | asList("foo"), |
| 149 | ValidationMode.OUTPUT_GROUP, |
| 150 | /*shouldRunTests=*/ shouldRunTests); |
| 151 | assertThat(outputGroups) |
| 152 | .containsExactlyElementsIn( |
| 153 | outputGroupsWithDefaultIfRunningTests( |
| 154 | shouldRunTests, "foo", OutputGroupInfo.VALIDATION)); |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 158 | public void testDetermineOutputGroupsContainsValidationGroupAfterAdd( |
| 159 | @TestParameter boolean shouldRunTests) { |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 160 | Set<String> outputGroups = |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 161 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 162 | ImmutableSet.of("x", "y", "z"), |
| 163 | asList("+a"), |
| 164 | ValidationMode.OUTPUT_GROUP, |
| 165 | /*shouldRunTests=*/ shouldRunTests); |
| 166 | assertThat(outputGroups) |
| 167 | .containsExactlyElementsIn( |
| 168 | outputGroupsWithDefaultIfRunningTests( |
| 169 | shouldRunTests, "x", "y", "z", "a", OutputGroupInfo.VALIDATION)); |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 173 | public void testDetermineOutputGroupsContainsValidationGroupAfterRemove( |
| 174 | @TestParameter boolean shouldRunTests) { |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 175 | Set<String> outputGroups = |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 176 | determineOutputGroups( |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 177 | ImmutableSet.of("x", "y", "z"), |
| 178 | asList("-x"), |
| 179 | ValidationMode.OUTPUT_GROUP, |
| 180 | /*shouldRunTests=*/ shouldRunTests); |
| 181 | assertThat(outputGroups) |
| 182 | .containsExactlyElementsIn( |
| 183 | outputGroupsWithDefaultIfRunningTests( |
| 184 | shouldRunTests, "y", "z", OutputGroupInfo.VALIDATION)); |
ahumesky | 60205bb | 2019-10-14 13:50:00 -0700 | [diff] [blame] | 185 | } |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 186 | |
| 187 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 188 | public void testDetermineOutputGroupsContainsValidationGroupDespiteRemove( |
| 189 | @TestParameter boolean shouldRunTests) { |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 190 | Set<String> outputGroups = |
| 191 | determineOutputGroups( |
| 192 | ImmutableSet.of("x", "y", "z"), |
| 193 | asList("-" + OutputGroupInfo.VALIDATION), |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 194 | ValidationMode.OUTPUT_GROUP, |
| 195 | /*shouldRunTests=*/ shouldRunTests); |
| 196 | assertThat(outputGroups) |
| 197 | .containsExactlyElementsIn( |
| 198 | outputGroupsWithDefaultIfRunningTests( |
| 199 | shouldRunTests, "x", "y", "z", OutputGroupInfo.VALIDATION)); |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | @Test |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 203 | public void testDetermineOutputGroupsContainsTopLevelValidationGroup( |
| 204 | @TestParameter boolean shouldRunTests) { |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 205 | Set<String> outputGroups = |
| 206 | determineOutputGroups( |
| 207 | ImmutableSet.of("x", "y", "z"), |
| 208 | asList("-" + OutputGroupInfo.VALIDATION_TOP_LEVEL), |
adgar | bce6d26 | 2021-05-03 13:56:28 -0700 | [diff] [blame] | 209 | ValidationMode.ASPECT, |
| 210 | /*shouldRunTests=*/ shouldRunTests); |
| 211 | assertThat(outputGroups) |
| 212 | .containsExactlyElementsIn( |
| 213 | outputGroupsWithDefaultIfRunningTests( |
| 214 | shouldRunTests, "x", "y", "z", OutputGroupInfo.VALIDATION_TOP_LEVEL)); |
| 215 | } |
| 216 | |
| 217 | private static Iterable<String> outputGroupsWithDefaultIfRunningTests( |
| 218 | boolean shouldRunTests, String... groups) { |
| 219 | ImmutableList.Builder<String> result = ImmutableList.builder(); |
| 220 | result.add(groups); |
| 221 | if (shouldRunTests) { |
| 222 | result.add(DEFAULT); |
| 223 | } |
| 224 | return result.build(); |
kmb | 0d89740 | 2021-04-22 09:42:46 -0700 | [diff] [blame] | 225 | } |
Alex Humesky | 152feb0 | 2016-06-20 19:43:11 +0000 | [diff] [blame] | 226 | } |