Han-Wen Nienhuys | 3428dc9 | 2015-10-21 15:03:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 The Bazel Authors. All rights reserved. |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 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.packages; |
| 15 | |
| 16 | import static com.google.common.truth.Truth.assertThat; |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 17 | import static com.google.devtools.build.lib.packages.Attribute.attr; |
Lukacs Berki | ffa73ad | 2015-09-18 11:40:12 +0000 | [diff] [blame] | 18 | import static com.google.devtools.build.lib.packages.BuildType.LABEL; |
| 19 | import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; |
Googler | c5fcc86 | 2019-09-06 16:17:47 -0700 | [diff] [blame] | 20 | import static com.google.devtools.build.lib.packages.Type.INTEGER; |
| 21 | import static com.google.devtools.build.lib.packages.Type.STRING; |
| 22 | import static com.google.devtools.build.lib.packages.Type.STRING_LIST; |
michajlo | 660d17f | 2020-03-27 09:01:57 -0700 | [diff] [blame] | 23 | import static org.junit.Assert.assertThrows; |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 24 | |
| 25 | import com.google.common.base.Predicates; |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame] | 26 | import com.google.common.collect.ImmutableMap; |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 27 | import com.google.devtools.build.lib.analysis.config.BuildOptions; |
gregce | 676a957 | 2017-12-21 11:33:32 -0800 | [diff] [blame] | 28 | import com.google.devtools.build.lib.analysis.config.HostTransition; |
jcater | 98a09b6 | 2019-04-02 13:06:19 -0700 | [diff] [blame] | 29 | import com.google.devtools.build.lib.analysis.config.TransitionFactories; |
John Cater | 5adcd3e | 2019-03-28 10:14:32 -0700 | [diff] [blame] | 30 | import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition; |
gregce | 6bc35ed | 2017-12-22 11:51:39 -0800 | [diff] [blame] | 31 | import com.google.devtools.build.lib.analysis.config.transitions.SplitTransition; |
John Cater | 0a9e1ed | 2019-03-27 11:02:01 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.analysis.config.transitions.TransitionFactory; |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 33 | import com.google.devtools.build.lib.analysis.util.TestAspects; |
Lukacs Berki | 6e91eb9 | 2015-09-21 09:12:37 +0000 | [diff] [blame] | 34 | import com.google.devtools.build.lib.cmdline.Label; |
gregce | f0a40ac | 2020-03-31 14:11:30 -0700 | [diff] [blame] | 35 | import com.google.devtools.build.lib.events.EventHandler; |
Googler | 72f3a10 | 2017-12-01 16:28:28 -0800 | [diff] [blame] | 36 | import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassNamePredicate; |
John Cater | 0a9e1ed | 2019-03-27 11:02:01 -0700 | [diff] [blame] | 37 | import com.google.devtools.build.lib.testutil.FakeAttributeMapper; |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 38 | import com.google.devtools.build.lib.util.FileType; |
| 39 | import com.google.devtools.build.lib.util.FileTypeSet; |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 40 | import java.util.Arrays; |
| 41 | import java.util.Collections; |
| 42 | import java.util.List; |
Googler | 19226b7 | 2020-02-06 12:58:43 -0800 | [diff] [blame] | 43 | import java.util.Map; |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 44 | import org.junit.Test; |
| 45 | import org.junit.runner.RunWith; |
| 46 | import org.junit.runners.JUnit4; |
| 47 | |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 48 | /** Tests of Attribute code. */ |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 49 | @RunWith(JUnit4.class) |
| 50 | public class AttributeTest { |
| 51 | |
| 52 | private void assertDefaultValue(Object expected, Attribute attr) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 53 | assertThat(attr.getDefaultValue(null)).isEqualTo(expected); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | private void assertType(Type<?> expectedType, Attribute attr) { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 57 | assertThat(attr.getType()).isEqualTo(expectedType); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testBasics() throws Exception { |
| 62 | Attribute attr = attr("foo", Type.INTEGER).mandatory().value(3).build(); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 63 | assertThat(attr.getName()).isEqualTo("foo"); |
| 64 | assertThat(attr.getDefaultValue(null)).isEqualTo(3); |
| 65 | assertThat(attr.getType()).isEqualTo(Type.INTEGER); |
| 66 | assertThat(attr.isMandatory()).isTrue(); |
| 67 | assertThat(attr.isDocumented()).isTrue(); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 68 | attr = attr("$foo", Type.INTEGER).build(); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 69 | assertThat(attr.isDocumented()).isFalse(); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Test |
| 73 | public void testNonEmptyReqiresListType() throws Exception { |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 74 | NullPointerException e = |
| 75 | assertThrows( |
| 76 | NullPointerException.class, |
| 77 | () -> attr("foo", Type.INTEGER).nonEmpty().value(3).build()); |
| 78 | assertThat(e).hasMessageThat().isEqualTo("attribute 'foo' must be a list"); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Test |
| 82 | public void testNonEmpty() throws Exception { |
Lukacs Berki | ffa73ad | 2015-09-18 11:40:12 +0000 | [diff] [blame] | 83 | Attribute attr = attr("foo", BuildType.LABEL_LIST).nonEmpty().legacyAllowAnyFileType().build(); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 84 | assertThat(attr.getName()).isEqualTo("foo"); |
| 85 | assertThat(attr.getType()).isEqualTo(BuildType.LABEL_LIST); |
| 86 | assertThat(attr.isNonEmpty()).isTrue(); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testSingleArtifactReqiresLabelType() throws Exception { |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 91 | IllegalStateException e = |
| 92 | assertThrows( |
| 93 | IllegalStateException.class, |
| 94 | () -> attr("foo", Type.INTEGER).singleArtifact().value(3).build()); |
| 95 | assertThat(e).hasMessageThat().isEqualTo("attribute 'foo' must be a label-valued type"); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Test |
| 99 | public void testDoublePropertySet() { |
jcater | ffb65c8 | 2019-03-29 07:52:16 -0700 | [diff] [blame] | 100 | Attribute.Builder<String> builder = |
| 101 | attr("x", STRING) |
| 102 | .mandatory() |
| 103 | .cfg(HostTransition.createFactory()) |
| 104 | .undocumented("") |
| 105 | .value("y"); |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 106 | assertThrows(IllegalStateException.class, () -> builder.mandatory()); |
| 107 | assertThrows(IllegalStateException.class, () -> builder.cfg(HostTransition.createFactory())); |
| 108 | assertThrows(IllegalStateException.class, () -> builder.undocumented("")); |
| 109 | assertThrows(IllegalStateException.class, () -> builder.value("z")); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 110 | |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 111 | Attribute.Builder<String> builder2 = attr("$x", STRING); |
| 112 | assertThrows(IllegalStateException.class, () -> builder2.undocumented("")); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Tests the "convenience factories" (string, label, etc) for default |
| 117 | * values. |
| 118 | */ |
| 119 | @Test |
| 120 | public void testConvenienceFactoriesDefaultValues() throws Exception { |
| 121 | assertDefaultValue(0, |
| 122 | attr("x", INTEGER).build()); |
| 123 | assertDefaultValue(42, |
| 124 | attr("x", INTEGER).value(42).build()); |
| 125 | |
| 126 | assertDefaultValue("", |
| 127 | attr("x", STRING).build()); |
| 128 | assertDefaultValue("foo", |
| 129 | attr("x", STRING).value("foo").build()); |
| 130 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame] | 131 | Label label = Label.parseAbsolute("//foo:bar", ImmutableMap.of()); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 132 | assertDefaultValue(null, |
| 133 | attr("x", LABEL).legacyAllowAnyFileType().build()); |
| 134 | assertDefaultValue(label, |
| 135 | attr("x", LABEL).legacyAllowAnyFileType().value(label).build()); |
| 136 | |
| 137 | List<String> slist = Arrays.asList("foo", "bar"); |
| 138 | assertDefaultValue(Collections.emptyList(), |
| 139 | attr("x", STRING_LIST).build()); |
| 140 | assertDefaultValue(slist, |
| 141 | attr("x", STRING_LIST).value(slist).build()); |
| 142 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame] | 143 | List<Label> llist = |
| 144 | Arrays.asList( |
| 145 | Label.parseAbsolute("//foo:bar", ImmutableMap.of()), |
| 146 | Label.parseAbsolute("//foo:wiz", ImmutableMap.of())); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 147 | assertDefaultValue(Collections.emptyList(), |
| 148 | attr("x", LABEL_LIST).legacyAllowAnyFileType().build()); |
| 149 | assertDefaultValue(llist, |
| 150 | attr("x", LABEL_LIST).legacyAllowAnyFileType().value(llist).build()); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Tests the "convenience factories" (string, label, etc) for types. |
| 155 | */ |
| 156 | @Test |
| 157 | public void testConvenienceFactoriesTypes() throws Exception { |
| 158 | assertType(INTEGER, |
| 159 | attr("x", INTEGER).build()); |
| 160 | assertType(INTEGER, |
| 161 | attr("x", INTEGER).value(42).build()); |
| 162 | |
| 163 | assertType(STRING, |
| 164 | attr("x", STRING).build()); |
| 165 | assertType(STRING, |
| 166 | attr("x", STRING).value("foo").build()); |
| 167 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame] | 168 | Label label = Label.parseAbsolute("//foo:bar", ImmutableMap.of()); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 169 | assertType(LABEL, |
| 170 | attr("x", LABEL).legacyAllowAnyFileType().build()); |
| 171 | assertType(LABEL, |
| 172 | attr("x", LABEL).legacyAllowAnyFileType().value(label).build()); |
| 173 | |
| 174 | List<String> slist = Arrays.asList("foo", "bar"); |
| 175 | assertType(STRING_LIST, |
| 176 | attr("x", STRING_LIST).build()); |
| 177 | assertType(STRING_LIST, |
| 178 | attr("x", STRING_LIST).value(slist).build()); |
| 179 | |
dannark | 90e2b4b | 2018-06-27 13:35:04 -0700 | [diff] [blame] | 180 | List<Label> llist = |
| 181 | Arrays.asList( |
| 182 | Label.parseAbsolute("//foo:bar", ImmutableMap.of()), |
| 183 | Label.parseAbsolute("//foo:wiz", ImmutableMap.of())); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 184 | assertType(LABEL_LIST, |
| 185 | attr("x", LABEL_LIST).legacyAllowAnyFileType().build()); |
| 186 | assertType(LABEL_LIST, |
| 187 | attr("x", LABEL_LIST).legacyAllowAnyFileType().value(llist).build()); |
| 188 | } |
| 189 | |
| 190 | @Test |
| 191 | public void testCloneBuilder() { |
| 192 | FileTypeSet txtFiles = FileTypeSet.of(FileType.of("txt")); |
Googler | 72f3a10 | 2017-12-01 16:28:28 -0800 | [diff] [blame] | 193 | RuleClassNamePredicate ruleClasses = RuleClassNamePredicate.only("mock_rule"); |
Han-Wen Nienhuys | 3428dc9 | 2015-10-21 15:03:34 +0000 | [diff] [blame] | 194 | |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 195 | Attribute parentAttr = |
| 196 | attr("x", LABEL_LIST) |
| 197 | .allowedFileTypes(txtFiles) |
| 198 | .mandatory() |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 199 | .aspect(TestAspects.SIMPLE_ASPECT) |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 200 | .build(); |
Han-Wen Nienhuys | 3428dc9 | 2015-10-21 15:03:34 +0000 | [diff] [blame] | 201 | |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 202 | { |
| 203 | Attribute childAttr1 = parentAttr.cloneBuilder().build(); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 204 | assertThat(childAttr1.getName()).isEqualTo("x"); |
| 205 | assertThat(childAttr1.getAllowedFileTypesPredicate()).isEqualTo(txtFiles); |
| 206 | assertThat(childAttr1.getAllowedRuleClassesPredicate()).isEqualTo(Predicates.alwaysTrue()); |
| 207 | assertThat(childAttr1.isMandatory()).isTrue(); |
| 208 | assertThat(childAttr1.isNonEmpty()).isFalse(); |
cushon | 8c6b7ab | 2018-04-27 01:25:50 -0700 | [diff] [blame] | 209 | assertThat(childAttr1.getAspects(/* rule= */ null)).hasSize(1); |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 210 | } |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 211 | |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 212 | { |
| 213 | Attribute childAttr2 = |
| 214 | parentAttr |
| 215 | .cloneBuilder() |
| 216 | .nonEmpty() |
| 217 | .allowedRuleClasses(ruleClasses) |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 218 | .aspect(TestAspects.ERROR_ASPECT) |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 219 | .build(); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 220 | assertThat(childAttr2.getName()).isEqualTo("x"); |
| 221 | assertThat(childAttr2.getAllowedFileTypesPredicate()).isEqualTo(txtFiles); |
Googler | 72f3a10 | 2017-12-01 16:28:28 -0800 | [diff] [blame] | 222 | assertThat(childAttr2.getAllowedRuleClassesPredicate()) |
| 223 | .isEqualTo(ruleClasses.asPredicateOfRuleClass()); |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 224 | assertThat(childAttr2.isMandatory()).isTrue(); |
| 225 | assertThat(childAttr2.isNonEmpty()).isTrue(); |
cushon | 8c6b7ab | 2018-04-27 01:25:50 -0700 | [diff] [blame] | 226 | assertThat(childAttr2.getAspects(/* rule= */ null)).hasSize(2); |
Carmi Grushko | 215fa84 | 2016-03-31 18:14:39 +0000 | [diff] [blame] | 227 | } |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 228 | |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 229 | // Check if the parent attribute is unchanged |
| 230 | assertThat(parentAttr.isNonEmpty()).isFalse(); |
| 231 | assertThat(parentAttr.getAllowedRuleClassesPredicate()).isEqualTo(Predicates.alwaysTrue()); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Tests that configurability settings are properly received. |
| 236 | */ |
| 237 | @Test |
| 238 | public void testConfigurability() { |
lberki | aea56b3 | 2017-05-30 12:35:33 +0200 | [diff] [blame] | 239 | assertThat( |
| 240 | attr("foo_configurable", BuildType.LABEL_LIST) |
| 241 | .legacyAllowAnyFileType() |
| 242 | .build() |
| 243 | .isConfigurable()) |
| 244 | .isTrue(); |
| 245 | assertThat( |
| 246 | attr("foo_nonconfigurable", BuildType.LABEL_LIST) |
| 247 | .legacyAllowAnyFileType() |
| 248 | .nonconfigurable("test") |
| 249 | .build() |
| 250 | .isConfigurable()) |
| 251 | .isFalse(); |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 252 | } |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 253 | |
| 254 | @Test |
| 255 | public void testSplitTransition() throws Exception { |
| 256 | TestSplitTransition splitTransition = new TestSplitTransition(); |
jcater | 98a09b6 | 2019-04-02 13:06:19 -0700 | [diff] [blame] | 257 | Attribute attr = |
| 258 | attr("foo", LABEL).cfg(TransitionFactories.of(splitTransition)).allowedFileTypes().build(); |
jcater | e8f5a98 | 2019-04-02 11:12:19 -0700 | [diff] [blame] | 259 | assertThat(attr.getTransitionFactory().isSplit()).isTrue(); |
John Cater | 5adcd3e | 2019-03-28 10:14:32 -0700 | [diff] [blame] | 260 | ConfigurationTransition transition = |
John Cater | 2c0dece | 2019-04-02 09:18:18 -0700 | [diff] [blame] | 261 | attr.getTransitionFactory() |
jcater | 2358946 | 2019-05-20 08:51:24 -0700 | [diff] [blame] | 262 | .create( |
| 263 | AttributeTransitionData.builder().attributes(FakeAttributeMapper.empty()).build()); |
John Cater | 5adcd3e | 2019-03-28 10:14:32 -0700 | [diff] [blame] | 264 | assertThat(transition).isEqualTo(splitTransition); |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | @Test |
| 268 | public void testSplitTransitionProvider() throws Exception { |
| 269 | TestSplitTransitionProvider splitTransitionProvider = new TestSplitTransitionProvider(); |
| 270 | Attribute attr = |
| 271 | attr("foo", LABEL).cfg(splitTransitionProvider).allowedFileTypes().build(); |
jcater | e8f5a98 | 2019-04-02 11:12:19 -0700 | [diff] [blame] | 272 | assertThat(attr.getTransitionFactory().isSplit()).isTrue(); |
John Cater | 5adcd3e | 2019-03-28 10:14:32 -0700 | [diff] [blame] | 273 | ConfigurationTransition transition = |
John Cater | 2c0dece | 2019-04-02 09:18:18 -0700 | [diff] [blame] | 274 | attr.getTransitionFactory() |
jcater | 2358946 | 2019-05-20 08:51:24 -0700 | [diff] [blame] | 275 | .create( |
| 276 | AttributeTransitionData.builder().attributes(FakeAttributeMapper.empty()).build()); |
John Cater | 5adcd3e | 2019-03-28 10:14:32 -0700 | [diff] [blame] | 277 | assertThat(transition).isInstanceOf(TestSplitTransition.class); |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | @Test |
| 281 | public void testHostTransition() throws Exception { |
jcater | ffb65c8 | 2019-03-29 07:52:16 -0700 | [diff] [blame] | 282 | Attribute attr = |
| 283 | attr("foo", LABEL).cfg(HostTransition.createFactory()).allowedFileTypes().build(); |
jcater | b44167f | 2019-04-02 12:06:26 -0700 | [diff] [blame] | 284 | assertThat(attr.getTransitionFactory().isHost()).isTrue(); |
jcater | e8f5a98 | 2019-04-02 11:12:19 -0700 | [diff] [blame] | 285 | assertThat(attr.getTransitionFactory().isSplit()).isFalse(); |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 286 | } |
| 287 | |
gregce | 6bc35ed | 2017-12-22 11:51:39 -0800 | [diff] [blame] | 288 | private static class TestSplitTransition implements SplitTransition { |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 289 | @Override |
gregce | f0a40ac | 2020-03-31 14:11:30 -0700 | [diff] [blame] | 290 | public Map<String, BuildOptions> split(BuildOptions buildOptions, EventHandler eventHandler) { |
Googler | 19226b7 | 2020-02-06 12:58:43 -0800 | [diff] [blame] | 291 | return ImmutableMap.of("test0", buildOptions.clone(), "test1", buildOptions.clone()); |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
John Cater | 0a9e1ed | 2019-03-27 11:02:01 -0700 | [diff] [blame] | 295 | private static class TestSplitTransitionProvider |
John Cater | 2c0dece | 2019-04-02 09:18:18 -0700 | [diff] [blame] | 296 | implements TransitionFactory<AttributeTransitionData> { |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 297 | @Override |
John Cater | 2c0dece | 2019-04-02 09:18:18 -0700 | [diff] [blame] | 298 | public SplitTransition create(AttributeTransitionData data) { |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 299 | return new TestSplitTransition(); |
| 300 | } |
cparsons | 21e2518 | 2019-01-15 16:00:26 -0800 | [diff] [blame] | 301 | |
| 302 | @Override |
John Cater | 0a9e1ed | 2019-03-27 11:02:01 -0700 | [diff] [blame] | 303 | public boolean isSplit() { |
| 304 | return true; |
| 305 | } |
Chris Parsons | 2e62c0d | 2016-04-19 22:13:59 +0000 | [diff] [blame] | 306 | } |
gregce | da4c959 | 2017-07-27 22:09:34 +0200 | [diff] [blame] | 307 | |
| 308 | @Test |
| 309 | public void allowedRuleClassesAndAllowedRuleClassesWithWarningsCannotOverlap() throws Exception { |
jcater | b922677 | 2019-04-29 12:04:52 -0700 | [diff] [blame] | 310 | IllegalStateException e = |
| 311 | assertThrows( |
| 312 | IllegalStateException.class, |
| 313 | () -> |
| 314 | attr("x", LABEL_LIST) |
| 315 | .allowedRuleClasses("foo", "bar", "baz") |
| 316 | .allowedRuleClassesWithWarning("bar") |
| 317 | .allowedFileTypes() |
| 318 | .build()); |
| 319 | assertThat(e).hasMessageThat().contains("may not contain the same rule classes"); |
gregce | da4c959 | 2017-07-27 22:09:34 +0200 | [diff] [blame] | 320 | } |
Ulf Adams | 83763ee | 2015-05-04 15:36:12 +0000 | [diff] [blame] | 321 | } |