// Copyright 2015 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.packages; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.packages.BuildType.Selector; import com.google.devtools.build.lib.syntax.EvalUtils; import com.google.devtools.build.lib.syntax.Printer; import com.google.devtools.build.lib.syntax.SelectorList; import com.google.devtools.build.lib.syntax.SelectorValue; import com.google.devtools.build.lib.syntax.Type.ConversionException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.util.Arrays; import java.util.List; import java.util.Map; /** * Test of type-conversions for build-specific types. */ @RunWith(JUnit4.class) public class BuildTypeTest { private Label currentRule; @Before public final void setCurrentRule() throws Exception { this.currentRule = Label.parseAbsolute("//quux:baz"); } @Test public void testFilesetEntry() throws Exception { Label srcDir = Label.create("foo", "src"); Label entryLabel = Label.create("foo", "entry"); FilesetEntry input = new FilesetEntry(srcDir, ImmutableList.of(entryLabel), null, null, null, null); assertEquals(input, BuildType.FILESET_ENTRY.convert(input, null, currentRule)); assertThat(BuildType.FILESET_ENTRY.flatten(input)).containsExactly(entryLabel); } @Test public void testFilesetEntryList() throws Exception { Label srcDir = Label.create("foo", "src"); Label entry1Label = Label.create("foo", "entry1"); Label entry2Label = Label.create("foo", "entry"); List input = ImmutableList.of( new FilesetEntry(srcDir, ImmutableList.of(entry1Label), null, null, null, null), new FilesetEntry(srcDir, ImmutableList.of(entry2Label), null, null, null, null)); assertEquals(input, BuildType.FILESET_ENTRY_LIST.convert(input, null, currentRule)); assertThat(BuildType.FILESET_ENTRY_LIST.flatten(input)).containsExactly(entry1Label, entry2Label); } /** * Tests basic {@link Selector} functionality. */ @Test public void testSelector() throws Exception { Object input = ImmutableMap.of( "//conditions:a", "//a:a", "//conditions:b", "//b:b", BuildType.Selector.DEFAULT_CONDITION_KEY, "//d:d"); Selector