|
| 1 | +// Copyright 2020 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 | +package com.google.devtools.build.lib.buildtool; |
| 15 | + |
| 16 | +import static com.google.common.truth.Truth.assertThat; |
| 17 | + |
| 18 | +import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; |
| 19 | +import com.google.devtools.build.lib.events.EventCollector; |
| 20 | +import com.google.devtools.build.lib.events.EventKind; |
| 21 | +import com.google.devtools.build.lib.packages.Target; |
| 22 | +import java.util.ArrayList; |
| 23 | +import java.util.Collection; |
| 24 | +import java.util.Collections; |
| 25 | +import java.util.List; |
| 26 | +import org.junit.Test; |
| 27 | +import org.junit.runner.RunWith; |
| 28 | +import org.junit.runners.JUnit4; |
| 29 | + |
| 30 | +/** Tests {@link com.google.devtools.build.lib.buildtool.InstrumentationFilterSupport}. */ |
| 31 | +@RunWith(JUnit4.class) |
| 32 | +public class InstrumentationFilterSupportTest extends BuildViewTestCase { |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testComputeInstrumentationFilter() throws Exception { |
| 36 | + EventCollector events = new EventCollector(EventKind.INFO); |
| 37 | + scratch.file("foo/BUILD", "sh_test(name='t', srcs=['t.sh'])"); |
| 38 | + scratch.file("foobar/BUILD", "sh_test(name='t', srcs=['t.sh'])"); |
| 39 | + List<Target> listOfTargets = new ArrayList<>(); |
| 40 | + listOfTargets.add(getTarget("//foo:t")); |
| 41 | + listOfTargets.add(getTarget("//foobar:t")); |
| 42 | + Collection<Target> targets = Collections.unmodifiableCollection(listOfTargets); |
| 43 | + String expectedFilter = "^//foo[/:],^//foobar[/:]"; |
| 44 | + assertThat(InstrumentationFilterSupport.computeInstrumentationFilter(events, targets)) |
| 45 | + .isEqualTo(expectedFilter); |
| 46 | + } |
| 47 | +} |
0 commit comments