aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2016-11-11 10:00:53 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-11-11 10:56:56 +0000
commit9f74dfbc7aba8e455150f8eba4b616c56467e598 (patch)
tree0fa37bdff01c4610c6b4adc982caa0980e5b0569 /src/test/java/com/google/devtools/build/lib
parent279a061eb0873df4e8ea71755684037b4bdd511f (diff)
Implement build tag filtering.
If the --build_tag_filters option is specified, targets built will be filtered according to their tags (at least one included, none excluded) -- MOS_MIGRATED_REVID=138856195
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/TargetUtilsTest.java81
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/TestTargetUtilsTest.java38
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java19
-rw-r--r--src/test/java/com/google/devtools/build/lib/util/TargetUtilsTest.java37
4 files changed, 97 insertions, 78 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/TargetUtilsTest.java b/src/test/java/com/google/devtools/build/lib/packages/TargetUtilsTest.java
new file mode 100644
index 0000000000..c1fb849fd4
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/packages/TargetUtilsTest.java
@@ -0,0 +1,81 @@
+// Copyright 2014 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 com.google.common.base.Predicate;
+import com.google.common.collect.Lists;
+import com.google.devtools.build.lib.packages.util.PackageLoadingTestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Test for {@link TargetUtils}
+ */
+@RunWith(JUnit4.class)
+public class TargetUtilsTest extends PackageLoadingTestCase {
+
+ @Test
+ public void getRuleLanguage() {
+ assertEquals("java", TargetUtils.getRuleLanguage("java_binary"));
+ assertEquals("foobar", TargetUtils.getRuleLanguage("foobar"));
+ assertThat(TargetUtils.getRuleLanguage("")).isEmpty();
+ }
+
+ @Test
+ public void testFilterByTag() throws Exception {
+ scratch.file(
+ "tests/BUILD",
+ "sh_binary(name = 'tag1', srcs=['sh.sh'], tags=['tag1'])",
+ "sh_binary(name = 'tag2', srcs=['sh.sh'], tags=['tag2'])",
+ "sh_binary(name = 'tag1b', srcs=['sh.sh'], tags=['tag1'])");
+
+ Target tag1 = getTarget("//tests:tag1");
+ Target tag2 = getTarget("//tests:tag2");
+ Target tag1b = getTarget("//tests:tag1b");
+
+ Predicate<Target> tagFilter = TargetUtils.tagFilter(Lists.<String>newArrayList());
+ assertTrue(tagFilter.apply(tag1));
+ assertTrue(tagFilter.apply(tag2));
+ assertTrue(tagFilter.apply(tag1b));
+ tagFilter = TargetUtils.tagFilter(Lists.newArrayList("tag1", "tag2"));
+ assertTrue(tagFilter.apply(tag1));
+ assertTrue(tagFilter.apply(tag2));
+ assertTrue(tagFilter.apply(tag1b));
+ tagFilter = TargetUtils.tagFilter(Lists.newArrayList("tag1"));
+ assertTrue(tagFilter.apply(tag1));
+ assertFalse(tagFilter.apply(tag2));
+ assertTrue(tagFilter.apply(tag1b));
+ tagFilter = TargetUtils.tagFilter(Lists.newArrayList("-tag2"));
+ assertTrue(tagFilter.apply(tag1));
+ assertFalse(tagFilter.apply(tag2));
+ assertTrue(tagFilter.apply(tag1b));
+ // Applying same tag as positive and negative filter produces an empty
+ // result because the negative filter is applied first and positive filter will
+ // not match anything.
+ tagFilter = TargetUtils.tagFilter(Lists.newArrayList("tag2", "-tag2"));
+ assertFalse(tagFilter.apply(tag1));
+ assertFalse(tagFilter.apply(tag2));
+ assertFalse(tagFilter.apply(tag1b));
+ tagFilter = TargetUtils.tagFilter(Lists.newArrayList("tag2", "-tag1"));
+ assertFalse(tagFilter.apply(tag1));
+ assertTrue(tagFilter.apply(tag2));
+ assertFalse(tagFilter.apply(tag1b));
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/TestTargetUtilsTest.java b/src/test/java/com/google/devtools/build/lib/packages/TestTargetUtilsTest.java
index aedc014935..53f21bb036 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/TestTargetUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/TestTargetUtilsTest.java
@@ -23,7 +23,6 @@ import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.ResolvedTargets;
@@ -34,15 +33,13 @@ import com.google.devtools.build.lib.pkgcache.TargetProvider;
import com.google.devtools.build.lib.skyframe.TestSuiteExpansionValue;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
-
+import java.util.Collection;
+import java.util.EnumSet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.Collection;
-import java.util.EnumSet;
-
@RunWith(JUnit4.class)
public class TestTargetUtilsTest extends PackageLoadingTestCase {
private Target test1;
@@ -124,37 +121,6 @@ public class TestTargetUtilsTest extends PackageLoadingTestCase {
}
@Test
- public void testFilterByTag() throws Exception {
- Predicate<Target> tagFilter = TestTargetUtils.tagFilter(Lists.<String>newArrayList());
- assertTrue(tagFilter.apply(test1));
- assertTrue(tagFilter.apply(test2));
- assertTrue(tagFilter.apply(test1b));
- tagFilter = TestTargetUtils.tagFilter(Lists.newArrayList("tag1", "tag2"));
- assertTrue(tagFilter.apply(test1));
- assertTrue(tagFilter.apply(test2));
- assertTrue(tagFilter.apply(test1b));
- tagFilter = TestTargetUtils.tagFilter(Lists.newArrayList("tag1"));
- assertTrue(tagFilter.apply(test1));
- assertFalse(tagFilter.apply(test2));
- assertTrue(tagFilter.apply(test1b));
- tagFilter = TestTargetUtils.tagFilter(Lists.newArrayList("-tag2"));
- assertTrue(tagFilter.apply(test1));
- assertFalse(tagFilter.apply(test2));
- assertTrue(tagFilter.apply(test1b));
- // Applying same tag as positive and negative filter produces an empty
- // result because the negative filter is applied first and positive filter will
- // not match anything.
- tagFilter = TestTargetUtils.tagFilter(Lists.newArrayList("tag2", "-tag2"));
- assertFalse(tagFilter.apply(test1));
- assertFalse(tagFilter.apply(test2));
- assertFalse(tagFilter.apply(test1b));
- tagFilter = TestTargetUtils.tagFilter(Lists.newArrayList("tag2", "-tag1"));
- assertFalse(tagFilter.apply(test1));
- assertTrue(tagFilter.apply(test2));
- assertFalse(tagFilter.apply(test1b));
- }
-
- @Test
public void testExpandTestSuites() throws Exception {
assertExpandedSuites(Sets.newHashSet(test1, test2), Sets.newHashSet(test1, test2));
assertExpandedSuites(Sets.newHashSet(test1, test2), Sets.newHashSet(suite));
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java
index e5d72aa7cf..3ac4ac9f31 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TargetPatternPhaseKeyTest.java
@@ -50,24 +50,33 @@ public class TargetPatternPhaseKeyTest {
.addEqualityGroup(of(ImmutableList.of("b"), ""))
.addEqualityGroup(of(ImmutableList.of("c"), ""))
.addEqualityGroup(of(ImmutableList.<String>of(), ""))
- .addEqualityGroup(of(ImmutableList.<String>of(), "", null, COMPILE_ONE_DEPENDENCY))
- .addEqualityGroup(of(ImmutableList.<String>of(), "", emptyTestFilter(), BUILD_TESTS_ONLY))
- .addEqualityGroup(of(ImmutableList.<String>of(), "", emptyTestFilter(), DETERMINE_TESTS))
+ .addEqualityGroup(of(
+ ImmutableList.<String>of(), "", ImmutableList.<String>of(), null,
+ COMPILE_ONE_DEPENDENCY))
+ .addEqualityGroup(of(
+ ImmutableList.<String>of(), "", ImmutableList.<String>of(), emptyTestFilter(),
+ BUILD_TESTS_ONLY))
+ .addEqualityGroup(of(
+ ImmutableList.<String>of(), "", ImmutableList.<String>of(), emptyTestFilter(),
+ DETERMINE_TESTS))
+ .addEqualityGroup(of(
+ ImmutableList.<String>of(), "", ImmutableList.<String>of("a"), null))
.testEquals();
}
private TargetPatternList of(ImmutableList<String> targetPatterns, String offset,
+ ImmutableList<String> buildTagFilter,
@Nullable TestFilter testFilter, Flag... flags) {
ImmutableSet<Flag> set = ImmutableSet.copyOf(flags);
boolean compileOneDependency = set.contains(Flag.COMPILE_ONE_DEPENDENCY);
boolean buildTestsOnly = set.contains(Flag.BUILD_TESTS_ONLY);
boolean determineTests = set.contains(Flag.DETERMINE_TESTS);
return new TargetPatternList(targetPatterns, offset, compileOneDependency, buildTestsOnly,
- determineTests, testFilter);
+ determineTests, buildTagFilter, testFilter);
}
private TargetPatternList of(ImmutableList<String> targetPatterns, String offset) {
- return of(targetPatterns, offset, null);
+ return of(targetPatterns, offset, ImmutableList.<String>of(), null);
}
private TestFilter emptyTestFilter() {
diff --git a/src/test/java/com/google/devtools/build/lib/util/TargetUtilsTest.java b/src/test/java/com/google/devtools/build/lib/util/TargetUtilsTest.java
deleted file mode 100644
index 201b8486e4..0000000000
--- a/src/test/java/com/google/devtools/build/lib/util/TargetUtilsTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 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.util;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertEquals;
-
-import com.google.devtools.build.lib.packages.TargetUtils;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Test for {@link TargetUtils}
- */
-@RunWith(JUnit4.class)
-public class TargetUtilsTest {
-
- @Test
- public void getRuleLanguage() {
- assertEquals("java", TargetUtils.getRuleLanguage("java_binary"));
- assertEquals("foobar", TargetUtils.getRuleLanguage("foobar"));
- assertThat(TargetUtils.getRuleLanguage("")).isEmpty();
- }
-}